Skip to content

Commit

Permalink
Attempt to issue linakges in sorted order.
Browse files Browse the repository at this point in the history
Something like this could almost work, if we had left and right
cumulative costs.  See issue opencog#1451
  • Loading branch information
linas committed Feb 24, 2023
1 parent acb424d commit ce0200a
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 0 deletions.
27 changes: 27 additions & 0 deletions link-grammar/parse/extract-links.c
Original file line number Diff line number Diff line change
Expand Up @@ -122,9 +122,18 @@ static void record_choice(
{
Parse_choice *pc = make_choice(lset, lrc, rset, rlc, md, pex);

// Place in sorted order.
if (s->first) {
Parse_choice *last = s->first;
while (last->next && pc->md->cost > last->md->cost) last=last->next;
pc->next = last->next;
last->next = pc;
printf("duuuude chained last ccost=%f nextcost=%f\n", pc->md->cost, last->md->cost);
} else {
// Chain it into the parse set.
pc->next = s->first;
s->first = pc;
}
s->num_pc++;
}

Expand Down Expand Up @@ -838,8 +847,26 @@ static void list_links(Linkage lkg, Parse_set * set, int index)
}
assert(pc != NULL, "walked off the end in list_links");
issue_links_for_choice(lkg, pc, set);

if (NULL == pc->set[0]->first) {
list_links(lkg, pc->set[1], index);
return;
}

if (NULL == pc->set[1]->first) {
list_links(lkg, pc->set[0], index);
return;
}

float lcost = pc->set[0]->first->md->cost;
float rcost = pc->set[1]->first->md->cost;
if (lcost < rcost) {
list_links(lkg, pc->set[0], index % pc->set[0]->count);
list_links(lkg, pc->set[1], index / pc->set[0]->count);
} else {
list_links(lkg, pc->set[0], index / pc->set[1]->count);
list_links(lkg, pc->set[1], index % pc->set[1]->count);
}
}

static void list_random_links(Linkage lkg, unsigned int *rand_state,
Expand Down
3 changes: 3 additions & 0 deletions link-grammar/parse/parse.c
Original file line number Diff line number Diff line change
Expand Up @@ -519,6 +519,9 @@ static void sort_linkages(Sentence sent, Parse_Options opts)
for (uint32_t i=0; i<sent->num_linkages_alloced; i++)
sent->lnkages[i].dupe = false;

for (uint32_t i=0; i<sent->num_linkages_alloced; i++)
printf("duuude i=%u cost=%f\n", i, sent->lnkages[i].lifo.disjunct_cost);

/* Sorting will also mark some of them as being duplicates */
qsort((void *)sent->lnkages, sent->num_linkages_alloced,
sizeof(struct Linkage_s),
Expand Down

0 comments on commit ce0200a

Please sign in to comment.