forked from GitHub/gf-core
now there is a limit of 2000000 items in the chart of the robust parser. This prevents from explosion in the memory size but it will also prevent us from parsing some sentences.
This commit is contained in:
@@ -245,6 +245,7 @@ struct PgfConcr {
|
||||
PgfCallbacksMap* callbacks;
|
||||
int total_cats;
|
||||
int max_fid;
|
||||
int item_quota;
|
||||
};
|
||||
|
||||
extern GU_DECLARE_TYPE(PgfConcr, struct);
|
||||
|
||||
@@ -31,6 +31,7 @@ typedef struct {
|
||||
PgfItem* target;
|
||||
PgfProduction meta_prod;
|
||||
int max_fid;
|
||||
int item_count;
|
||||
} PgfParsing;
|
||||
|
||||
typedef struct {
|
||||
@@ -686,6 +687,7 @@ pgf_parsing_production(PgfParseState* state,
|
||||
{
|
||||
PgfItem* item =
|
||||
pgf_new_item(state->offset, ccat, lin_idx, prod, conts, delta_prob, state->pool);
|
||||
state->ps->item_count++;
|
||||
gu_buf_heap_push(state->agenda, &pgf_item_prob_order, &item);
|
||||
}
|
||||
|
||||
@@ -875,6 +877,7 @@ pgf_parsing_td_predict(PgfParseState* before, PgfParseState* after,
|
||||
// Top-down prediction for meta rules
|
||||
PgfItem *item =
|
||||
pgf_new_item(before->offset, ccat, lin_idx, before->ps->meta_prod, conts, 0, before->pool);
|
||||
before->ps->item_count++;
|
||||
item->inside_prob =
|
||||
ccat->cnccat->abscat->meta_prob;
|
||||
gu_buf_heap_push(before->agenda, &pgf_item_prob_order, &item);
|
||||
@@ -1425,6 +1428,9 @@ static PgfLiteralCallback pgf_meta_callback =
|
||||
static void
|
||||
pgf_parsing_proceed(PgfParseState* state, void** output) {
|
||||
while (*output == NULL) {
|
||||
if (state->ps->item_count > state->ps->concr->item_quota)
|
||||
break;
|
||||
|
||||
float best_prob = INFINITY;
|
||||
PgfParseState* before = NULL;
|
||||
|
||||
@@ -1476,6 +1482,7 @@ pgf_new_parsing(PgfConcr* concr, GuPool* pool)
|
||||
ps->completed = NULL;
|
||||
ps->target = NULL;
|
||||
ps->max_fid = concr->max_fid;
|
||||
ps->item_count = 0;
|
||||
|
||||
PgfProductionExtern* pext =
|
||||
gu_new_variant(PGF_PRODUCTION_EXTERN,
|
||||
@@ -1757,11 +1764,13 @@ pgf_parser_init_state(PgfConcr* concr, PgfCId cat, size_t lin_idx, GuPool* pool)
|
||||
gu_seq_get(prods, PgfProduction, i);
|
||||
PgfItem* item =
|
||||
pgf_new_item(0, ccat, lin_idx, prod, conts, 0, pool);
|
||||
ps->item_count++;
|
||||
gu_buf_heap_push(state->agenda, &pgf_item_prob_order, &item);
|
||||
}
|
||||
|
||||
PgfItem *item =
|
||||
pgf_new_item(0, ccat, lin_idx, ps->meta_prod, conts, 0, pool);
|
||||
ps->item_count++;
|
||||
item->inside_prob =
|
||||
ccat->cnccat->abscat->meta_prob;
|
||||
gu_buf_heap_push(state->agenda, &pgf_item_prob_order, &item);
|
||||
|
||||
@@ -72,6 +72,15 @@ pgf_read(GuIn* in, GuPool* pool, GuExn* err);
|
||||
bool
|
||||
pgf_load_meta_child_probs(PgfPGF*, const char* fpath, GuPool* pool);
|
||||
|
||||
typedef struct PgfConcr PgfConcr;
|
||||
|
||||
void
|
||||
pgf_set_item_quota(PgfConcr* concr, int quota);
|
||||
|
||||
int
|
||||
pgf_get_item_quota(PgfConcr* concr);
|
||||
|
||||
|
||||
#include <gu/type.h>
|
||||
extern GU_DECLARE_TYPE(PgfPGF, struct);
|
||||
|
||||
|
||||
@@ -791,6 +791,7 @@ pgf_read_new_PgfConcr(GuType* type, PgfReader* rdr, GuPool* pool,
|
||||
concr->callbacks = pgf_new_callbacks_map(concr, pool);
|
||||
concr->total_cats = pgf_read_int(rdr);
|
||||
concr->max_fid = concr->total_cats;
|
||||
concr->item_quota = 2000000;
|
||||
|
||||
// set the function ids
|
||||
int n_funs = gu_list_length(concr->cncfuns);
|
||||
@@ -987,3 +988,13 @@ pgf_load_meta_child_probs(PgfPGF* pgf, const char* fpath, GuPool* pool)
|
||||
fclose(fp);
|
||||
return true;
|
||||
}
|
||||
|
||||
void
|
||||
pgf_set_item_quota(PgfConcr* concr, int quota) {
|
||||
concr->item_quota = quota > 0 ? quota : 0;
|
||||
}
|
||||
|
||||
int
|
||||
pgf_get_item_quota(PgfConcr* concr) {
|
||||
return concr->item_quota;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user