-
Notifications
You must be signed in to change notification settings - Fork 0
/
concept-selection-test.lisp
306 lines (229 loc) · 9.8 KB
/
concept-selection-test.lisp
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
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
;; -*- Mode: LISP; Syntax: Common-Lisp; Package: PROVER -*-
(in-package :PROVER)
;;;
;;;
;;;
(defmethod count-no-of-open-disjuncts ((node abox-node) (or-concept or-concept))
(loop as arg in (arguments or-concept)
when (and (not (on-tableau-p node arg))
(not (on-tableau-p node (get-negated-concept arg))))
sum 1))
;;;
;;; Code for syntactic branching
;;;
(defun get-or-score (node or-concept)
(declare (ignorable node or-concept))
1)
(defmethod select-or-concept ((abox abox) (language dl))
(let ((or nil)
(node nil)
(score nil))
(loop-over-abox-nodes (or-node abox nil)
(when (and (active-p or-node)
(has-unexpanded-or-concepts-p or-node nil))
(when *reflexive-checks-p*
(unless (deterministically-expanded-p or-node)
(error "SELECT-OR-CONCEPT: Strategy Error!")))
(loop-over-node-unexpanded-or-concepts (or-concept or-node nil)
(let ((new-score
(get-or-score or-node or-concept)))
(when (or (not or)
(> new-score score))
(setf score new-score)
(setf or or-concept node or-node)))))
(when or
(announce "~%+++ Selected OR CONCEPT ~A : ~A" node or)
(return-from select-or-concept
(values or node))))))
;;;
;;; Code for semantic branching
;;;
(defmethod select-open-disjunct ((abox abox) (language dl))
(let ((best-score nil)
(best nil)
(concept nil)
(best-node nil)
(score nil)
(ors-found-p nil))
(loop-over-abox-nodes (node abox)
(when (and (active-p node)
(has-unexpanded-or-concepts-p node nil))
(when *reflexive-checks-p*
(unless (deterministically-expanded-p node)
(error "SELECT-OPEN-DISJUNCT: Strategy Error!")))
(let ((score (get-node-score node)))
(when (or (not best-score)
(> score best-score))
(setf best-score score)
(setf best-node node)))))
(when best-node
(let ((open-disjuncts nil)
(ors nil)
(node best-node))
(loop-over-node-unexpanded-or-concepts (or-concept node nil)
(push or-concept ors)
(setf ors-found-p t)
(dolist (disjunct (arguments or-concept))
(when (and ;(not (on-tableau-p node disjunct)) ;; kann nicht auftreten!
(not (on-tableau-p node (get-negated-concept disjunct))))
;;(return-from select-open-disjunct
;; (values disjunct or-concept node))
(push (list disjunct or-concept) open-disjuncts))))
(dolist (disjunct-and-or open-disjuncts)
(let ((disjunct (first disjunct-and-or))
(or-concept2 (second disjunct-and-or)))
(dolist (disjunct (list disjunct (get-negated-concept disjunct)))
(let ((score 0))
#|
(dolist (or-concept ors)
(when (member disjunct (arguments or-concept))
(incf score))) |#
(setf score
(get-node-score node))
(unless (zerop score)
;;; ein solches Disjunkt bewirkt nichts,
;;; ist in keiner Disjunktion ein Argument!
(when (or (not best)
(> score best-score))
(setf best-node node
concept or-concept2
best disjunct
best-score score)))))))
(when (and ors-found-p (not best))
(error "Could not select disjunct!"))
(when best
(announce "~%+++ Selected OPEN DISJUNCT ~A OF ~A : ~A" best concept best-node)
(return-from select-open-disjunct
(values best concept best-node)))))))
;;;
;;;
;;;
;;;
;;;
;;;
;;;
;;;
;;;
;;;
(defun get-at-least-score (node at-least-concept)
(- 1000000000
(tools:maximum (get-choice-points at-least-concept :node node))))
(defmethod select-at-least-concept ((abox abox) (language dl))
(let ((node
(or
(get-oldest-node-satisfying1 abox ; wichtig! sonst falsch!
#'(lambda (x)
(and (active-p x)
(old-p x)
(has-unexpanded-at-least-concepts-p x nil))))
(get-youngest-node-satisfying1 abox ; Tiefensuche!
#'(lambda (x)
(and (active-p x)
(has-unexpanded-at-least-concepts-p x nil)))))))
(when node
(let ((at-least nil)
(score nil))
(loop-over-node-unexpanded-at-least-concepts (at-least-concept node nil)
(let ((new-score
(get-at-least-score node at-least-concept)))
(when (or (not at-least)
(> new-score score))
(setf score new-score)
(setf at-least at-least-concept))))
(when at-least
(announce "~%+++ Selected AT-LEAST CONCEPT ~A : ~A" node at-least)
(return-from select-at-least-concept
(values at-least node)))))))
;;;
;;;
;;;
(defmethod select-violated-at-most-concept ((abox abox) (language dl))
(loop-over-abox-nodes (node abox)
(let ((role-n-entries nil))
(when (and (active-p node)
(has-unexpanded-at-most-concepts-p node))
(when *reflexive-checks-p*
(unless (deterministically-expanded-p node)
(error "Strategy Error!")))
;;; kleinstes (at-most n R) pro Rolle R raussuchen
(loop-over-node-unexpanded-at-most-concepts (at-most-concept node)
(unless (is-top-concept-p (qualification at-most-concept))
(error "To be implemented!"))
(let ((role-n (assoc (role at-most-concept)
role-n-entries)))
(if role-n
(setf (second role-n)
(if (< (n at-most-concept)
(n (second role-n)))
at-most-concept
(second role-n)))
(push (list (role at-most-concept) at-most-concept) role-n-entries))))
;;;
(dolist (role-n role-n-entries)
(let* ((role (first role-n))
(at-most-concept (second role-n))
(n (n at-most-concept))
(m 0)
(edges nil))
(loop-over-role-successors (node role) (succ edge)
;;; (format t "~% ~A ~A ~A ~A" node role succ edge)
(if (eq node (from edge))
(unless (zerop (multiplicity edge))
(push edge edges)
(incf m (multiplicity edge)))
(unless (zerop (inverse-multiplicity edge))
(push edge edges)
(incf m (inverse-multiplicity edge)))))
(when (> m n)
(announce "~%+++ Selected violated AT-MOST CONCEPT ~A : ~A" node at-most-concept)
(announce "~%+++ Edges found: ~A" edges)
(return-from select-violated-at-most-concept
(values at-most-concept node edges m)))))))))
;;;
;;;
;;;
(defmethod select-attribute-exists-concepts ((abox abox) (language dl))
(let ((node
(or (get-oldest-node-satisfying1 abox ; wichig! sonst falsch!
;;; s. Gegenbeispiel in alchfnrplus-prover.lisp!
#'(lambda (x)
(and (active-p x)
(old-p x)
(has-unexpanded-attribute-exists-concepts-p x))))
(get-youngest-node-satisfying1 abox
#'(lambda (x)
(and (active-p x)
(has-unexpanded-attribute-exists-concepts-p x))))))
(ae-concept nil)
(ae-concepts nil)
(relevant-ae-concepts nil)
(score nil))
(when node
(loop-over-node-unexpanded-attribute-exists-concepts (concept node nil)
(let ((new-score
(get-some-score node ae-concept)))
(when (or (not ae-concept)
(> new-score score))
(setf score new-score)
(setf ae-concept concept))
(push concept ae-concepts)))
(push ae-concept relevant-ae-concepts)
(when ae-concept
(announce "~%+++ Selected ATTRIBUTE-EXISTS CONCEPT ~A : ~A" node ae-concept)
(let* ((found t))
(loop while found do
(setf found nil)
(let ((x
(find-if #'(lambda (x)
(some #'(lambda (y)
(has-common-parent-feature (role x) (role y)))
relevant-ae-concepts))
ae-concepts)))
(when x
(setf found t)
(setf ae-concepts (delete x ae-concepts))
(push x relevant-ae-concepts)))))
(setf relevant-ae-concepts
(delete-duplicates relevant-ae-concepts))
(announce "~%+++ Selected group of ATTRIBUTE-EXISTS CONCEPTS ~A : ~A" node relevant-ae-concepts)
(values ae-concept relevant-ae-concepts node)))))