From 1a0a7f9d09b91e01d6ca652f089480b6b6146986 Mon Sep 17 00:00:00 2001 From: Krasimir Angelov Date: Thu, 13 Aug 2026 08:11:45 +0200 Subject: [PATCH] make sure that we don't miss low-prob trees --- src/runtime/c/pgf/parser.cxx | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/src/runtime/c/pgf/parser.cxx b/src/runtime/c/pgf/parser.cxx index 3a18d5c50..6c2de6cf1 100644 --- a/src/runtime/c/pgf/parser.cxx +++ b/src/runtime/c/pgf/parser.cxx @@ -1471,7 +1471,7 @@ void PgfParser::final_item(State *state, CCat *ccat, Item *item, interval_t valu estate->expr = 0; estate->prob = 0; estate->hash = 0; - estate->res = NULL; + estate->res = ccat; estate->index = 0; estate->n_args = item->args.size(); for (size_t i = 0; i < estate->n_args; i++) { @@ -1480,6 +1480,24 @@ void PgfParser::final_item(State *state, CCat *ccat, Item *item, interval_t valu } queue.push_back(estate); std::push_heap(queue.begin(), queue.end(), estate_comp); + } else if (ccat != NULL && ccat->pending.size() > 0) { + auto lin = ref::untagged(item->rule->container); + ExprState *estate = new(item->args.size()) ExprState; + estate->expr = u->efun(&lin->name); + estate->prob = ccat->pending[0]->prob-ccat->viterbi_prob+lin->absfun->prob; + estate->hash = 0; + estate->res = ccat; + estate->index = 0; + estate->n_args = item->args.size(); + for (size_t i = 0; i < lin->name.size; i++) { + estate->hash = estate->hash * 101 + lin->name.text[i]; + } + for (size_t i = 0; i < estate->n_args; i++) { + estate->args[i] = item->args[i]; + estate->prob += estate->args[i]->viterbi_prob; + } + queue.push_back(estate); + std::push_heap(queue.begin(), queue.end(), estate_comp); } }