Why is cog-bind writing the VariableNode in the <instantiated-pattern> part of BindLink to Atomspace?

33 views
Skip to first unread message

Gaurav Gautam

unread,
Jul 17, 2016, 11:26:33 AM7/17/16
to opencog
Hello,

I was adding some things to the third lesson in Hands_On_With_OpenCog when I came across this.
I have attached the guile script to this post so you can look at the whole thing.

I used cog-bind to perform a graph-rewrite to do the following:
1. Look for all atoms that are types of Animals
2. Create a new InheritanceLink to mark all such nodes as Pets

;The BindLink
(define rewrite
    (BindLink

        ;Declare the variables [optional]
        (VariableNode "$denizen")
        ;Declare the pattern used to ground the variables
        (InheritanceLink
            (VariableNode "$denizen")
            (ConceptNode "Animal")
        )

        ;If a match is found for the pattern then we want
        ;to add the following hypergraph ot the Atomspace

        (InheritanceLink
            (VariableNode "$denizen")
            (ConceptNode "Pet")
        )
    )
)


The output of bind-link is as expected:
(SetLink
   (InheritanceLink
      (ConceptNode "fish")
      (ConceptNode "Pet")
   )
   (InheritanceLink
      (ConceptNode "dog")
      (ConceptNode "Pet")
   )
   (InheritanceLink
      (ConceptNode "cat")
      (ConceptNode "Pet")
   )
)

But when I run a cog-satisfying-set query to look for all pets in the Atomspace I find that a new Pet has been defined
with the name "$denizen".
The pattern I use for cog-satisfying-set is:
(define petnode
    (SatisfactionLink
        ;Declare varibales [optional]
        (VariableNode "$animal")
        ;The pattern that the variable must satisfy
        (InheritanceLink
            (VariableNode "$animal")
            (ConceptNode "Pet")
        )
    )
)


The output is:
(SetLink
   (ConceptNode "fish")
   (ConceptNode "dog")
   (ConceptNode "cat")
   (VariableNode "$denizen") <--- This is the thing I don't understand
)


Is this the expected behavior for bind-link? I thought that the "$denizen" VariableNode is never entering the Atomspace. Is this untrue?

Yours sincerely
Gaurav Gautam
helloPM.scm

Linas Vepstas

unread,
Jul 17, 2016, 3:52:03 PM7/17/16
to opencog
Hi,

The answer is simple:  Since you are looking for inheritance links of a particular structure, it will return everything it finds, having that particular structure, and the $denizen variable fits the structure, and so its reported.

If you do NOT want to see that, and see only the cncept nodes, then replace the bare (VariableNode "$animal") declaration with

this:

(TypedVariable
    (VariableNode "$animal")
  (VariableType "ConceptNode"))

This will return ONLY the concept nodes.  There is a wiki page on both VariableType and TypedVariable that gives more details

--linas

--
You received this message because you are subscribed to the Google Groups "opencog" group.
To unsubscribe from this group and stop receiving emails from it, send an email to opencog+u...@googlegroups.com.
To post to this group, send email to ope...@googlegroups.com.
Visit this group at https://groups.google.com/group/opencog.
To view this discussion on the web visit https://groups.google.com/d/msgid/opencog/620e1bc1-841e-4ae3-ad07-bc01294b06dd%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Gaurav Gautam

unread,
Jul 17, 2016, 10:58:16 PM7/17/16
to opencog
If the atomspace has a hypergraph of the form:

(InheritanceLink
(VariableNode "$denizen")
(ConceptNode "Pet")
)
then I understand what you are saying. However, my question is how this hypergraph got added to the atomspace in the first place. I did not add this explicitly and it only appears in the BindLink's output section. I was under the impression that the output part of BindLink is only written to the Atomspace after grounding the VariableNodes, and this is indeed what the output of cog-bind shows. Then how did this hypergraph get into the atomspace?

Gaurav Gautam

unread,
Jul 18, 2016, 12:00:05 AM7/18/16
to opencog
Hi Linas,
I think I understand what is happening now. The bindlink that I defined has this variablenode and since the BindLink is in the atomspace, so is this $denizen node.


Linas Vepstas

unread,
Jul 18, 2016, 11:25:39 AM7/18/16
to opencog
yes, exactly .. the bindlink itself is in the atomspace, and thus, so are all of its subgraphs . In general, whenever you create a link, all the atoms in the link get added to the atomspace (if they are not there already)

--linas

On Sun, Jul 17, 2016 at 11:00 PM, Gaurav Gautam <gauta...@gmail.com> wrote:
Hi Linas,
I think I understand what is happening now. The bindlink that I defined has this variablenode and since the BindLink is in the atomspace, so is this $denizen node.
--
You received this message because you are subscribed to the Google Groups "opencog" group.
To unsubscribe from this group and stop receiving emails from it, send an email to opencog+u...@googlegroups.com.
To post to this group, send email to ope...@googlegroups.com.
Visit this group at https://groups.google.com/group/opencog.
Reply all
Reply to author
Forward
0 new messages