diff options
| author | kr.angelov <kr.angelov@gmail.com> | 2013-07-03 12:30:30 +0000 |
|---|---|---|
| committer | kr.angelov <kr.angelov@gmail.com> | 2013-07-03 12:30:30 +0000 |
| commit | 8f2032a07de4e6d50c8f853a5612e6a2f24d9368 (patch) | |
| tree | 043ff997d0d57254d6d0fbed80af68c103abef35 | |
| parent | f0c703d42f85c87411966714c14aec8087819125 (diff) | |
the parser in the C runtime now checks for duplicated results
| -rw-r--r-- | src/runtime/c/pgf/parser.c | 25 |
1 files changed, 24 insertions, 1 deletions
diff --git a/src/runtime/c/pgf/parser.c b/src/runtime/c/pgf/parser.c index 6cf095740..52fa0cf9a 100644 --- a/src/runtime/c/pgf/parser.c +++ b/src/runtime/c/pgf/parser.c @@ -2025,6 +2025,29 @@ pgf_result_predict(PgfParsing* ps, } } +static bool +pgf_parse_result_is_new(PgfExprState* st) +{ + // we have found a complete abstract tree but we must check + // whether this is not a duplication. Since the trees are + // generated in probability order it is enough to check only + // trees with the same probability. + + size_t i = gu_buf_length(st->answers->exprs); + while (i-- > 0) { + PgfExprProb* ep = + gu_buf_get(st->answers->exprs, PgfExprProb*, i); + + if (ep->prob < st->ep.prob) + break; + + if (pgf_expr_eq(ep->expr, st->ep.expr)) + return false; + } + + return true; +} + static PgfExprProb* pgf_parse_result_next(PgfParseResult* pr) { @@ -2063,7 +2086,7 @@ pgf_parse_result_next(PgfParseResult* pr) } else { pgf_result_predict(pr->state->ps, st, ccat); } - } else { + } else if (pgf_parse_result_is_new(st)) { gu_buf_push(st->answers->exprs, PgfExprProb*, &st->ep); size_t n_conts = gu_buf_length(st->answers->conts); |
