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

Internal patterns passed on evalution of a DefinedSchemaNode by a GroundedPredicateNode #704

Closed
amebel opened this issue Mar 16, 2016 · 9 comments

Comments

@amebel
Copy link
Contributor

amebel commented Mar 16, 2016

Setup scheme file content

(clear)
(use-modules (opencog))
(use-modules (opencog exec))
(use-modules (opencog query))

(InheritanceLink
   (ConceptNode "OpenPsi: Energy" (stv 0.66960984 0.99999982))
   (ConceptNode "OpenPsi: Demand")
)

(InheritanceLink
   (DefinedSchemaNode "OpenPsi: Energy-action-rule-Default")
   (ConceptNode "opencog: action")
)

(MemberLink (stv 1 0.99999982)
   (DefinedSchemaNode "OpenPsi: Energy-action-rule-Default")
   (ConceptNode "OpenPsi: Energy" (stv 0.66960984 0.99999982))
)

(EvaluationLink
   (PredicateNode "OpenPsi: default_value")
   (ListLink
      (ConceptNode "OpenPsi: Energy" (stv 0.66960984 0.99999982))
      (NumberNode "0.710000")
   )
)

(DefineLink
   (DefinedPredicateNode "OpenPsi: demand-pattern")
   (PresentLink
      (InheritanceLink
         (VariableNode "Demand" (stv 0.96491325 0))
         (ConceptNode "OpenPsi: Demand")
      )
      (EvaluationLink
         (PredicateNode "OpenPsi: default_value")
         (ListLink
            (VariableNode "Demand" (stv 0.96491325 0))
            (VariableNode "default_value")
         )
      )
   )
)

(define z-dsn (DefinedSchemaNode "OpenPsi: Energy-action-rule-Default"))
(DefineLink
   z-dsn
   (BindLink
      (VariableList
         (TypedVariableLink
            (VariableNode "Demand" (stv 0.96491325 0))
            (TypeNode "ConceptNode")
         )
      )
      (AndLink
         (DefinedPredicateNode "OpenPsi: demand-pattern")
         (EqualLink
            (VariableNode "Demand" (stv 0.96491325 0))
            (ConceptNode "OpenPsi: Energy" (stv 0.66960984 0.99999982))
         )
      )
      (ExecutionOutputLink
         (GroundedSchemaNode "scm: foo")
         (ListLink
            (VariableNode "Demand" (stv 0.96491325 0))
         )
      )
   )
)

(define (foo node) node)

(define z-get
    (GetLink
       (TypedVariableLink
          (VariableNode "x")
          (TypeNode "DefinedSchemaNode")
       )
       (AndLink
          (MemberLink
             (VariableNode "x")
             (ConceptNode "OpenPsi: Energy" (stv 0.66960984 0.99999982))
          )
          (InheritanceLink
             (VariableNode "x")
             (ConceptNode "opencog: action")
          )
          (EvaluationLink
             (GroundedPredicateNode "scm: what?")
             (ListLink
                (VariableNode "x")
             )
          )
       )
    )
)

(define (what? dsn)
    (begin
        (display "\n------------------------------------------\n")
        (display "\nDefinedSchemaNode Expanded and passed to this function \n")
        (display dsn)
        (display "\n------------------------------------------\n")
        (display "\nExpected DefinedSchemaNode got\n")
        (display (cog-chase-link 'DefineLink 'DefinedSchemaNode dsn))
        (display "\n------------------------------------------\n")
        (display "\n#############################################\n")
        (stv 1 1)
    )
)

(define (test)
    (cog-execute! z-get)
)

(define (check)
    (cog-chase-link 'DefineLink 'BindLink z-dsn)
)

Trying to get the DefineSchemaNode

scheme@(guile-user)> (load "the-scheme-setup-file-from-above.scm")
....
scheme@(guile-user)> (test)

------------------------------------------

DefinedSchemaNode Expanded and passed to this function
(BindLink
   (VariableList
      (TypedVariableLink
         (VariableNode "Demand" (stv 0.96491325 0))
         (TypeNode "ConceptNode")
      )
   )
   (AndLink
      (DefinedPredicateNode "OpenPsi: demand-pattern")
      (EqualLink
         (VariableNode "Demand" (stv 0.96491325 0))
         (ConceptNode "OpenPsi: Energy" (stv 0.66960984 0.99999982))
      )
   )
   (VariableNode "Demand" (stv 0.96491325 0))
)

------------------------------------------

Expected DefinedSchemaNode got
()
------------------------------------------

#############################################
(SetLink
   (DefinedSchemaNode "OpenPsi: Energy-action-rule-Default")
)

The issue

If the BindLink was actually an expansion of the DefinedSchemaNode, then the Expected DefinedSchemaNode got lines of the output wouldn't have been an empty list. It seems, a BindLink that is created intermediately within the query-engine is passed instead.

Expected BindLink to be passed to the what? function is

scheme@(guile-user)> (check)
((BindLink
   (VariableList
      (TypedVariableLink
         (VariableNode "Demand" (stv 0.96491325 0))
         (TypeNode "ConceptNode")
      )
   )
   (AndLink
      (DefinedPredicateNode "OpenPsi: demand-pattern")
      (EqualLink
         (VariableNode "Demand" (stv 0.96491325 0))
         (ConceptNode "OpenPsi: Energy" (stv 0.66960984 0.99999982))
      )
   )
   (ExecutionOutputLink
      (GroundedSchemaNode "scm: foo")
      (ListLink
         (VariableNode "Demand" (stv 0.96491325 0))
         (NumberNode "5.000000")
      )
   )
)
)
@linas
Copy link
Member

linas commented Mar 16, 2016

This is difficult to understand, but I think you were expecting what? to get z-dsn as the argument, and, instead, you got the result of (cog-execute! z-dsn) and are surprised by that.

The explanation for this is easy: when you (cog-execute! z-get), you have an AndLink of three items, one of which is

     (EvaluationLink
             (GroundedPredicateNode "scm: what?")
             (ListLink
                (VariableNode "x")))

In order to see if the AndLink is true, the pattern matcher must check to see if above is true. This is done in two steps: first, (VariableNode "x") is replaced by its grounding (which is z-dsn), then the EvaluationLink as a whole is evaluated. A side effect of that evaluation is that (cog-execute! z-dsn) is performed, and the result of that is passed to what?.

From what I can tell, what you need to do is to have this instead:

     (EvaluationLink
             (GroundedPredicateNode "scm: what?")
             (ListLink
                (DontExecLink (VariableNode "x"))))

and that will give you what you want. However, the DontExecLink doesn't exist yet.

Is this what you want to do? If so, then I guess that a DontExecLink could be created... (we need a better name for it)

@linas
Copy link
Member

linas commented Mar 17, 2016

In scheme, DontExecLink is called syntax or quasisyntax .. I don't exactly like the name SyntaxLink but QuasiSyntaxLink makes it vaguely acceptable...

@amebel
Copy link
Contributor Author

amebel commented Mar 17, 2016

Yes, something like quasisyntax is what I wanted.

Another thing I don't get why (cog-execute! z-dsn) would return

(BindLink
   (VariableList
      (TypedVariableLink
         (VariableNode "Demand" (stv 0.96491325 0))
         (TypeNode "ConceptNode")
      )
   )
   (AndLink
      (DefinedPredicateNode "OpenPsi: demand-pattern")
      (EqualLink
         (VariableNode "Demand" (stv 0.96491325 0))
         (ConceptNode "OpenPsi: Energy" (stv 0.66960984 0.99999982))
      )
   )
   (VariableNode "Demand" (stv 0.96491325 0))
)

instead of

(SetLink 
     (ConceptNode "OpenPsi: Energy")
)

@linas
Copy link
Member

linas commented Mar 17, 2016

ah yes, you are right ... the result of (cog-execute! z-dsn) is incoherent/wrong. Its related to bug #686 -- for historical reasons, you cannot "run" Bindlinks with cog-execute, you can only run them with cog-bind. Nonetheless, cog-execute! is being eager and blind, and tries to do something, anything, and it ends up finding the embedded ExecutionOutputLink, and it runs only that. This is a separate, distinct bug.

@linas
Copy link
Member

linas commented Mar 17, 2016

I opened issue #705 do describe this bug. Do you want me to fix this muddled-puddle of issues? I'd probably fix #705 first, by making it partly do what #686 is saying. After that, would need to implement QuasiSyntaxLink. is there a better name for this?

@amebel
Copy link
Contributor Author

amebel commented Mar 17, 2016

Yes please, on fixing the muddled-puddle 😄

How about PassLink similar to python's pass https://docs.python.org/2.7/reference/simple_stmts.html#pass

@linas
Copy link
Member

linas commented Mar 18, 2016

working on it now. Its causing a snowball of changes to occur.

@linas linas self-assigned this Mar 18, 2016
linas added a commit to linas/atomspace that referenced this issue Mar 20, 2016
@linas linas mentioned this issue Mar 20, 2016
@linas
Copy link
Member

linas commented Mar 20, 2016

fixed in pull request #714

linas added a commit that referenced this issue Mar 20, 2016
@amebel
Copy link
Contributor Author

amebel commented Mar 21, 2016

Thanks

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

2 participants