mirror of
https://github.com/GrammaticalFramework/gf-core.git
synced 2026-04-23 19:42:50 -06:00
a simple refactoring in the statistical parser
This commit is contained in:
@@ -1559,49 +1559,47 @@ pgf_parsing_item(PgfParseState* before, PgfParseState* after, PgfItem* item)
|
|||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
pgf_parsing_proceed(PgfParseState* state, void** output) {
|
pgf_parsing_proceed(PgfParseState* state) {
|
||||||
while (*output == NULL) {
|
prob_t best_prob = INFINITY;
|
||||||
prob_t best_prob = INFINITY;
|
PgfParseState* before = NULL;
|
||||||
PgfParseState* before = NULL;
|
|
||||||
|
|
||||||
PgfParseState* st = state;
|
PgfParseState* st = state;
|
||||||
while (st != NULL) {
|
while (st != NULL) {
|
||||||
if (gu_buf_length(st->agenda) > 0) {
|
if (gu_buf_length(st->agenda) > 0) {
|
||||||
PgfItem* item = gu_buf_get(st->agenda, PgfItem*, 0);
|
PgfItem* item = gu_buf_get(st->agenda, PgfItem*, 0);
|
||||||
prob_t item_prob = item->inside_prob+item->conts->outside_prob;
|
prob_t item_prob = item->inside_prob+item->conts->outside_prob;
|
||||||
if (item_prob < best_prob) {
|
if (item_prob < best_prob) {
|
||||||
best_prob = item_prob;
|
best_prob = item_prob;
|
||||||
before = st;
|
before = st;
|
||||||
}
|
|
||||||
}
|
}
|
||||||
st = st->next;
|
|
||||||
}
|
}
|
||||||
|
st = st->next;
|
||||||
if (before == NULL)
|
|
||||||
break;
|
|
||||||
|
|
||||||
PgfParseState* after = NULL;
|
|
||||||
|
|
||||||
st = state;
|
|
||||||
while (st != before) {
|
|
||||||
PgfParseState* tmp = st->next;
|
|
||||||
st->next = after;
|
|
||||||
after = st;
|
|
||||||
st = tmp;
|
|
||||||
}
|
|
||||||
|
|
||||||
PgfItem* item;
|
|
||||||
gu_buf_heap_pop(before->agenda, &pgf_item_prob_order, &item);
|
|
||||||
pgf_parsing_item(before, after, item);
|
|
||||||
|
|
||||||
while (after != NULL) {
|
|
||||||
PgfParseState* tmp = after->next;
|
|
||||||
after->next = before;
|
|
||||||
before = after;
|
|
||||||
after = tmp;
|
|
||||||
}
|
|
||||||
state = before;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (before == NULL)
|
||||||
|
return;
|
||||||
|
|
||||||
|
PgfParseState* after = NULL;
|
||||||
|
|
||||||
|
st = state;
|
||||||
|
while (st != before) {
|
||||||
|
PgfParseState* tmp = st->next;
|
||||||
|
st->next = after;
|
||||||
|
after = st;
|
||||||
|
st = tmp;
|
||||||
|
}
|
||||||
|
|
||||||
|
PgfItem* item;
|
||||||
|
gu_buf_heap_pop(before->agenda, &pgf_item_prob_order, &item);
|
||||||
|
pgf_parsing_item(before, after, item);
|
||||||
|
|
||||||
|
while (after != NULL) {
|
||||||
|
PgfParseState* tmp = after->next;
|
||||||
|
after->next = before;
|
||||||
|
before = after;
|
||||||
|
after = tmp;
|
||||||
|
}
|
||||||
|
state = before;
|
||||||
}
|
}
|
||||||
|
|
||||||
static PgfParsing*
|
static PgfParsing*
|
||||||
@@ -1693,7 +1691,8 @@ pgf_parser_next_state(PgfParseState* prev, PgfToken tok, GuPool* pool)
|
|||||||
pgf_new_parse_state(prev->ps, prev, ts, pool);
|
pgf_new_parse_state(prev->ps, prev, ts, pool);
|
||||||
|
|
||||||
state->ps->target = NULL;
|
state->ps->target = NULL;
|
||||||
pgf_parsing_proceed(state, (void**) &state->ps->target);
|
while (state->ps->target == NULL)
|
||||||
|
pgf_parsing_proceed(state);
|
||||||
if (state->ps->target != NULL) {
|
if (state->ps->target != NULL) {
|
||||||
return state;
|
return state;
|
||||||
}
|
}
|
||||||
@@ -1815,8 +1814,8 @@ pgf_parse_result_next(PgfParseResult* pr, GuPool* pool)
|
|||||||
|
|
||||||
for (;;) {
|
for (;;) {
|
||||||
if (pr->state->ps->completed == NULL) {
|
if (pr->state->ps->completed == NULL) {
|
||||||
pgf_parsing_proceed(pr->state,
|
while (pr->state->ps->completed == NULL)
|
||||||
(void**) &pr->state->ps->completed);
|
pgf_parsing_proceed(pr->state);
|
||||||
if (pr->state->ps->completed == NULL)
|
if (pr->state->ps->completed == NULL)
|
||||||
return NULL;
|
return NULL;
|
||||||
pgf_result_cat_init(pr, NULL, 0, pr->state->ps->completed);
|
pgf_result_cat_init(pr, NULL, 0, pr->state->ps->completed);
|
||||||
|
|||||||
Reference in New Issue
Block a user