mirror of
https://github.com/GrammaticalFramework/gf-core.git
synced 2026-05-03 08:12:51 -06:00
bug fix in the management of memory pools in the statistical parser
This commit is contained in:
@@ -1638,12 +1638,12 @@ pgf_parsing_default_beam_size(PgfConcr* concr)
|
|||||||
}
|
}
|
||||||
|
|
||||||
static PgfParsing*
|
static PgfParsing*
|
||||||
pgf_new_parsing(PgfConcr* concr, GuPool* pool)
|
pgf_new_parsing(PgfConcr* concr, GuPool* pool, GuPool* out_pool)
|
||||||
{
|
{
|
||||||
PgfParsing* ps = gu_new(PgfParsing, pool);
|
PgfParsing* ps = gu_new(PgfParsing, pool);
|
||||||
ps->concr = concr;
|
ps->concr = concr;
|
||||||
ps->pool = pool;
|
ps->pool = pool;
|
||||||
ps->out_pool = NULL;
|
ps->out_pool = out_pool;
|
||||||
ps->expr_queue = gu_new_buf(PgfExprState*, pool);
|
ps->expr_queue = gu_new_buf(PgfExprState*, pool);
|
||||||
ps->max_fid = concr->total_cats;
|
ps->max_fid = concr->total_cats;
|
||||||
#ifdef PGF_COUNTS_DEBUG
|
#ifdef PGF_COUNTS_DEBUG
|
||||||
@@ -1861,20 +1861,19 @@ pgf_parser_completions_next(GuEnum* self, void* to, GuPool* pool)
|
|||||||
}
|
}
|
||||||
|
|
||||||
GuEnum*
|
GuEnum*
|
||||||
pgf_parser_completions(PgfParseState* prev, GuString prefix,
|
pgf_parser_completions(PgfParseState* prev, GuString prefix)
|
||||||
GuPool* pool)
|
|
||||||
{
|
{
|
||||||
#ifdef PGF_COUNTS_DEBUG
|
#ifdef PGF_COUNTS_DEBUG
|
||||||
pgf_parsing_print_counts(prev->ps);
|
pgf_parsing_print_counts(prev->ps);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
PgfPrefixTokenState* ts =
|
PgfPrefixTokenState* ts =
|
||||||
pgf_new_token_state(PgfPrefixTokenState, pool);
|
pgf_new_token_state(PgfPrefixTokenState, prev->ps->pool);
|
||||||
ts->en.next = pgf_parser_completions_next;
|
ts->en.next = pgf_parser_completions_next;
|
||||||
ts->prefix = prefix;
|
ts->prefix = prefix;
|
||||||
ts->tp = NULL;
|
ts->tp = NULL;
|
||||||
ts->state =
|
ts->state =
|
||||||
pgf_new_parse_state(prev->ps, prev, &ts->ts, pool);
|
pgf_new_parse_state(prev->ps, prev, &ts->ts, prev->ps->pool);
|
||||||
|
|
||||||
return &ts->en;
|
return &ts->en;
|
||||||
}
|
}
|
||||||
@@ -2101,18 +2100,16 @@ pgf_parse_result_enum_next(GuEnum* self, void* to, GuPool* pool)
|
|||||||
}
|
}
|
||||||
|
|
||||||
PgfExprEnum*
|
PgfExprEnum*
|
||||||
pgf_parse_result(PgfParseState* state, GuPool* pool)
|
pgf_parse_result(PgfParseState* state)
|
||||||
{
|
{
|
||||||
#ifdef PGF_COUNTS_DEBUG
|
#ifdef PGF_COUNTS_DEBUG
|
||||||
pgf_parsing_print_counts(state->ps);
|
pgf_parsing_print_counts(state->ps);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
state->ps->out_pool = pool;
|
|
||||||
|
|
||||||
PgfExprEnum* en =
|
PgfExprEnum* en =
|
||||||
&gu_new_i(pool, PgfParseResult,
|
&gu_new_i(state->ps->pool, PgfParseResult,
|
||||||
.state = state,
|
.state = state,
|
||||||
.en.next = pgf_parse_result_enum_next)->en;
|
.en.next = pgf_parse_result_enum_next)->en;
|
||||||
|
|
||||||
return en;
|
return en;
|
||||||
}
|
}
|
||||||
@@ -2216,7 +2213,8 @@ pgf_parse_print_chunks(PgfParseState* state)
|
|||||||
|
|
||||||
// TODO: s/CId/Cat, add the cid to Cat, make Cat the key to CncCat
|
// TODO: s/CId/Cat, add the cid to Cat, make Cat the key to CncCat
|
||||||
PgfParseState*
|
PgfParseState*
|
||||||
pgf_parser_init_state(PgfConcr* concr, PgfCId cat, size_t lin_idx, GuPool* pool)
|
pgf_parser_init_state(PgfConcr* concr, PgfCId cat, size_t lin_idx,
|
||||||
|
GuPool* pool, GuPool* out_pool)
|
||||||
{
|
{
|
||||||
PgfCncCat* cnccat =
|
PgfCncCat* cnccat =
|
||||||
gu_map_get(concr->cnccats, &cat, PgfCncCat*);
|
gu_map_get(concr->cnccats, &cat, PgfCncCat*);
|
||||||
@@ -2226,7 +2224,7 @@ pgf_parser_init_state(PgfConcr* concr, PgfCId cat, size_t lin_idx, GuPool* pool)
|
|||||||
gu_assert(lin_idx < cnccat->n_lins);
|
gu_assert(lin_idx < cnccat->n_lins);
|
||||||
|
|
||||||
PgfParsing* ps =
|
PgfParsing* ps =
|
||||||
pgf_new_parsing(concr, pool);
|
pgf_new_parsing(concr, pool, out_pool);
|
||||||
PgfParseState* state =
|
PgfParseState* state =
|
||||||
pgf_new_parse_state(ps, NULL, NULL, pool);
|
pgf_new_parse_state(ps, NULL, NULL, pool);
|
||||||
|
|
||||||
|
|||||||
@@ -34,7 +34,7 @@ typedef struct PgfParseState PgfParseState;
|
|||||||
/// Begin parsing
|
/// Begin parsing
|
||||||
PgfParseState*
|
PgfParseState*
|
||||||
pgf_parser_init_state(PgfConcr* concr, PgfCId cat, size_t lin_idx,
|
pgf_parser_init_state(PgfConcr* concr, PgfCId cat, size_t lin_idx,
|
||||||
GuPool* pool);
|
GuPool* pool, GuPool* out_pool);
|
||||||
/**<
|
/**<
|
||||||
* @param parser The parser to use
|
* @param parser The parser to use
|
||||||
*
|
*
|
||||||
@@ -67,8 +67,7 @@ pgf_parser_next_state(PgfParseState* prev, PgfToken tok);
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
GuEnum*
|
GuEnum*
|
||||||
pgf_parser_completions(PgfParseState* prev, GuString prefix,
|
pgf_parser_completions(PgfParseState* prev, GuString prefix);
|
||||||
GuPool* pool);
|
|
||||||
|
|
||||||
void
|
void
|
||||||
pgf_parser_set_beam_size(PgfParseState* state, double beam_size);
|
pgf_parser_set_beam_size(PgfParseState* state, double beam_size);
|
||||||
@@ -90,7 +89,7 @@ pgf_parser_add_literal(PgfConcr *concr, PgfCId cat,
|
|||||||
|
|
||||||
/// Retrieve the current parses from the parse state.
|
/// Retrieve the current parses from the parse state.
|
||||||
PgfExprEnum*
|
PgfExprEnum*
|
||||||
pgf_parse_result(PgfParseState* state, GuPool* pool);
|
pgf_parse_result(PgfParseState* state);
|
||||||
/**<
|
/**<
|
||||||
* @param parse A parse state
|
* @param parse A parse state
|
||||||
*
|
*
|
||||||
|
|||||||
@@ -157,7 +157,7 @@ pgf_parseval(PgfConcr* concr, PgfExpr expr, PgfCId cat,
|
|||||||
|
|
||||||
PgfMetricsLznState state;
|
PgfMetricsLznState state;
|
||||||
state.funcs = &pgf_metrics_lin_funcs1;
|
state.funcs = &pgf_metrics_lin_funcs1;
|
||||||
state.ps = pgf_parser_init_state(concr, cat, 0, pool);
|
state.ps = pgf_parser_init_state(concr, cat, 0, pool, pool);
|
||||||
state.marks = gu_new_buf(int, pool);
|
state.marks = gu_new_buf(int, pool);
|
||||||
state.pos = 0;
|
state.pos = 0;
|
||||||
state.phrases = gu_new_buf(PgfPhrase*, pool);
|
state.phrases = gu_new_buf(PgfPhrase*, pool);
|
||||||
@@ -172,7 +172,7 @@ pgf_parseval(PgfConcr* concr, PgfExpr expr, PgfCId cat,
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
GuEnum* en_trees = pgf_parse_result(state.ps, pool);
|
GuEnum* en_trees = pgf_parse_result(state.ps);
|
||||||
PgfExprProb* ep = gu_next(en_trees, PgfExprProb*, pool);
|
PgfExprProb* ep = gu_next(en_trees, PgfExprProb*, pool);
|
||||||
if (ep == NULL) {
|
if (ep == NULL) {
|
||||||
gu_pool_free(pool);
|
gu_pool_free(pool);
|
||||||
|
|||||||
@@ -212,7 +212,7 @@ pgf_parse(PgfConcr* concr, PgfCId cat, PgfLexer *lexer,
|
|||||||
{
|
{
|
||||||
// Begin parsing a sentence of the specified category
|
// Begin parsing a sentence of the specified category
|
||||||
PgfParseState* state =
|
PgfParseState* state =
|
||||||
pgf_parser_init_state(concr, cat, 0, pool);
|
pgf_parser_init_state(concr, cat, 0, pool, out_pool);
|
||||||
if (state == NULL) {
|
if (state == NULL) {
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
@@ -234,7 +234,7 @@ pgf_parse(PgfConcr* concr, PgfCId cat, PgfLexer *lexer,
|
|||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
// Now begin enumerating the resulting syntax trees
|
// Now begin enumerating the resulting syntax trees
|
||||||
return pgf_parse_result(state, out_pool);
|
return pgf_parse_result(state);
|
||||||
}
|
}
|
||||||
|
|
||||||
GuEnum*
|
GuEnum*
|
||||||
@@ -243,7 +243,7 @@ pgf_get_completions(PgfConcr* concr, PgfCId cat, PgfLexer *lexer,
|
|||||||
{
|
{
|
||||||
// Begin parsing a sentence of the specified category
|
// Begin parsing a sentence of the specified category
|
||||||
PgfParseState* state =
|
PgfParseState* state =
|
||||||
pgf_parser_init_state(concr, cat, 0, pool);
|
pgf_parser_init_state(concr, cat, 0, pool, pool);
|
||||||
if (state == NULL) {
|
if (state == NULL) {
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
@@ -265,7 +265,7 @@ pgf_get_completions(PgfConcr* concr, PgfCId cat, PgfLexer *lexer,
|
|||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
// Now begin enumerating the resulting syntax trees
|
// Now begin enumerating the resulting syntax trees
|
||||||
return pgf_parser_completions(state, prefix, pool);
|
return pgf_parser_completions(state, prefix);
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
@@ -273,7 +273,7 @@ pgf_print_chunks(PgfConcr* concr, PgfCId cat, PgfLexer *lexer, GuPool* pool)
|
|||||||
{
|
{
|
||||||
// Begin parsing a sentence of the specified category
|
// Begin parsing a sentence of the specified category
|
||||||
PgfParseState* state =
|
PgfParseState* state =
|
||||||
pgf_parser_init_state(concr, cat, 0, pool);
|
pgf_parser_init_state(concr, cat, 0, pool, pool);
|
||||||
if (state == NULL) {
|
if (state == NULL) {
|
||||||
printf("\n");
|
printf("\n");
|
||||||
return;
|
return;
|
||||||
|
|||||||
@@ -115,7 +115,7 @@ int main(int argc, char* argv[]) {
|
|||||||
|
|
||||||
// Begin parsing a sentence of the specified category
|
// Begin parsing a sentence of the specified category
|
||||||
PgfParseState* state =
|
PgfParseState* state =
|
||||||
pgf_parser_init_state(concr, cat, 0, ppool);
|
pgf_parser_init_state(concr, cat, 0, ppool, ppool);
|
||||||
if (state == NULL) {
|
if (state == NULL) {
|
||||||
fprintf(stderr, "Couldn't begin parsing\n");
|
fprintf(stderr, "Couldn't begin parsing\n");
|
||||||
status = EXIT_FAILURE;
|
status = EXIT_FAILURE;
|
||||||
|
|||||||
Reference in New Issue
Block a user