-
Notifications
You must be signed in to change notification settings - Fork 234
/
choice.scm
58 lines (50 loc) · 1.07 KB
/
choice.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
;
; choice.scm -- Using the ChoiceLink to explore alternatives.
;
; A very simple example of using the ChoiceLink.
;
; Populate the AtomSpace with some data
(Evaluation
(Predicate "has-color")
(List
(Concept "apple")
(Concept "green")))
(Evaluation
(Predicate "has-color")
(List
(Concept "banana")
(Concept "yellow")))
(Evaluation
(Predicate "has-color")
(List
(Concept "strawberry")
(Concept "red")))
; Look for fruit that is red or green.
; This won't work; although it looks nice, the ChoiceLink cannot
; be used in this way. Sorry.
(define find-fruit
(Get
(Evaluation
(Predicate "has-color")
(List
(Variable "$fruit")
(Choice
(Concept "red")
(Concept "green"))))))
; This will work; the ChoiceLink appears at the top.
(define find-fruit
(Get
(Choice
(Evaluation
(Predicate "has-color")
(List
(Variable "$fruit")
(Concept "red")))
(Evaluation
(Predicate "has-color")
(List
(Variable "$fruit")
(Concept "green"))))))
; Run the query:
(cog-execute! find-fruit)
; The answer will be what you expect.