From 9c94b75ab21df54c8fd5072b39c5eb17f2fc780e Mon Sep 17 00:00:00 2001 From: Linas Vepstas Date: Sat, 4 Feb 2023 12:56:10 -0600 Subject: [PATCH 1/2] Change linkage limit to match link-parser command This allows the output of the python code to be directly compared to what link-parser is printing. It also allows the python unit tests to pass, after the changes to be made in the next commit. Basically, the spell-check test failed, because the desired spell correction never showed up in the smaller sample. Because !spell=99 was set and !max-linkages=100 and so random sampling kicked in. --- bindings/python/linkgrammar.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bindings/python/linkgrammar.py b/bindings/python/linkgrammar.py index 520de869ca..2becbfe2ed 100644 --- a/bindings/python/linkgrammar.py +++ b/bindings/python/linkgrammar.py @@ -30,7 +30,7 @@ def new_init(self_, *args, **kwargs): class ParseOptions(object): @kwargs_only def __init__(self, verbosity=0, - linkage_limit=100, + linkage_limit=1000, min_null_count=0, max_null_count=0, islands_ok=False, From 321c9b9a3701202d5a04d330d9f48d69e5c05faa Mon Sep 17 00:00:00 2001 From: Linas Vepstas Date: Sat, 4 Feb 2023 13:06:40 -0600 Subject: [PATCH 2/2] Eliminate the tail pointer from the parse set. It is not needed, it makes no difference, it uses space, and it makes the code more complicated. --- link-grammar/parse/extract-links.c | 32 ++++++++---------------------- 1 file changed, 8 insertions(+), 24 deletions(-) diff --git a/link-grammar/parse/extract-links.c b/link-grammar/parse/extract-links.c index 457046d03d..2b9e56958b 100644 --- a/link-grammar/parse/extract-links.c +++ b/link-grammar/parse/extract-links.c @@ -48,6 +48,7 @@ struct Parse_choice_struct * tracons l_id and r_id on words lw and rw, correspondingly. */ struct Parse_set_struct { + Parse_choice * first; short lw, rw; /* left and right word index */ unsigned int null_count; /* number of island words */ int l_id, r_id; /* tracons on words lw, rw */ @@ -62,8 +63,6 @@ struct Parse_set_struct #else #define RECOUNT(X) /* Make it disappear... */ #endif - Parse_choice * first; - Parse_choice * tail; }; typedef struct Pset_bucket_struct Pset_bucket; @@ -123,32 +122,18 @@ make_choice(Parse_set *lset, Connector * llc, Connector * lrc, return pc; } -/** - * Put this parse_choice into a given set. The tail pointer is always - * left pointing to the end of the list. - */ -static void put_choice_in_set(Parse_set *s, Parse_choice *pc) -{ - if (s->first == NULL) - { - s->first = pc; - } - else - { - s->tail->next = pc; - } - s->tail = pc; - pc->next = NULL; -} - static void record_choice( Parse_set *lset, Connector * llc, Connector * lrc, Parse_set *rset, Connector * rlc, Connector * rrc, Disjunct *md, Parse_set *s, extractor_t* pex) { - put_choice_in_set(s, make_choice(lset, llc, lrc, - rset, rlc, rrc, - md, pex)); + Parse_choice *pc = make_choice(lset, llc, lrc, + rset, rlc, rrc, + md, pex); + + // Chain it into the parse set. + pc->next = s->first; + s->first = pc; } /** @@ -283,7 +268,6 @@ static Pset_bucket * x_table_store(int lw, int rw, n->set.r_id = (NULL != re) ? re->tracon_id : rw; n->set.count = 0; n->set.first = NULL; - n->set.tail = NULL; h = pair_hash(lw, rw, n->set.l_id, n->set.r_id, null_count); t = &pex->x_table[h & (pex->x_table_size -1)];