-
Notifications
You must be signed in to change notification settings - Fork 234
/
unify.scm
60 lines (51 loc) · 1.7 KB
/
unify.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
;
; unify.scm -- Term unification demo
;
; The query engine is able to perform conventional, classical
; term unification. The below is a very short, simple demo of
; this ability.
;
(use-modules (opencog) (opencog exec))
; Populate the AtomSpace with some initial data. This includes
; the data we want to match, and also some confounding data,
; that should not be found.
(Inheritance (Concept "A") (Concept "B"))
(Inheritance (Concept "A") (Concept "C"))
(Inheritance (Concept "B") (Concept "C"))
; Define a basic unifier. It uses the conventional GetLink to
; do the work.
(define unifier
(Get
(VariableList (Variable "$X") (Variable "$Y"))
(Identical
(Inheritance (Concept "A") (Variable "$Y"))
(Inheritance (Variable "$X") (Concept "B")))))
; Run it.
(cog-execute! unifier)
; The variable declaration is not explicitly required; the variables
; will be automatically extracted in the order that they are found.
; Caution: this reverses the variable order from the above! So $Y
; comes first, so the results will be reversed.
(define implicit-vars
(Get
(Identical
(Inheritance (Concept "A") (Variable "$Y"))
(Inheritance (Variable "$X") (Concept "B")))))
; Run it.
(cog-execute! implicit-vars)
; Lets try something more complex, a three-way unification.
; We'll declare the variables explicitly, to avoid confusion.
(define three-way
(Get
(VariableList (Variable "$X") (Variable "$Y") (Variable "$Z"))
(And
(Identical
(Inheritance (Concept "A") (Variable "$Y"))
(Inheritance (Variable "$X") (Concept "B")))
(Identical
(Inheritance (Concept "B") (Variable "$Z"))
(Inheritance (Variable "$Y") (Concept "C")))
)))
; Run it.
(cog-execute! three-way)
; The End. That's all, folks!