-
Notifications
You must be signed in to change notification settings - Fork 12
/
Copy pathfamilyTwo.CLP
111 lines (79 loc) · 3.21 KB
/
familyTwo.CLP
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
99
100
101
102
103
104
105
106
107
108
109
; ===============================
; deftemplates for the program:
; ===============================
(deftemplate parent-of
(slot parent)
(slot child))
(deftemplate children-of
(slot child)
(slot parent))
(deftemplate grandparents-of
(slot grandparent)
(slot grandchild))
(deftemplate grandchildren-of
(slot grandchild)
(slot grandparent))
;=============================================
; deffacts for the program:
;=============================================
(deffacts family-tree
(parent-of (parent Holt) (child Frances))
(parent-of (parent Viola) (child Frances))
(parent-of (parent Walter) (child Norm))
(parent-of (parent Cora) (child Norm))
(parent-of (parent Frances) (child Steve))
(parent-of (parent Frances) (child Norman))
(parent-of (parent Frances) (child Susan))
(parent-of (parent Norm) (child Steve))
(parent-of (parent Norm) (child Norman))
(parent-of (parent Norm) (child Susan))
(parent-of (parent Susan) (child Chris))
(parent-of (parent Susan) (child Melissa))
(parent-of (parent Charles) (child Chris))
(parent-of (parent Charles) (child Melissa))
(parent-of (parent Linda) (child Jonathan))
(parent-of (parent Linda) (child Kristin))
(parent-of (parent Linda) (child Stephen))
(parent-of (parent Steve) (child Jonathan))
(parent-of (parent Steve) (child Kristin))
(parent-of (parent Steve) (child Stephen))
(parent-of (parent Jonathan) (child Grayson))
(parent-of (parent Amy) (child Grayson))
(parent-of (parent Kristin) (child RJ))
(parent-of (parent Ryan) (child RJ))
(parent-of (parent Stephen) (child Austin))
(parent-of (parent Stephen) (child Parker))
(parent-of (parent Sandy) (child Austin))
(parent-of (parent Sandy) (child Parker)))
; ================================================
; rule to find parents:
; ================================================
(defrule find-parents
(find-parents-of ?child)
(parent-of (parent ?parent) (child ?child))
=>
(printout t ?parent " is the parent of " ?child "." crlf))
; ==================================================
; rule to find child of parent:
; ==================================================
(defrule find-children
(find-children-of ?parent)
(children-of (child ?child) (parent ?parent))
=>
(printout t ?child " is the child of " ?parent "." crlf))
; ====================================================
; rule to find grandparents:
; ====================================================
(defrule find-grandparents
(find-grandparents-of ?grandchild)
(grandparents-of (grandparent ?grandparent) (grandchild ?grandchild))
=>
(printout t ?grandparent " is the grandparent of " ?grandchild "." crlf))
; =====================================================
; rule to find grandchildren:
; =====================================================
(defrule find-grandchildren
(find-grandparents-of ?grandchild)
(grandchildren-of (grandchild ?grandchild) (grandparent ?grandparents))
=>
(printout t ?grandchild " is the grandchild of " ?grandparents "." crlf))