forked from dnr2/krr-question-answering
-
Notifications
You must be signed in to change notification settings - Fork 0
/
rules.meld
198 lines (175 loc) · 8.73 KB
/
rules.meld
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
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
(in-microtheory TaskGlobalMt)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;; Event Rules
;; Happens after transitivity.
(<== (happensAfter ?z ?x)
(happensAfter ?y ?x)
(happensAfter ?z ?y))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;; Person Rules
;; Rule defining where a person currently is.
;; This considers the case only one micro-theory talks has movesTo.
;;
;; NOTE:
;; the following is equivalent to:
;; (thereExistExactly 1 ?microtheory (ist-Information ?microtheory (MovesTo ?person ?anyPlace)))
;;
;; but apparently companions can't handle "thereExist" clauses.
;;
(<== (isCurrentlyIn ?person ?place)
(ist-Information ?microtheory (MovesTo ?person ?place))
(evaluate 1
;; Count the number of micro-theories that has the movesTo actions.
(CardinalityFn
(TheClosedRetrievalSetOf ?anyMicrotheory
(ist-Information ?anyMicrotheory (MovesTo ?person ?anyPlace))))))
;; Rule defining where a person currently is.
;; This considers the case more than one micro-theory has movesTo action.
;; More than one movesTo exists, gets the place associated with the
;; latest event micro-theory.
;;
(<== (isCurrentlyIn ?person ?place)
(genlMt ?microtheory1 TaskLocalMt)
(ist-Information ?microtheory1 (MovesTo ?person ?place))
(evaluate 0
;; Count the number of micro-theories that happens after ?microtheory1.
(CardinalityFn
(TheClosedRetrievalSetOf ?microtheory2
(and (genlMt ?microtheory2 TaskLocalMt)
(ist-Information ?microtheory2 (MovesTo ?person ?anotherPlace))
(happensAfter ?microtheory2 ?microtheory1) )))))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;; Person and Object Rules
;; First case, person picked up the object and and didn't drop or gave it.
(<== (isHoldingObject ?person ?object)
(ist-Information ?microtheory1 (pickedUpObject ?person ?object))
(evaluate 0
;; Count the number of micro-theories that happens after ?microtheory1 that the person dropped the object.
(CardinalityFn
(TheClosedRetrievalSetOf ?microtheory2
(and (genlMt ?microtheory2 TaskLocalMt)
(ist-Information ?microtheory2 (droppedObject ?person ?object))
(happensAfter ?microtheory2 ?microtheory1)))))
(evaluate 0
;; Count the number of micro-theories that happens after ?microtheory1 that the person gave the object
;; to another person.
(CardinalityFn
(TheClosedRetrievalSetOf ?microtheory2
(and (genlMt ?microtheory2 TaskLocalMt)
(ist-Information ?microtheory2 (giveTo ?person ?anotherPerson ?object))
(happensAfter ?microtheory2 ?microtheory1))))))
;; Second case, person was given the object and and didn't drop or gave it.
(<== (isHoldingObject ?person ?object)
(ist-Information ?microtheory1 (giveTo ?anyPerson ?person ?object))
(evaluate 0
;; Count the number of micro-theories that happens after ?microtheory1 that the person dropped the object.
(CardinalityFn
(TheClosedRetrievalSetOf ?microtheory2
(and (genlMt ?microtheory2 TaskLocalMt)
(ist-Information ?microtheory2 (droppedObject ?person ?object))
(happensAfter ?microtheory2 ?microtheory1)))))
(evaluate 0
;; Count the number of micro-theories that happens after ?microtheory1 that the person gave the object
;; to another person.
(CardinalityFn
(TheClosedRetrievalSetOf ?microtheory2
(and (genlMt ?microtheory2 TaskLocalMt)
(ist-Information ?microtheory2 (giveTo ?person ?anotherPerson ?object))
(happensAfter ?microtheory2 ?microtheory1))))))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;; Object Rules
;; First case, someone is currently holding the object
(<== (isObjectCurrentlyIn ?object ?place)
(isHoldingObject ?person ?object)
(isCurrentlyIn ?person ?place))
;; Second case, nobody is holding the object, find the place someone dropped it for the last time.
(<== (isObjectCurrentlyIn ?object ?place)
(ist-Information ?microtheory1 (droppedObject ?person ?object))
(ist-Information ?microtheory2 (MovesTo ?person ?place))
(happensAfter ?microtheory1 ?microtheory2)
(evaluate 0
;; Count the number of people currently holding object.
(CardinalityFn
(TheClosedRetrievalSetOf ?anyPerson
(isHoldingObject ?anyPerson ?object))))
(evaluate 0
;; Count the number of micro-theories that happens after ?microtheory1 where
;; the same person dropped the object.
(CardinalityFn
(TheClosedRetrievalSetOf ?microtheory3
(and (genlMt ?microtheory3 TaskLocalMt)
(ist-Information ?microtheory3 (droppedObject ?person ?object))
(happensAfter ?microtheory3 ?microtheory1)))))
(evaluate 0
;; Count the number of micro-theories that happens after ?microtheory1 where
;; another person dropped the object.
(CardinalityFn
(TheClosedRetrievalSetOf ?microtheory3
(and (genlMt ?microtheory3 TaskLocalMt)
(ist-Information ?microtheory3 (droppedObject ?anotherPerson ?object))
(happensAfter ?microtheory3 ?microtheory1)))))
(evaluate 0
;; Count the number of micro-theories that happens after ?microtheory2 and before
;; ?microtheory1 and a person moved to another place.
(CardinalityFn
(TheClosedRetrievalSetOf ?microtheory3
(and (genlMt ?microtheory3 TaskLocalMt)
(ist-Information ?microtheory3 (MovesTo ?person ?anotherPlace))
(happensAfter ?microtheory3 ?microtheory2)
(happensAfter ?microtheory1 ?microtheory3)))))
)
;; For the query : Where was the apple before the bathroom?
(<== (wasInPlaceBefore ?object ?place ?placeBefore)
(ist-Information ?microtheory1 (wasObjectIn ?object ?place))
(ist-Information ?microtheory2 (wasObjectIn ?object ?placeBefore))
(happensAfter ?microtheory1 ?microtheory2)
(evaluate 0
;; Count the number of micro-theories that happens after ?microtheory1 where
;; the same object in the same place.
(CardinalityFn
(TheClosedRetrievalSetOf ?microtheory3
(and (genlMt ?microtheory3 TaskLocalMt)
(ist-Information ?microtheory3 (wasObjectIn ?object ?place))
(happensAfter ?microtheory3 ?microtheory1)))))
(evaluate 0
;; Count the number of micro-theories that happens between ?microtheory2 and ?microtheory1 where
;; the same object in someplace else.
(CardinalityFn
(TheClosedRetrievalSetOf ?microtheory3
(and (genlMt ?microtheory3 TaskLocalMt)
(ist-Information ?microtheory3 (wasObjectIn ?object ?anotherplace))
(happensAfter ?microtheory3 ?microtheory2)
(happensAfter ?microtheory1 ?microtheory3)))))
)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;; Last give Rules : find the last happened microtheory with giveTo
;;; For the query like "Who gave the apple?" or "Who received the apple?"
(<== (lastGiveTo ?give-person ?receive-person ?give-object)
(genlMt ?microtheory1 TaskLocalMt)
(ist-Information ?microtheory1 (giveTo ?give-person ?receive-person ?give-object))
(evaluate 0
;; Count the number of micro-theories that happens after ?microtheory1.
(CardinalityFn
(TheClosedRetrievalSetOf ?microtheory2
(and (genlMt ?microtheory2 TaskLocalMt)
(ist-Information ?microtheory2 (giveTo ?give-person2 ?receive-person2 ?give-object))
(happensAfter ?microtheory2 ?microtheory1) ))))
)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;; Directions Rules
;; symmetrical relations
(<== (northOf ?x ?y)
(southOf ?y ?x))
(<== (southOf ?x ?y)
(northOf ?y ?x))
(<== (westOf ?x ?y)
(eastOf ?y ?x))
(<== (eastOf ?x ?y)
(westOf ?y ?x))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;; Logic Rules
;; Implement Prolog's negation by failure.
(<== (not ?fact)
(uninferredSentence ?fact))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;; End of Code