Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Nested Variables #1456

Open
Yidnekachew opened this issue Dec 5, 2017 · 11 comments
Open

Nested Variables #1456

Yidnekachew opened this issue Dec 5, 2017 · 11 comments

Comments

@Yidnekachew
Copy link
Contributor

Is there anyway I can implement nested variables of the type (Variable "$n" (Variable "$a")) to match (Not (Concept "A")) ?

@linas
Copy link
Member

linas commented Dec 5, 2017

Yes. See https://wiki.opencog.org/w/SignatureLink I think they are partly implemented, and work in many cases, but that implementation is kind-of incomplete -- not everything uses them or understands them correctly

@linas
Copy link
Member

linas commented Dec 5, 2017

Hmm. Except that the SignatureLink is not quite what your original question is about. Its similar, but not the same. Can you provide a more detailed example of what you are trying to do? Maybe we have existing infrastructure to solve this and maybe we don't....

@linas
Copy link
Member

linas commented Dec 5, 2017

I also once started work on a FuzzyLink that does approximate matching, but it's hard to get right. It's hard to understand what is meant by "fuzzy", whether its the right kind of "fuzzy", and what problem it was that the user wanted.

@linas
Copy link
Member

linas commented Dec 5, 2017

Note also, your question hints that its about polymorphism, and we have TypeChoice for that.

@linas
Copy link
Member

linas commented Dec 5, 2017

This works:

(use-modules (opencog))
(use-modules (opencog exec))

(SequentialAnd (Concept "A"))

(define vl
  (Get
      (TypedVariable
        (Variable "$L")
        (Signature
          (SequentialAnd
             (TypeNode "ConceptNode"))))
    (And
        (Present (Variable "$L")))))
(cog-execute! vl)

@linas
Copy link
Member

linas commented Dec 5, 2017

This also works:

(SequentialAnd (Concept "A"))
(SequentialOr (Concept "B"))
(Not (Concept "C"))
(List (Concept "D"))

(define vl2
  (Get
      (TypedVariable
        (Variable "$L")
        (TypeChoice
           (Signature
             (SequentialAnd
                (TypeNode "ConceptNode")))
           (Signature
             (List
                (TypeNode "ConceptNode")))))
    (And
        (Present (Variable "$L")))))

(cog-execute! vl2)

@ngeiswei
Copy link
Member

ngeiswei commented Dec 6, 2017

@linas , @Yidnekachew wants to be able to rewrite expressions with some link like NotLink captured by some variable, like VariableNode "$N", meaning the rewrite term would be something like

(Variable "$N" (Variable "$X"))

But I don't think it's possible, is it?

Of course instead he can write rules specifically for each link type, Not, etc. But being able to wrap them in variables means that he can instead write generic rules according to algebraic properties.

@ngeiswei
Copy link
Member

ngeiswei commented Dec 6, 2017

Hmm, maybe meta-rules would be adequate here. Since algebraic properties are usually static, it makes even sense from an efficiency standpoint.

@linas
Copy link
Member

linas commented Dec 6, 2017

The naive (Variable "$N" (Variable "$X")) doesn't work, because we don't have this:

   (CreateLinkOfType
        (TypeNode "NotLink")
        (Concept "A"))

which, when evaluated, would return (Not (Concept "A")) If we did have CreateLinkOfType then you could write

   (CreateLinkOfType
        (Variable "$N")
        (Variable "$X"))

to deal with the result of searches. However, I think we can do the search ... hang on. next post.

@linas
Copy link
Member

linas commented Dec 6, 2017

The below is super-duper klunky, but it does work.

(use-modules (opencog))
(use-modules (opencog exec))

(SequentialAnd (Concept "A"))
(SequentialOr (Concept "B"))
(Not (Concept "C"))
(List (Concept "D"))
(Not (Predicate "E"))

(define vl4
  (Get
    (VariableList
      (TypedVariable
        (Variable "$L")
        (TypeChoice
            (TypeNode "NotLink")
            (TypeNode "SequentialOrLink")))
      (TypedVariable
        (Variable "$X")
        (TypeNode "ConceptNode")))
    (And
        (Present (Variable "$L"))
        (Present (Variable "$X"))
        (Or
           (Equal
              (NotLink (Variable "$X"))
              (Variable "$L"))
           (Equal
              (SequentialOrLink (Variable "$X"))
              (Variable "$L"))))))

(cog-execute! vl4)

@linas
Copy link
Member

linas commented Dec 6, 2017

Unrelated to this, but after reading lots of ugly R2L code, it became clear that we also need

(CreateNodeOfName
     (TypeNode "ConceptNode")
     (WordNode "foobar"))

which, when executed, would create (Concept "foobar")

There's also a need to grab values and convert them into atoms, and vice-versa, grab atoms and convert them into values. This opens up a box of all new tricks and techniques, and it should be opened somewhat carefully.

Along the way, I want to merge cog-execute! and cog-evaluate! into one, which is easy to say but confusing.

Also, its time we stopped using cog-bind Just use cog-execute! wherever cog-bind appears.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants