-
Notifications
You must be signed in to change notification settings - Fork 234
/
satisfaction.scm
98 lines (84 loc) · 2.24 KB
/
satisfaction.scm
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
;
; satisfaction.scm -- Determining satisfiability of a query.
;
; SatisfactionLink usage example.
;
; Using the SatisfactionLink is fairly straightforward; what this
; example shows is how to obtain the variable grounding that caused
; the satisfaction to be fulfilled.
;
(use-modules (opencog) (opencog exec))
; Define a very simple satisfaction link.
(define satlink
(Satisfaction
(Evaluation
(Predicate "foobar")
(List
(Concept "funny")
(Variable "$x")))))
; Create something that will satisfy the above.
(Evaluation
(Predicate "foobar")
(List
(Concept "funny")
(Concept "thing")))
; Actually run it - this should return TrueTV i.e. `(stv 1 1)`
; because the SatisfactionLink is satisfiable.
(cog-execute! satlink)
; Fine, but can we know what variable grounding resulted in the
; satisfaction? Sure! In several different ways.
;
; Define an anchor point, where the result will be placed.
(define gnd-sat
(Satisfaction
(Anchor "please put groundings here")
(Evaluation
(Predicate "foobar")
(List
(Concept "funny")
(Variable "$x")))))
(cog-execute! gnd-sat)
; Above returns the same TruthValue as before. The grounding for
; Variable $x is attached to the Anchor with a MemberLink:
(define anchr (Anchor "please put groundings here"))
(cog-incoming-by-type anchr 'Member)
; An alternate way of writing the above, this time declaring the
; the variable explicitly.
(define gnd-decl-sat
(Satisfaction
(VariableList
(Variable "$x")
(Anchor "please put groundings here"))
(Evaluation
(Predicate "foobar")
(List
(Concept "funny")
(Variable "$x")))))
(cog-execute! gnd-decl-sat)
(cog-incoming-by-type anchr 'Member)
; If there is more than one variable, then the order in which
; they appear is important, as it is used to report the grounding.
(define gnd2-sat
(Satisfaction
(VariableList
(Variable "$p")
(Variable "$x")
(Anchor "please put groundings here"))
(Evaluation
(Variable "$p")
(List
(Concept "funny")
(Variable "$x")))))
(cog-execute! gnd2-sat)
(cog-incoming-by-type anchr 'Member)
(define gnd2-get
(Get
(VariableList
(Variable "$p")
(Variable "$x"))
(Evaluation
(Variable "$p")
(List
(Concept "funny")
(Variable "$x")))))
(cog-execute! gnd2-get)