-
Notifications
You must be signed in to change notification settings - Fork 0
/
clips.clp
158 lines (133 loc) · 3.04 KB
/
clips.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
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
;;Run commands in terminal
;; ~: clips (if u havent got alias in the system run absolute path: /dirs/abs_path/your_dir/clips)
;; CLIPS> ( chdir "/dirs/abs_path/your_dir/Expert_Systems_Labs" ) - its only for setting work directory with project file
;; CLIPS> (load ./clips.clp)
;; CLIPS> (reset)
;; CLIPS> (run)
;; Then u will see programm inputs
;; initialiaze relations and facts
(deffacts initialFacts
"initialize relations in program"
(parent dima katya)
(parent dima kirill)
(parent dima maria)
(parent ira maria)
(parent maria egor)
(parent maria anya)
(parent kirill vitya)
(female katya)
(male kirill)
(female ira)
(female maria)
(female anya)
(male egor)
(male vitya)
(male dima)
)
;;===============inputs===========================================
(defrule getNames
(declare (salience 100))
=>
(printout t "Enter first name: ")
(bind ?name1 (read))
(printout t "Enter second name: ")
(bind ?name2 (read))
(printout t "--------Results--------" crlf)
(assert (abuelo ?name1))
)
;;===============relatonship rules=====================================================
(defrule brotherRelation
(male ?x)
(parent ?z ?x)
(parent ?z ?y)
(test (not (eq ?y ?x)))
=>
(assert (brother ?x ?y))
)
(defrule sisterRelation
(female ?x)
(parent ?z ?x)
(parent ?z ?y)
(test (not (eq ?y ?x)))
=>
(assert (sister ?x ?y))
)
(defrule brother0rSisterRelation
(parent ?z ?x)
(parent ?z ?y)
(test (not (eq ?y ?x)))
=>
(assert (brother-sister ?x ?y))
)
(defrule cousingRelation
(parent ?w ?x)
(parent ?z ?y)
(brother ?w ?z)
=>
(assert (cousing ?x ?y))
)
(defrule grandFatherRelation
(parent ?x ?z)
(parent ?z ?y)
(male ?x)
=>
(assert (grandFather ?x ?y))
)
(defrule grandMotherRelation
(parent ?x ?z)
(parent ?z ?y)
(female ?x)
=>
(assert (grandMother ?x ?y))
)
(defrule grandChildRelation
(grandFather ?z ?x)
(male ?x)
=>
(assert (grandChild ?x ?z))
)
(defrule grandDaugtherRelation
(grandFather ?z ?x)
(female ?x)
=>
(assert (grandDaugther ?x ?z))
)
(defrule uncleRelation
(parent ?z ?x)
(brother ?y ?z)
=>
(assert (uncle ?y ?x))
)
(defrule auntRelation
(parent ?z ?x)
(sister ?y ?z)
=>
(assert (aunt ?y ?x))
)
(defrule grandFatherOrGrandMotherRelation
(parent ?x ?z)
(parent ?z ?y)
=>
(assert (grandFather-grandMother ?x ?y))
)
;;===============extra rules===============================================
(defrule isGrandFather
(grandFather ?a ?b)
=>
(printout t ?a " is GrandFather of: " ?b crlf)
)
(defrule isNotGrandFather
(not (grandFather ?resp1 ?resp2))
=>
(printout t "Not is grand father" crlf)
)
(defrule isGrandMother
(grandMother ?a ?b)
=>
(printout t ?a " is GrandMother of: " ?b crlf)
)
(defrule isNotGrandMother
(not (grandMother ?resp1 ?resp2))
=>
(printout t "Not is grand mother" crlf)
)