From f2e1b999b431810f764fc6e81c05f66405dcad21 Mon Sep 17 00:00:00 2001 From: Krasimir Angelov Date: Fri, 28 Aug 2026 11:18:01 +0200 Subject: [PATCH] simpler and correct condition for bu_predict --- src/runtime/c/pgf/parser.cxx | 8 +++++++- src/runtime/c/pgf/parser.h | 1 + 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/src/runtime/c/pgf/parser.cxx b/src/runtime/c/pgf/parser.cxx index bc3e761f2..3e0d75426 100644 --- a/src/runtime/c/pgf/parser.cxx +++ b/src/runtime/c/pgf/parser.cxx @@ -956,6 +956,7 @@ void PgfParser::bu_predict(PgfPhrasetable phrasetable, next_state->end = state->end; next_state->next = state->next; next_state->needs_bind = false; + next_state->did_bu_predict = false; next_state->viterbi_prob = state->viterbi_prob; state->next = next_state; } @@ -1381,6 +1382,7 @@ PgfAbstractParser::State *PgfParser::new_state(const PgfTextSpot &start, prob_t state = new State; state->start = start; state->end = start; + state->did_bu_predict = false; state->viterbi_prob = viterbi_prob; state->next = *prev; *prev = state; @@ -1421,6 +1423,7 @@ void PgfParser::symbol_bind(Item *item, State *state, PgfSymbol sym) next_state->end = state->end; next_state->next = state->next; next_state->needs_bind = false; + next_state->did_bu_predict = false; next_state->viterbi_prob = state->viterbi_prob; state->next = next_state; } @@ -1480,7 +1483,8 @@ void PgfParser::suspend(Cont *cont,Item *item,bool do_predict,ref epsilontable_iter(concr->epsilontable,cont->lincat,f); } - if (do_predict) { + if (!cont->state->did_bu_predict) { + cont->state->did_bu_predict = true; prob_t viterbi_prob = item->inside_prob+item->outside_prob; if (cont->state->needs_bind) { bu_predict(concr->phrasetable4, cont->state, viterbi_prob); @@ -1730,6 +1734,8 @@ PgfParseTableMaker::PgfParseTableMaker(ref concr) current_state = new State; current_state->start.pos = 0; current_state->start.byte_pos = 0; + current_state->needs_bind = false; + current_state->did_bu_predict = false; current_state->end = current_state->start; current_state->viterbi_prob = 0; current_state->next = NULL; diff --git a/src/runtime/c/pgf/parser.h b/src/runtime/c/pgf/parser.h index 29ce2fc7c..ed7b3baa4 100644 --- a/src/runtime/c/pgf/parser.h +++ b/src/runtime/c/pgf/parser.h @@ -99,6 +99,7 @@ protected: struct State { PgfTextSpot start, end; bool needs_bind; + bool did_bu_predict; std::map,Cont*> conts1; std::map conts2; std::map>> completed;