Skip to content

Commit a88e5d1

Browse files
committed
Restore original maxcost computation.
Dennis had it right. See issue opencog#1449 This improves parsing of real sentences, without causing damage elsewhere.
1 parent 7c4179a commit a88e5d1

File tree

2 files changed

+16
-14
lines changed

2 files changed

+16
-14
lines changed

ChangeLog

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ Version 5.12.1 (XXX 2023)
99
* English dict: paraphrasing fixes. #1398
1010
* Report CPU time usage only for the current thread. #1399
1111
* Extensive performance optimizations for MST dictionaries. #1402
12+
* Fix incorrect maxcost computation. This is a very old bug. #1450
1213

1314
Version 5.12.0 (26 Nov 2022)
1415
* Fix crash when using the Atomese dictionary backend.

link-grammar/prepare/build-disjuncts.c

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,8 @@ typedef struct clause_struct Clause;
3333
struct clause_struct
3434
{
3535
Clause * next;
36-
float totcost;
37-
float maxcost;
36+
float totcost; // Total cost of all connectors in the clause
37+
float maxcost; // Cost of the most costly lingle connector.
3838
Tconnector * c;
3939
};
4040

@@ -148,14 +148,10 @@ static Clause * build_clause(Exp *e, clause_context *ct, Clause **c_last)
148148
{
149149
for (Clause *c4 = c2; c4 != NULL; c4 = c4->next)
150150
{
151-
float maxcost = MAX(c3->maxcost,c4->maxcost);
152-
/* Cannot use this shortcut due to negative costs. */
153-
//if (maxcost + e->cost > ct->cost_cutoff) continue;
154-
155151
Clause *c5 = pool_alloc(ct->Clause_pool);
156152
if ((c_head == NULL) && (c_last != NULL)) *c_last = c5;
153+
c5->maxcost = MAX(c3->maxcost, c4->maxcost);
157154
c5->totcost = c3->totcost + c4->totcost;
158-
c5->maxcost = maxcost;
159155
c5->c = catenate(c4->c, c3->c, ct->Tconnector_pool);
160156
c5->next = c_head;
161157
c_head = c5;
@@ -204,14 +200,19 @@ static Clause * build_clause(Exp *e, clause_context *ct, Clause **c_last)
204200
/* c now points to the list of clauses */
205201
for (Clause *c1 = c; c1 != NULL; c1 = c1->next)
206202
{
207-
c1->totcost += e->cost;
208-
/* c1->maxcost = MAX(c1->maxcost,e->cost); */
209-
/* Above is how Dennis had it. Someone changed it to below.
210-
* However, this can sometimes lead to a maxcost that is less
211-
* than the cost ! -- which seems wrong to me ... seems Dennis
212-
* had it right!?
203+
/* The maxcost is the most costly single connector in the
204+
* expression. It is used, in conjunction with the cost_cutoff,
205+
* to reject clauses which contain a single costly connector
206+
* in them. This allows cost_cutoff to be raised for panic
207+
* parses, thus allowing perhaps-dubious disjuncts into the
208+
* parse. Note that maxcost can be less than totcost, because
209+
* the totcost might be the sum of many low-cost connectors,
210+
* sum sums can get large. (maxcost is the Banach l_0 norm,
211+
* while totcost is the Banach l_1 norm).
213212
*/
214-
c1->maxcost += e->cost;
213+
c1->maxcost = MAX(c1->maxcost, e->cost);
214+
c1->totcost += e->cost;
215+
215216
/* Note: The above computation is used as a saving shortcut in
216217
* the inner loop of AND_type. If it is changed here, it needs to be
217218
* changed there too. */

0 commit comments

Comments
 (0)