Skip to content

Commit

Permalink
Fix how unknown word uses links
Browse files Browse the repository at this point in the history
  • Loading branch information
linas committed Nov 4, 2022
1 parent ebf1d4d commit 8d1d591
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 1 deletion.
1 change: 1 addition & 0 deletions link-grammar/dict-atomese/local-as.h
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ Exp* make_sect_exprs(Dictionary dict, const Handle& germ);
Exp* make_pair_exprs(Dictionary dict, const Handle& germ);
Exp* make_cart_pairs(Dictionary dict, const Handle& germ, int arity, bool any);
Exp* make_any_exprs(Dictionary dict);
Exp* make_cart_any(Dictionary dict, int arity);

void or_enchain(Dictionary, Exp* &orhead, Exp*);
void and_enchain_left(Dictionary, Exp* &orhead, Exp* &ortail, Exp*);
Expand Down
5 changes: 4 additions & 1 deletion link-grammar/dict-atomese/lookup-atomese.cc
Original file line number Diff line number Diff line change
Expand Up @@ -427,7 +427,10 @@ Dict_node * as_lookup_list(Dictionary dict, const char *s)

if (local->enable_unknown_word and 0 == strcmp(s, "<UNKNOWN-WORD>"))
{
Exp* exp = make_any_exprs(dict);
// XXX Note the hard-coded 6. I do not understand why 2 is not
// enough. See issue #1351 for a discussion.
// https://github.com/opencog/link-grammar/issues/1351
Exp* exp = make_cart_any(dict, 6);
return make_dn(dict, exp, ssc);
}

Expand Down
33 changes: 33 additions & 0 deletions link-grammar/dict-atomese/word-pairs.cc
Original file line number Diff line number Diff line change
Expand Up @@ -241,4 +241,37 @@ Exp* make_any_exprs(Dictionary dict)
return any;
}

/// Much like make_part_pairs, except that this duplicates the
/// ANY connector. It creates the expression
/// {@ANY- or @ANY+} and {@ANY- or @ANY+} and ... and {@ANY- or @ANY+}
/// This cartesian allows multiple connectors to participate in loops.
/// However, the behavior is ... sruprising. See
/// https://github.com/opencog/link-grammar/issues/1351
/// for a discussion of what this is all about.
Exp* make_cart_any(Dictionary dict, int arity)
{
if (0 >= arity) return nullptr;

Exp* andhead = nullptr;
Exp* andtail = nullptr;

Exp* any = make_any_exprs(dict);

Exp* optex = make_optional_node(dict->Exp_pool, any);

// If its 1-dimensional, we are done.
if (1 == arity) return optex;

and_enchain_right(dict, andhead, andtail, optex);

for (int i=1; i< arity; i++)
{
Exp* opt = make_optional_node(dict->Exp_pool, any);
and_enchain_right(dict, andhead, andtail, opt);
}

return andhead;
}

// ===============================================================
#endif // HAVE_ATOMESE

0 comments on commit 8d1d591

Please sign in to comment.