Skip to content

Commit

Permalink
Merge pull request opencog#27 from kasimebrahim/misc-bug-fix
Browse files Browse the repository at this point in the history
Misc bug fix
  • Loading branch information
ngeiswei authored Nov 10, 2020
2 parents 19fa8e5 + 770259c commit 0cc497f
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 12 deletions.
20 changes: 16 additions & 4 deletions opencog/unify/Unify.cc
Original file line number Diff line number Diff line change
Expand Up @@ -686,8 +686,8 @@ Unify::SolutionSet Unify::ordered_unify(const HandleSeq& lhs,

if (lhs.empty() and rhs.empty()) return SolutionSet(true);

#define is_lh_glob lhs[0]->get_type() == GLOB_NODE
#define is_rh_glob rhs[0]->get_type() == GLOB_NODE
#define is_lh_glob lhs[0]->get_type() == GLOB_NODE and is_declared_variable(lhs[0])
#define is_rh_glob rhs[0]->get_type() == GLOB_NODE and is_declared_variable(rhs[0])

if (!lhs.empty() and !rhs.empty() and !(is_lh_glob) and !(is_rh_glob)){
const auto head_sol = unify(lhs[0], rhs[0], lc, rc);
Expand Down Expand Up @@ -720,8 +720,20 @@ void Unify::ordered_unify_glob(const HandleSeq &lhs,
const auto inter = _variables.get_interval(lhs[0]);
for (size_t i = inter.first;
(i <= inter.second and i <= rhs.size()); i++) {
const Handle r_h =
createLink(HandleSeq(rhs.begin(), rhs.begin() + i), LIST_LINK);
// The condition is to avoid extra complexity when calculating
// type-intersection for glob. Should be fixed from the atomspace
// Variables::is_type.
Handle r_h;
if (i == 1) {
Type rtype = (*rhs.begin())->get_type();
if (GLOB_NODE == rtype)
r_h = *rhs.begin();
else if (QUOTE_LINK == rtype or UNQUOTE_LINK == rtype)
r_h = createLink((*rhs.begin())->getOutgoingSet(), LIST_LINK);
else r_h = createLink(HandleSeq(rhs.begin(), rhs.begin() + i), LIST_LINK);
}
else r_h = createLink(HandleSeq(rhs.begin(), rhs.begin() + i), LIST_LINK);

auto head_sol = flip ?
unify(r_h, lhs[0], rc, lc) :
unify(lhs[0], r_h, lc, rc);
Expand Down
8 changes: 0 additions & 8 deletions tests/unify/UnifyGlobUTest.cxxtest
Original file line number Diff line number Diff line change
Expand Up @@ -500,8 +500,6 @@ void UnifyGlobUTest::test_unify_typed_3()
Unify::SolutionSet(
{{{{U, al(LIST_LINK, {X, Y})}, al(LIST_LINK, {X, Y})},
{{Z, al(LIST_LINK, HandleSeq{})}, al(LIST_LINK, HandleSeq{})}},
{{{U, X}, U},
{{Y, Z, al(LIST_LINK, HandleSeq{})}, al(LIST_LINK, HandleSeq{})}},
{{{U, X}, X},
{{Y, Z, al(LIST_LINK, HandleSeq{})}, al(LIST_LINK, HandleSeq{})}}});
std::cout << "\n expected\n" << oc_to_string(expected) << std::endl;
Expand Down Expand Up @@ -557,16 +555,10 @@ void UnifyGlobUTest::test_unify_typed_4()
{{Z, al(LIST_LINK, HandleSeq{})}, al(LIST_LINK, HandleSeq{})}},
{{{U, X}, U},
{{Y, Z, al(LIST_LINK, HandleSeq{})}, al(LIST_LINK, HandleSeq{})}},
{{{U, X}, X},
{{Y, Z, al(LIST_LINK, HandleSeq{})}, al(LIST_LINK, HandleSeq{})}},
{{{U, Z}, U},
{{Y, X, al(LIST_LINK, HandleSeq{})}, al(LIST_LINK, HandleSeq{})}},
{{{U, Z}, Z},
{{Y, X, al(LIST_LINK, HandleSeq{})}, al(LIST_LINK, HandleSeq{})}},
{{{U, Y}, U},
{{Z, X, al(LIST_LINK, HandleSeq{})}, al(LIST_LINK, HandleSeq{})}},
{{{U, Y}, Y},
{{Z, X, al(LIST_LINK, HandleSeq{})}, al(LIST_LINK, HandleSeq{})}},
{{{U, al(LIST_LINK, {X, Y, Z})}, al(LIST_LINK, {X, Y, Z})}},
{{{U, X, Y, Z, al(LIST_LINK, HandleSeq{})}, al(LIST_LINK, HandleSeq{})}}});
std::cout << "\n expected\n" << oc_to_string(expected) << std::endl;
Expand Down

0 comments on commit 0cc497f

Please sign in to comment.