summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorkr.angelov <kr.angelov@gmail.com>2012-06-12 11:30:01 +0000
committerkr.angelov <kr.angelov@gmail.com>2012-06-12 11:30:01 +0000
commitc9c5675e1dba3dc371d53c8255743e0eb38488e2 (patch)
tree8b0ebaee6197c13cc64048b7f25d176c45091141
parent90306fa926bfebec64ffdd61524c67a45330cd46 (diff)
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.
-rw-r--r--src/runtime/c/pgf/data.h1
-rw-r--r--src/runtime/c/pgf/parser.c9
-rw-r--r--src/runtime/c/pgf/pgf.h9
-rw-r--r--src/runtime/c/pgf/reader.c11
4 files changed, 30 insertions, 0 deletions
diff --git a/src/runtime/c/pgf/data.h b/src/runtime/c/pgf/data.h
index 7fe2fc7d3..f85e68cca 100644
--- a/src/runtime/c/pgf/data.h
+++ b/src/runtime/c/pgf/data.h
@@ -245,6 +245,7 @@ struct PgfConcr {
PgfCallbacksMap* callbacks;
int total_cats;
int max_fid;
+ int item_quota;
};
extern GU_DECLARE_TYPE(PgfConcr, struct);
diff --git a/src/runtime/c/pgf/parser.c b/src/runtime/c/pgf/parser.c
index a05600884..10bff32d6 100644
--- a/src/runtime/c/pgf/parser.c
+++ b/src/runtime/c/pgf/parser.c
@@ -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);
diff --git a/src/runtime/c/pgf/pgf.h b/src/runtime/c/pgf/pgf.h
index e14b4c8c8..b42921f09 100644
--- a/src/runtime/c/pgf/pgf.h
+++ b/src/runtime/c/pgf/pgf.h
@@ -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);
diff --git a/src/runtime/c/pgf/reader.c b/src/runtime/c/pgf/reader.c
index 08cc16096..166dc9bd2 100644
--- a/src/runtime/c/pgf/reader.c
+++ b/src/runtime/c/pgf/reader.c
@@ -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;
+}