opencog / atomspace

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

Pattern Matcher unexpected exception #210

Closed linas closed 8 years ago

linas commented 8 years ago

The following throws an exception, which is not expected:

(EvaluationLink
   (ConceptNode "arkle")
   (ConceptNode "barkle")
   (ConceptNode "curry"))

(EvaluationLink
   (ConceptNode "glib")
   (ConceptNode "blab"))

(define bnd
(BindLink
   ;(VariableList (VariableNode "$a") (VariableNode "$b")
   ;   (TypedVariableLink (VariableNode "$lnk")
   ;       (TypeNode "EvaluationLink")))
   (AndLink
       (VariableNode "$lnk")
       (EvaluationLink
           (VariableNode "$a")
           (VariableNode "$b"))
       (EqualLink
           (VariableNode "$lnk")
           (EvaluationLink
               (VariableNode "$a")
               (VariableNode "$b"))))
   (VariableNode "$lnk")
))
(cog-bind bnd)

It does not throw when the VariableList is uncommented, so that the type restrictions are enforced. This is unexpected, because both versions should return the same answer, although the version with the type declarations should run faster, as it prunes some un-needed searches.

jswiergo commented 8 years ago

In this case the instantiator is evaluating following solution during pattern matching:

(EqualLink (stv 1,000000 0,000000)
  (BindLink (stv 1,000000 0,000000)
    (AndLink (stv 1,000000 0,000000)
      (VariableNode "$lnk") ; [9]
      (EvaluationLink (stv 1,000000 0,000000)
        (VariableNode "$a") ; [10]
        (VariableNode "$b") ; [11]
      ) ; [18446744073709551615]
      (EqualLink (stv 1,000000 0,000000)
        (VariableNode "$lnk") ; [9]
        (EvaluationLink (stv 1,000000 0,000000)
          (VariableNode "$a") ; [10]
          (VariableNode "$b") ; [11]
        ) ; [18446744073709551615]
      ) ; [18446744073709551615]
    ) ; [18446744073709551615]
    (VariableNode "$lnk") ; [9]
  ) ; [18446744073709551615]
  (EvaluationLink (stv 1,000000 0,000000)
    (ConceptNode "glib") ; [6]
    (ConceptNode "blab") ; [7]
  ) ; [18446744073709551615]
) ; [18446744073709551615]

When the type restrictions are enabled this solution is pruned earlier. Also when my previous fix #243 is merged this solution is pruned because the fix does not allow to ground variable $lnk by atom containing $lnk as it is in this situation.

The exception is caused by constructor of BindLink atom above during validation of its clauses. I have checked deeper and it turned out that some FindUtils methods do not support searching of the atom tree which is not in the atomspace yet. I will send small fix for that. The strange max int numbers above are due to optimisation in the instantiator which creates new atom tree, but instantiate it in the atomspace at the end only.

linas commented 8 years ago

Thanks!

I am interested in getting as much of the infrastructure as possible to work correctly, even if atoms are not in the atomspace. So yes, please send a FindUtils fix if you have one!

linas commented 8 years ago

This is closely related to #211 and also pull req #244 affects this.

williampma commented 8 years ago

What about https://github.com/opencog/atomspace/issues/172? The BindLink constructor exception is the same one right?

linas commented 8 years ago

I just tried #172 and it seems to work for me.

williampma commented 8 years ago

Reopening this as well, since it's the exact same issue as #172 (trying to create BindLink in _temp_aspace for evaluatable). The fact it doesn't crash anymore is just a side effect of those functions in FindUtils always return true.

linas commented 8 years ago

Hah?? If it doesn't crash any more, then what is the issue? This particular bug is fixed; if you have a new bug, open a new bug report and describe that bug.