opencog / atomspace

The OpenCog (hyper-)graph database and graph rewriting system
https://wiki.opencog.org/w/AtomSpace
Other
801 stars 224 forks source link

BindLink clause with an evaluatable of uncommon variable #171

Closed williampma closed 8 years ago

williampma commented 8 years ago

Very related to https://github.com/opencog/atomspace/issues/165 as it passes through the same code path to check whether to Pattern Match.

guile> (define B 
(BindLink 
   (VariableList (VariableNode "$A") (VariableNode "$B") (VariableNode "$C"))
   (AndLink
      (InheritanceLink (VariableNode "$A") (VariableNode "$B"))
      (EqualLink (VariableNode "$A") (VariableNode "$C")))
   (ListLink (VariableNode "$A") (VariableNode "$B") (VariableNode "$C"))))

guile> (InheritanceLink (ConceptNode "dog") (ConceptNode "cat"))
(InheritanceLink
   (ConceptNode "dog")
   (ConceptNode "cat")
)

guile> (cog-bind B)
(SetLink
)

If the evaluatable contains a variable that is not in common with any of the other non-evalutable clause, it cannot solve it. This is because Pattern Matcher tries to solve the non-virtual clause first, then use the mapping to evaluate the virtual, so the variables that are unique to the virtual clause is not grounded.

linas commented 8 years ago

Hmm, that is the the intended behavior. Rather than trying to fix this, we should check to see that all variablees appear somewhere, where they can be grounded, and throw an error when this is not the case.

(The alternative is just to try every-possible grounding for the thing, which is yucky, in part because such a search space can be huge. Despite your good example, I'm tempted to say that such implicit behavior s not what most users would desire...)

linas commented 8 years ago

Perhaps I was unclear. The pattern B is an invalid pattern, and so this is a user error. The Variable $C never appears in any term where it would result in it's being grounded. Thus, $C has no grounding, the EqualLink will always evaluate to false, and thus, you get no result back. What should have happened is that an error is thrown: the $C never appears in any non-evaluatable clause. This would at least let you know the expression is ill-formed.

linas commented 8 years ago

I just pushed an explicit check for a very similar fix, in pull request #247.

linas commented 8 years ago

Ooops, I take that back. #247 does explicitly throw an error if you try to define B like the above. Clsoing, please re-open if you disagree/dislike this ...