opencog / atomspace

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

How to get multiple fuzzy matches? #545

Closed linas closed 8 years ago

linas commented 8 years ago

I would like to get multiple matches from the fuzzy matcher, but can't seem to be able to do that.

So, I try this (afrer loading needed modules):

(nlp-parse "look left")
(nlp-parse "look left")
(nlp-parse "look left")
; yes, three times...
(nlp-parse "look right")
(nlp-parse "look up")
(nlp-parse "look down")

then this

(define s (car (nlp-parse "look to the left")))
(define r2l-set (get-r2l-set-of-sent s))
(define fzset (cog-fuzzy-match r2l-set 'SetLink '()))
(define reply (gen-sentences (cog-outgoing-set fzset)))

Looking at the fzset, I see that I get one of the three "look lefts"; I'd like to get all of them. Is there a way to do that?

There also seems to be a bug. When I do this:

(define s (car (nlp-parse "look to the right")))   ;;; notice its right this time
(define r2l-set (get-r2l-set-of-sent s))
(define fzset (cog-fuzzy-match r2l-set 'SetLink '()))
(define reply (gen-sentences (cog-outgoing-set fzset)))

I get "look left" as the reply. Hmmm This may be a relex bug though ... I will check that shortly.

Whatever happened to the visualizers? this is where an atomspace visualizer would be nice...

leungmanhin commented 8 years ago

For returning only one of the three "look lefts", it's because the fuzzy matcher filter out "identical" matches by default, perhaps I can add one more parameter to the function for this so that we can decide whether or not to do so

leungmanhin commented 8 years ago

Hmmm for the second one, seems like the word "right" is not captured... R2L outputs for "look right":

(ReferenceLink
   (InterpretationNode "sentence@37e9796b-dc8f-4d03-ad36-e4fffee73b53_parse_0_interpretation_$X")
   (SetLink
      (InheritanceLink
         (InterpretationNode "sentence@37e9796b-dc8f-4d03-ad36-e4fffee73b53_parse_0_interpretation_$X")
         (DefinedLinguisticConceptNode "ImperativeSpeechAct")
      )
      (ImplicationLink
         (PredicateNode "look@4697f52f-ce29-40cc-827f-17f03a1726ab")
         (PredicateNode "look" (ptv 1 0 1))
      )
      (InheritanceLink
         (PredicateNode "look@4697f52f-ce29-40cc-827f-17f03a1726ab")
         (DefinedLinguisticConceptNode "imperative")
      )
   )
)

But looks like the same doesn't happen for "look up" or "look down":

(ReferenceLink
   (InterpretationNode "sentence@9009986a-84b7-41a5-a839-03dffcf80a48_parse_0_interpretation_$X")
   (SetLink
      (InheritanceLink
         (InterpretationNode "sentence@9009986a-84b7-41a5-a839-03dffcf80a48_parse_0_interpretation_$X")
         (DefinedLinguisticConceptNode "ImperativeSpeechAct")
      )
      (ImplicationLink
         (PredicateNode "look@1cf0d101-5db2-447f-a5b7-071407fd0344")
         (PredicateNode "look_up" (ptv 1 0 1))
      )
      (InheritanceLink
         (PredicateNode "look@1cf0d101-5db2-447f-a5b7-071407fd0344")
         (DefinedLinguisticConceptNode "imperative")
      )
   )
)
linas commented 8 years ago

I had to make changes to link-grammar to get look-up and look-down to work correctly; the parse (PredicateNode "look_up") is wrong. The fix will be in LG version 5.3.3 in a few days.

linas commented 8 years ago

Hmm. Looks like R2L consistently fails to capture the direction! (no matter what the direction is) I'm looking at that now. That might explain a lot.

linas commented 8 years ago

Oh, OK, that is no surprise. Sometimes relex gives _advmod(look, right) and sometimes relex says _to-be(look, right) both of which are wrong. Unfortunately, there is no good way to fix relex, because relex does not have enough information to do the right thing. It needs to be _to-do(look, right) I'm not sure what r2l is doing.

linas commented 8 years ago

Sigh. it was a link grammar bug.

linas commented 8 years ago

Closing; after the fixes, it now works right. Err. works as designed. Email discussion contains what I want.

(Best match to "look to the right" is "look to the left" ...

leungmanhin commented 8 years ago

Thanks! Additionally PR #546 and opencog/opencog#1951 cover the changes for returning identical matches as mentioned above