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

Using GlobNode in Backward Chainer #31

Closed
stellarspot opened this issue Jan 23, 2019 · 2 comments
Closed

Using GlobNode in Backward Chainer #31

stellarspot opened this issue Jan 23, 2019 · 2 comments

Comments

@stellarspot
Copy link
Contributor

My aim is to write a rule for URE that deals with variable number of arguments in a link.

As an example I try to take the latest atom in a Product link and put it on top.
This works fine if I use GlobNode just in BindLink (sample [1]).
When I try to use the same BindLink with URE the result is nothing (sample[2]).
If I change GlobNode to VariableNode URE works fine (sample [3]).

[1] Using Glob node with BindLink:

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

;;;;;;;;;;;;;;;;;;;;;
;;; Knowledge base ;;
;;;;;;;;;;;;;;;;;;;;;

(Product (stv 1 1) ; a non-zero truth value is needed!
 (ConceptNode "A")
 (ConceptNode "B"))

;;;;;;;;;;;;;;;;;
;; Rule  base  ;;
;;;;;;;;;;;;;;;;;

(define (on-top h)
 (display "on-top input:\n")
 (display h)
 (cog-set-tv! h (cog-new-stv 0.75 0.42))
 h)

(define on-top-rule
 (BindLink
  (VariableList
   (GlobNode "$X1")
   (TypedVariable (Variable "$X2") (Type "ConceptNode"))
  )
  (Product
   (GlobNode "$X1")
   (Variable "$X2")
  )
  (ExecutionOutputLink
   (GroundedSchemaNode "scm: on-top")
   (ListLink
    (Product
     (Variable "$X2")
     (GlobNode "$X1")
    )))))

(display (cog-execute! on-top-rule))

Output:

on-top input:
(ProductLink
   (ConceptNode "B")
   (ConceptNode "A")
)
(SetLink
   (ProductLink (stv 0.75 0.42)
      (ConceptNode "B")
      (ConceptNode "A")
   )
)

[2] Using GlobNode with URE:

(use-modules (opencog) (opencog query) (opencog exec) (opencog rule-engine))

;;;;;;;;;;;;;;;;;;;;;
;;; Knowledge base ;;
;;;;;;;;;;;;;;;;;;;;;

(Product (stv 1 1) ; a non-zero truth value is needed!
 (ConceptNode "A")
 (ConceptNode "B"))

;;;;;;;;;;;;;;;;;
;; Rule  base  ;;
;;;;;;;;;;;;;;;;;

(define (on-top-formula h)
 (display "on-top input:\n")
 (display h)
 (cog-set-tv! h (cog-new-stv 0.75 0.42))
 h)

(define on-top-rule
 (BindLink
  (VariableList
   (GlobNode "$X1")
   (TypedVariable (Variable "$X2") (Type "ConceptNode"))
  )
  (Product
   (GlobNode "$X1")
   (Variable "$X2")
  )
  (ExecutionOutputLink
   (GroundedSchemaNode "scm: on-top-formula")
   (List
    (Product
     (Variable "$X2")
     (GlobNode "$X1")
    )))))


(define on-top-rule-name
 (DefinedSchema "on-top-rule"))

(Define on-top-rule-name
 on-top-rule)

;;;;;;;;;;
;; URE  ;;
;;;;;;;;;;

(define ci-rbs (Concept "ci-rbs"))

;; Add rules to ci-rbs
(ure-add-rules ci-rbs
 (list
  (cons on-top-rule-name (stv 1.0 1.0))))

;; Set URE parameters
(ure-set-maximum-iterations ci-rbs 20)

;; Attention allocation (set the TV strength to 0 to disable it, 1 to
;; enable it)
(EvaluationLink (stv 0 1)
 (PredicateNode "URE:attention-allocation")
 ci-rbs
)

;;;;;;;;;;;;;;;;;;;;;;
;; Backward Chainer ;;
;;;;;;;;;;;;;;;;;;;;;;

(display
 (cog-bc
  ci-rbs
  (Product (VariableNode "$X") (Concept "A"))
  #:vardecl (TypedVariable (VariableNode "$X") (TypeNode "ConceptNode")))
)

Output:

(SetLink
)

[3] Using VariableNode with URE:

(use-modules (opencog) (opencog query) (opencog exec) (opencog rule-engine))

;;;;;;;;;;;;;;;;;;;;;
;;; Knowledge base ;;
;;;;;;;;;;;;;;;;;;;;;

(Product (stv 1 1) ; a non-zero truth value is needed!
 (ConceptNode "A")
 (ConceptNode "B"))

;;;;;;;;;;;;;;;;;
;; Rule  base  ;;
;;;;;;;;;;;;;;;;;

(define (on-top-formula h)
 (display "on-top input:\n")
 (display h)
 (cog-set-tv! h (cog-new-stv 0.75 0.42))
 h)

(define on-top-rule
 (BindLink
  (VariableList
   (TypedVariable (Variable "$X1") (Type "ConceptNode"))
   (TypedVariable (Variable "$X2") (Type "ConceptNode"))
  )
  (Product
   (Variable "$X1")
   (Variable "$X2")
  )
  (ExecutionOutputLink
   (GroundedSchemaNode "scm: on-top-formula")
   (List
    (Product
     (Variable "$X2")
     (Variable "$X1")
    )))))


(define on-top-rule-name
 (DefinedSchema "on-top-rule"))

(Define on-top-rule-name
 on-top-rule)

;;;;;;;;;;
;; URE  ;;
;;;;;;;;;;

(define ci-rbs (Concept "ci-rbs"))

;; Add rules to ci-rbs
(ure-add-rules ci-rbs
 (list
  (cons on-top-rule-name (stv 1.0 1.0))))

;; Set URE parameters
(ure-set-maximum-iterations ci-rbs 20)

;; Attention allocation (set the TV strength to 0 to disable it, 1 to
;; enable it)
(EvaluationLink (stv 0 1)
 (PredicateNode "URE:attention-allocation")
 ci-rbs
)

;;;;;;;;;;;;;;;;;;;;;;
;; Backward Chainer ;;
;;;;;;;;;;;;;;;;;;;;;;

(display
 (cog-bc
  ci-rbs
  (Product (VariableNode "$X") (Concept "A"))
  #:vardecl (TypedVariable (VariableNode "$X") (TypeNode "ConceptNode")))
)

Output:

on-top input:
(ProductLink
   (ConceptNode "B")
   (ConceptNode "A")
)
(SetLink
   (ProductLink (stv 0.75 0.42)
      (ConceptNode "B")
      (ConceptNode "A")
   )
)
@ngeiswei
Copy link
Member

Thanks for your report @stellarspot . Your problem results from the lack of support of GlobNode by the unifier. I've created an issue about that https://github.com/opencog/atomspace/issues/2010

Adding this support is not the most pressing thing on my schedule, so it seems you have 2 options

  1. Use a rule generator to generate the same rule for different arities, see for example https://github.com/opencog/opencog/blob/master/opencog/pln/rules/propositional/fuzzy-conjunction-introduction.scm
  2. Wait that I or someone else, maybe you :-), implements it.

@linas linas transferred this issue from opencog/atomspace Jul 26, 2019
@ngeiswei
Copy link
Member

Glob support was added by Kasim, closing.

ngeiswei added a commit to ngeiswei/ure that referenced this issue Aug 16, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants