diff options
| author | kr.angelov <kr.angelov@gmail.com> | 2013-06-26 07:36:03 +0000 |
|---|---|---|
| committer | kr.angelov <kr.angelov@gmail.com> | 2013-06-26 07:36:03 +0000 |
| commit | 3c2d1890d0c5de25bbaa7c582c20bcd67bc47d8c (patch) | |
| tree | 9091c47c4693ab1ef14b98fc76726fec8c56c2f5 /src/runtime/c/pgf | |
| parent | d94b6146f2074608fba07421dd6185ac3a296680 (diff) | |
patch for adjustable heuristics from Python
Diffstat (limited to 'src/runtime/c/pgf')
| -rw-r--r-- | src/runtime/c/pgf/parser.c | 18 | ||||
| -rw-r--r-- | src/runtime/c/pgf/parser.h | 4 | ||||
| -rw-r--r-- | src/runtime/c/pgf/parseval.c | 2 | ||||
| -rw-r--r-- | src/runtime/c/pgf/pgf.c | 40 | ||||
| -rw-r--r-- | src/runtime/c/pgf/pgf.h | 10 |
5 files changed, 26 insertions, 48 deletions
diff --git a/src/runtime/c/pgf/parser.c b/src/runtime/c/pgf/parser.c index a1d8084ed..899628f6a 100644 --- a/src/runtime/c/pgf/parser.c +++ b/src/runtime/c/pgf/parser.c @@ -1638,7 +1638,8 @@ pgf_parsing_default_beam_size(PgfConcr* concr) } static PgfParsing* -pgf_new_parsing(PgfConcr* concr, GuPool* pool, GuPool* out_pool) +pgf_new_parsing(PgfConcr* concr, double heuristics, + GuPool* pool, GuPool* out_pool) { PgfParsing* ps = gu_new(PgfParsing, pool); ps->concr = concr; @@ -1654,7 +1655,7 @@ pgf_new_parsing(PgfConcr* concr, GuPool* pool, GuPool* out_pool) ps->prod_full_count = 0; #endif ps->free_item = NULL; - ps->beam_size = pgf_parsing_default_beam_size(concr); + ps->beam_size = heuristics; PgfExprMeta *expr_meta = gu_new_variant(PGF_EXPR_META, @@ -2214,6 +2215,7 @@ pgf_parse_print_chunks(PgfParseState* state) // TODO: s/CId/Cat, add the cid to Cat, make Cat the key to CncCat PgfParseState* pgf_parser_init_state(PgfConcr* concr, PgfCId cat, size_t lin_idx, + double heuristics, GuPool* pool, GuPool* out_pool) { PgfCncCat* cnccat = @@ -2223,8 +2225,12 @@ pgf_parser_init_state(PgfConcr* concr, PgfCId cat, size_t lin_idx, gu_assert(lin_idx < cnccat->n_lins); + if (heuristics < 0) { + heuristics = pgf_parsing_default_beam_size(concr); + } + PgfParsing* ps = - pgf_new_parsing(concr, pool, out_pool); + pgf_new_parsing(concr, heuristics, pool, out_pool); PgfParseState* state = pgf_new_parse_state(ps, NULL, NULL, pool); @@ -2270,12 +2276,6 @@ pgf_parser_init_state(PgfConcr* concr, PgfCId cat, size_t lin_idx, } void -pgf_parser_set_beam_size(PgfParseState* state, double beam_size) -{ - state->ps->beam_size = beam_size; -} - -void pgf_parser_add_literal(PgfConcr *concr, PgfCId cat, PgfLiteralCallback* callback) { diff --git a/src/runtime/c/pgf/parser.h b/src/runtime/c/pgf/parser.h index 8c4ba77e9..b49cba868 100644 --- a/src/runtime/c/pgf/parser.h +++ b/src/runtime/c/pgf/parser.h @@ -34,6 +34,7 @@ typedef struct PgfParseState PgfParseState; /// Begin parsing PgfParseState* pgf_parser_init_state(PgfConcr* concr, PgfCId cat, size_t lin_idx, + double heuristics, GuPool* pool, GuPool* out_pool); /**< * @param parser The parser to use @@ -70,9 +71,6 @@ GuEnum* pgf_parser_completions(PgfParseState* prev, GuString prefix); void -pgf_parser_set_beam_size(PgfParseState* state, double beam_size); - -void pgf_parser_add_literal(PgfConcr *concr, PgfCId cat, PgfLiteralCallback* callback); diff --git a/src/runtime/c/pgf/parseval.c b/src/runtime/c/pgf/parseval.c index 70b2666fd..eed216b82 100644 --- a/src/runtime/c/pgf/parseval.c +++ b/src/runtime/c/pgf/parseval.c @@ -157,7 +157,7 @@ pgf_parseval(PgfConcr* concr, PgfExpr expr, PgfCId cat, PgfMetricsLznState state; state.funcs = &pgf_metrics_lin_funcs1; - state.ps = pgf_parser_init_state(concr, cat, 0, pool, pool); + state.ps = pgf_parser_init_state(concr, cat, 0, -1, pool, pool); state.marks = gu_new_buf(int, pool); state.pos = 0; state.phrases = gu_new_buf(PgfPhrase*, pool); diff --git a/src/runtime/c/pgf/pgf.c b/src/runtime/c/pgf/pgf.c index f1b85cae3..95b2132f5 100644 --- a/src/runtime/c/pgf/pgf.c +++ b/src/runtime/c/pgf/pgf.c @@ -211,9 +211,17 @@ GuEnum* pgf_parse(PgfConcr* concr, PgfCId cat, PgfLexer *lexer, GuPool* pool, GuPool* out_pool) { + return pgf_parse_with_heuristics(concr, cat, lexer, -1.0, pool, out_pool); +} + +GuEnum* +pgf_parse_with_heuristics(PgfConcr* concr, PgfCId cat, PgfLexer *lexer, + double heuristics, + GuPool* pool, GuPool* out_pool) +{ // Begin parsing a sentence of the specified category PgfParseState* state = - pgf_parser_init_state(concr, cat, 0, pool, out_pool); + pgf_parser_init_state(concr, cat, 0, heuristics, pool, out_pool); if (state == NULL) { return NULL; } @@ -244,7 +252,7 @@ pgf_get_completions(PgfConcr* concr, PgfCId cat, PgfLexer *lexer, { // Begin parsing a sentence of the specified category PgfParseState* state = - pgf_parser_init_state(concr, cat, 0, pool, pool); + pgf_parser_init_state(concr, cat, 0, -1, pool, pool); if (state == NULL) { return NULL; } @@ -268,31 +276,3 @@ pgf_get_completions(PgfConcr* concr, PgfCId cat, PgfLexer *lexer, // Now begin enumerating the resulting syntax trees return pgf_parser_completions(state, prefix); } - -void -pgf_print_chunks(PgfConcr* concr, PgfCId cat, PgfLexer *lexer, GuPool* pool) -{ - // Begin parsing a sentence of the specified category - PgfParseState* state = - pgf_parser_init_state(concr, cat, 0, pool, pool); - if (state == NULL) { - printf("\n"); - return; - } - - // Tokenization - GuExn* lex_err = gu_new_exn(NULL, gu_kind(type), pool); - PgfToken tok = pgf_lexer_read_token(lexer, lex_err); - while (!gu_exn_is_raised(lex_err)) { - // feed the token to get a new parse state - state = pgf_parser_next_state(state, tok); - if (state == NULL) { - printf("\n"); - return; - } - - tok = pgf_lexer_read_token(lexer, lex_err); - } - - pgf_parse_print_chunks(state); -} diff --git a/src/runtime/c/pgf/pgf.h b/src/runtime/c/pgf/pgf.h index d83598cc0..2e7e43584 100644 --- a/src/runtime/c/pgf/pgf.h +++ b/src/runtime/c/pgf/pgf.h @@ -117,6 +117,11 @@ PgfExprEnum* pgf_parse(PgfConcr* concr, PgfCId cat, PgfLexer *lexer, GuPool* pool, GuPool* out_pool); +PgfExprEnum* +pgf_parse_with_heuristics(PgfConcr* concr, PgfCId cat, PgfLexer *lexer, + double heuristics, + GuPool* pool, GuPool* out_pool); + GuEnum* pgf_get_completions(PgfConcr* concr, PgfCId cat, PgfLexer *lexer, GuString prefix, GuPool* pool); @@ -128,11 +133,6 @@ pgf_parseval(PgfConcr* concr, PgfExpr expr, PgfCId cat, PgfExprEnum* pgf_generate(PgfPGF* pgf, PgfCId cat, GuPool* pool); -// an experimental function. Please don't use it -void -pgf_print_chunks(PgfConcr* concr, PgfCId cat, PgfLexer *lexer, GuPool* pool); - - /// @} void |
