-
Notifications
You must be signed in to change notification settings - Fork 12
/
family-1.CLP
107 lines (77 loc) · 3.17 KB
/
family-1.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
; ==========================================
; Author: James Anthony Ortiz
; File: family.CLP
; Date: 09/25/2019
; ==========================================
; ===============================
; deftemplate for the program:
; ===============================
(deftemplate parent-of
(slot parent)
(slot child))
;=============================================
; 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 parent of child: (functional)
; ===========================================
(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 children of parent: (functional)
; ==============================================
(defrule find-children
(find-children-of ?parent)
(parent-of (parent ?parent) (child ?child))
=>
(printout t ?child " is the child of " ?parent crlf))
; =========================================
; rule to find grandchildren: (functional)
; =========================================
(defrule find-grandchildren
(find-grandchildren-of ?grandparent)
(parent-of (parent ?grandparent) (child ?child))
(parent-of (parent ?child) (child ?gc))
=>
(printout t ?gc " is the grandchild of " ?grandparent crlf))
; ========================================
; rule to find grandparents: (functional)
; ========================================
(defrule find-grandparents
(find-grandparents-of ?grandchild)
(parent-of (parent ?child) (child ?grandchild))
(parent-of (parent ?grandparents) (child ?child))
=>
(printout t ?grandparents " is the grandparent of " ?grandchild crlf))