1 | ;;+----------------------------------------------------------------------------- |
---|
2 | ;;+ Isidorus |
---|
3 | ;;+ (c) 2008-2009 Marc Kuester, Christoph Ludwig, Lukas Giessmann |
---|
4 | ;;+ |
---|
5 | ;;+ Isidorus is freely distributable under the LGPL license. |
---|
6 | ;;+ You can find a detailed description in trunk/docs/LGPL-LICENSE.txt. |
---|
7 | ;;+----------------------------------------------------------------------------- |
---|
8 | (in-package :rdf-importer) |
---|
9 | |
---|
10 | (defun map-to-tm (tm-id start-revision |
---|
11 | &key (document-id *document-id*)) |
---|
12 | (let ((topics-to-map (get-isi-topics tm-id start-revision |
---|
13 | :document-id document-id)) |
---|
14 | (associations-to-map (get-isi-topics |
---|
15 | tm-id start-revision |
---|
16 | :document-id document-id |
---|
17 | :type-psi *tm2rdf-association-type-uri*))) |
---|
18 | (let ((mapped-topics |
---|
19 | (map 'list #'(lambda(top) |
---|
20 | (map-isi-topic top start-revision)) |
---|
21 | topics-to-map)) |
---|
22 | (mapped-associations |
---|
23 | (map 'list #'(lambda(top) |
---|
24 | (map-isi-association top start-revision tm-id |
---|
25 | :document-id document-id)) |
---|
26 | associations-to-map))) |
---|
27 | (let ((constructs |
---|
28 | (append mapped-topics mapped-associations))) |
---|
29 | (clear-store start-revision) |
---|
30 | (map 'list #'d::check-for-duplicate-identifiers constructs) |
---|
31 | constructs)))) |
---|
32 | |
---|
33 | |
---|
34 | (defun clear-store(start-revision) |
---|
35 | "Deletes all topics that are neede for RDF2TM mapping and are not |
---|
36 | referenced in an associaiton, as type or scope." |
---|
37 | (let ((psi-uris |
---|
38 | (list *tm2rdf-topic-type-uri* *tm2rdf-name-type-uri* |
---|
39 | *tm2rdf-variant-type-uri* *tm2rdf-occurrence-type-uri* |
---|
40 | *tm2rdf-association-type-uri* *tm2rdf-role-type-uri* |
---|
41 | *tm2rdf-itemIdentity-property* *tm2rdf-subjectLocator-property* |
---|
42 | *tm2rdf-subjectIdentifier-property* *tm2rdf-role-property* |
---|
43 | *tm2rdf-subjectIdentifier-property* *tm2rdf-player-property* |
---|
44 | *tm2rdf-nametype-property* *tm2rdf-value-property* |
---|
45 | *tm2rdf-occurrence-property* *tm2rdf-roletype-property* |
---|
46 | *tm2rdf-variant-property* *tm2rdf-occurrencetype-property* |
---|
47 | *tm2rdf-name-property* *tm2rdf-associationtype-property* |
---|
48 | *tm2rdf-scope-property* *tm2rdf-reifier-property*))) |
---|
49 | (dolist (uri psi-uris) |
---|
50 | (delete-topic-if-not-referenced uri start-revision)))) |
---|
51 | |
---|
52 | |
---|
53 | (defun delete-topic-if-not-referenced(type-psi start-revision) |
---|
54 | "Deletes a topic when it is not referenced." |
---|
55 | (declare (string type-psi)) |
---|
56 | (declare (integer start-revision)) |
---|
57 | (let ((type-topic (get-item-by-psi type-psi |
---|
58 | :revision start-revision))) |
---|
59 | (when type-topic |
---|
60 | (when (and (not (player-in-roles type-topic :revision start-revision)) |
---|
61 | (not (used-as-type type-topic :revision start-revision)) |
---|
62 | (not (used-as-theme type-topic :revision start-revision))) |
---|
63 | (d::delete-construct type-topic))))) |
---|
64 | |
---|
65 | |
---|
66 | (defun delete-instance-of-association(instance-topic type-topic start-revision) |
---|
67 | "Deletes a type-instance associaiton that corresponds with the passed |
---|
68 | parameters." |
---|
69 | (when (and instance-topic type-topic) |
---|
70 | (let ((instance (get-item-by-psi *instance-psi* :revision start-revision)) |
---|
71 | (type-instance (get-item-by-psi *type-instance-psi* |
---|
72 | :revision start-revision)) |
---|
73 | (type (get-item-by-psi *type-psi* :revision start-revision))) |
---|
74 | (declare (TopicC instance-topic type-topic) |
---|
75 | (integer start-revision)) |
---|
76 | (let ((assocs (remove-if |
---|
77 | #'null |
---|
78 | (map 'list |
---|
79 | #'(lambda(role) |
---|
80 | (when (and |
---|
81 | (eql (instance-of role :revision start-revision) |
---|
82 | instance) |
---|
83 | (eql (instance-of |
---|
84 | (parent role :revision start-revision) |
---|
85 | :revision start-revision) |
---|
86 | type-instance)) |
---|
87 | (parent role :revision start-revision))) |
---|
88 | (player-in-roles instance-topic :revision start-revision))))) |
---|
89 | (map 'list #'(lambda(assoc) |
---|
90 | (when (find-if |
---|
91 | #'(lambda(role) |
---|
92 | (and (eql (instance-of role :revision start-revision) |
---|
93 | type) |
---|
94 | (eql (player role :revision start-revision) |
---|
95 | type-topic))) |
---|
96 | (roles assoc :revision start-revision)) |
---|
97 | (d::delete-construct assoc))) |
---|
98 | assocs) |
---|
99 | nil)))) |
---|
100 | |
---|
101 | |
---|
102 | (defun delete-related-associations (top start-revision) |
---|
103 | "Deletes all associaitons related to the passed topic." |
---|
104 | (dolist (assoc-role (player-in-roles top :revision start-revision)) |
---|
105 | (d::delete-construct (parent assoc-role))) |
---|
106 | top) |
---|
107 | |
---|
108 | |
---|
109 | (defun get-isi-roles(assoc-top start-revision) |
---|
110 | "Returns all topics representing association-roles." |
---|
111 | (declare (TopicC assoc-top)) |
---|
112 | (declare (integer start-revision)) |
---|
113 | (let ((role-assocs |
---|
114 | (get-associations-by-type assoc-top start-revision |
---|
115 | *tm2rdf-role-property* |
---|
116 | *rdf2tm-subject*))) |
---|
117 | (let ((players |
---|
118 | (get-players-by-role-type |
---|
119 | role-assocs start-revision *rdf2tm-object*))) |
---|
120 | (map 'list #'d::delete-construct role-assocs) |
---|
121 | players))) |
---|
122 | |
---|
123 | |
---|
124 | (defun map-isi-role(role-top start-revision) |
---|
125 | "Maps a passed topic with all its isidorus:types to a |
---|
126 | property list representing an association-role." |
---|
127 | (declare (TopicC role-top)) |
---|
128 | (declare (integer start-revision)) |
---|
129 | (let ((err-pref "From map-isi-role(): ") |
---|
130 | (ids (map-isi-identifiers role-top start-revision)) |
---|
131 | (type-assocs |
---|
132 | (get-associations-by-type |
---|
133 | role-top start-revision *tm2rdf-roletype-property* |
---|
134 | *rdf2tm-subject*)) |
---|
135 | (player-assocs |
---|
136 | (get-associations-by-type |
---|
137 | role-top start-revision *tm2rdf-player-property* |
---|
138 | *rdf2tm-subject*))) |
---|
139 | (let ((types (get-players-by-role-type |
---|
140 | type-assocs start-revision *rdf2tm-object*)) |
---|
141 | (role-players (get-players-by-role-type |
---|
142 | player-assocs start-revision *rdf2tm-object*)) |
---|
143 | (reifiers (get-isi-reifiers role-top start-revision))) |
---|
144 | (elephant:ensure-transaction (:txn-nosync t) |
---|
145 | (map 'list #'d::delete-construct type-assocs) |
---|
146 | (map 'list #'d::delete-construct player-assocs) |
---|
147 | (when (/= 1 (length types)) |
---|
148 | (error "~aexpect one type topic but found: ~a" |
---|
149 | err-pref (length types))) |
---|
150 | (when (= 0 (length role-players)) |
---|
151 | (error "~aexpect one player but found: ~a" |
---|
152 | err-pref (length role-players))) |
---|
153 | (delete-related-associations role-top start-revision) |
---|
154 | (d::delete-construct role-top) |
---|
155 | (list :instance-of (first types) |
---|
156 | :player (first role-players) |
---|
157 | :item-identifiers ids |
---|
158 | :start-revision start-revision |
---|
159 | :reifiers reifiers))))) |
---|
160 | |
---|
161 | |
---|
162 | (defun map-isi-association(assoc-top start-revision tm-id |
---|
163 | &key (document-id *document-id*)) |
---|
164 | "Maps a passed topic with all its isidorus:types to a TM association." |
---|
165 | (declare (TopicC assoc-top)) |
---|
166 | (declare (integer start-revision)) |
---|
167 | (format t "A") |
---|
168 | (let ((err-pref "From map-isi-association(): ") |
---|
169 | (ids (map-isi-identifiers assoc-top start-revision)) |
---|
170 | (type-assocs |
---|
171 | (get-associations-by-type |
---|
172 | assoc-top start-revision *tm2rdf-associationtype-property* |
---|
173 | *rdf2tm-subject*)) |
---|
174 | (scope-assocs |
---|
175 | (get-associations-by-type |
---|
176 | assoc-top start-revision *tm2rdf-scope-property* |
---|
177 | *rdf2tm-subject*)) |
---|
178 | (role-topics (get-isi-roles assoc-top start-revision))) |
---|
179 | (let ((types (get-players-by-role-type |
---|
180 | type-assocs start-revision *rdf2tm-object*)) |
---|
181 | (scopes (get-players-by-role-type |
---|
182 | scope-assocs start-revision *rdf2tm-object*)) |
---|
183 | (reifier-topics (get-isi-reifiers assoc-top start-revision)) |
---|
184 | (assoc-roles |
---|
185 | (remove-if #'null (map 'list |
---|
186 | #'(lambda(role-topic) |
---|
187 | (map-isi-role role-topic start-revision)) |
---|
188 | role-topics)))) |
---|
189 | (elephant:ensure-transaction (:txn-nosync t) |
---|
190 | (map 'list #'d::delete-construct type-assocs) |
---|
191 | (map 'list #'d::delete-construct scope-assocs) |
---|
192 | (when (/= 1 (length types)) |
---|
193 | (error "~aexpect one type topic but found: ~a" |
---|
194 | err-pref (length types))) |
---|
195 | (when (= 0 (length assoc-roles)) |
---|
196 | (error "~aexpect at least one role but found: ~a" |
---|
197 | err-pref (length assoc-roles))) |
---|
198 | (delete-related-associations assoc-top start-revision) |
---|
199 | (d::delete-construct assoc-top) |
---|
200 | (with-tm (start-revision document-id tm-id) |
---|
201 | (add-to-tm |
---|
202 | xml-importer::tm |
---|
203 | (let ((association |
---|
204 | (make-construct 'AssociationC |
---|
205 | :start-revision start-revision |
---|
206 | :item-identifiers ids |
---|
207 | :instance-of (first types) |
---|
208 | :themes scopes |
---|
209 | :roles assoc-roles))) |
---|
210 | (map 'list #'(lambda(association-role) |
---|
211 | (let ((found-item |
---|
212 | (find-if #'(lambda(list-item) |
---|
213 | (and (eql (instance-of association-role) |
---|
214 | (getf list-item :instance-of)) |
---|
215 | (eql (player association-role) |
---|
216 | (getf list-item :player)) |
---|
217 | (getf list-item :reifiers))) |
---|
218 | assoc-roles))) |
---|
219 | (when found-item |
---|
220 | (dolist (reifier-topic (getf found-item :reifiers)) |
---|
221 | (add-reifier association-role reifier-topic |
---|
222 | :revision start-revision))))) |
---|
223 | (roles association :revision start-revision)) |
---|
224 | (dolist (reifier-topic reifier-topics) |
---|
225 | (add-reifier association reifier-topic :revision start-revision)) |
---|
226 | association))))))) |
---|
227 | |
---|
228 | |
---|
229 | (defun map-isi-topic(top start-revision) |
---|
230 | "Maps a passed topic with all its isidorus:types to a TM topic." |
---|
231 | (declare (integer start-revision)) |
---|
232 | (declare(TopicC top)) |
---|
233 | (format t "T") |
---|
234 | (let ((new-psis (map-isi-identifiers |
---|
235 | top start-revision |
---|
236 | :id-type-uri *tm2rdf-subjectidentifier-property*)) |
---|
237 | (new-locators (map-isi-identifiers |
---|
238 | top start-revision |
---|
239 | :id-type-uri *tm2rdf-subjectlocator-property*)) |
---|
240 | (new-item-ids (map-isi-identifiers top start-revision)) |
---|
241 | (occurrence-topics (get-isi-occurrences top start-revision)) |
---|
242 | (name-topics (get-isi-names top start-revision))) |
---|
243 | (bound-subject-identifiers top new-psis start-revision) |
---|
244 | (bound-subject-locators top new-locators start-revision) |
---|
245 | (bound-item-identifiers top new-item-ids start-revision) |
---|
246 | (map 'list #'(lambda(occurrence-topic) |
---|
247 | (map-isi-occurrence top occurrence-topic start-revision)) |
---|
248 | occurrence-topics) |
---|
249 | (map 'list #'(lambda(name-topic) |
---|
250 | (map-isi-name top name-topic start-revision)) |
---|
251 | name-topics)) |
---|
252 | top) |
---|
253 | |
---|
254 | |
---|
255 | (defun get-isi-variants(name-top start-revision) |
---|
256 | "Returns all topics representing a name's variant." |
---|
257 | (declare (TopicC name-top)) |
---|
258 | (declare (integer start-revision)) |
---|
259 | (let ((variant-assocs |
---|
260 | (get-associations-by-type name-top start-revision |
---|
261 | *tm2rdf-variant-property* |
---|
262 | *rdf2tm-subject*))) |
---|
263 | (let ((players |
---|
264 | (get-players-by-role-type |
---|
265 | variant-assocs start-revision *rdf2tm-object*))) |
---|
266 | (map 'list #'d::delete-construct variant-assocs) |
---|
267 | players))) |
---|
268 | |
---|
269 | |
---|
270 | (defun map-isi-variant (name variant-top start-revision) |
---|
271 | "Maps the passed variant-topic to a TM variant." |
---|
272 | (declare (TopicC variant-top)) |
---|
273 | (declare (NameC name)) |
---|
274 | (declare (integer start-revision)) |
---|
275 | (let ((ids (map-isi-identifiers variant-top start-revision)) |
---|
276 | (scope-assocs |
---|
277 | (get-associations-by-type |
---|
278 | variant-top start-revision *tm2rdf-scope-property* |
---|
279 | *rdf2tm-subject*)) |
---|
280 | (value-type-topic |
---|
281 | (get-item-by-psi *tm2rdf-value-property* :revision start-revision))) |
---|
282 | (let ((scopes (get-players-by-role-type |
---|
283 | scope-assocs start-revision *rdf2tm-object*)) |
---|
284 | (value-and-datatype |
---|
285 | (let ((value-occ |
---|
286 | (find-if #'(lambda(occ) |
---|
287 | (eql (instance-of occ) value-type-topic)) |
---|
288 | (occurrences variant-top)))) |
---|
289 | (if value-occ |
---|
290 | (list :value (charvalue value-occ) |
---|
291 | :datatype (datatype value-occ)) |
---|
292 | (list :value "" |
---|
293 | :datatype *xml-string*)))) |
---|
294 | (reifiers (get-isi-reifiers variant-top start-revision))) |
---|
295 | (elephant:ensure-transaction (:txn-nosync t) |
---|
296 | (map 'list #'d::delete-construct scope-assocs) |
---|
297 | (delete-related-associations variant-top start-revision) |
---|
298 | (d::delete-construct variant-top) |
---|
299 | (let ((variant |
---|
300 | (make-construct 'VariantC |
---|
301 | :start-revision start-revision |
---|
302 | :item-identifiers ids |
---|
303 | :themes scopes |
---|
304 | :charvalue (getf value-and-datatype :value) |
---|
305 | :datatype (getf value-and-datatype :datatype) |
---|
306 | :parent name))) |
---|
307 | (dolist (reifier-topic reifiers) |
---|
308 | (add-reifier variant reifier-topic :revision start-revision)) |
---|
309 | variant))))) |
---|
310 | |
---|
311 | |
---|
312 | (defun map-isi-name (top name-top start-revision) |
---|
313 | "Maps the passed occurrence-topic to a TM occurrence." |
---|
314 | (declare (TopicC top name-top)) |
---|
315 | (declare (integer start-revision)) |
---|
316 | (let ((ids (map-isi-identifiers name-top start-revision)) |
---|
317 | (type-assocs |
---|
318 | (get-associations-by-type |
---|
319 | name-top start-revision *tm2rdf-nametype-property* |
---|
320 | *rdf2tm-subject*)) |
---|
321 | (scope-assocs |
---|
322 | (get-associations-by-type |
---|
323 | name-top start-revision *tm2rdf-scope-property* |
---|
324 | *rdf2tm-subject*)) |
---|
325 | (value-type-topic |
---|
326 | (get-item-by-psi *tm2rdf-value-property* :revision start-revision)) |
---|
327 | (variant-topics (get-isi-variants name-top start-revision))) |
---|
328 | (let ((type (let ((fn-types |
---|
329 | (get-players-by-role-type |
---|
330 | type-assocs start-revision *rdf2tm-object*))) |
---|
331 | (when fn-types |
---|
332 | (first fn-types)))) |
---|
333 | (scopes (get-players-by-role-type |
---|
334 | scope-assocs start-revision *rdf2tm-object*)) |
---|
335 | (value |
---|
336 | (let ((value-occ |
---|
337 | (find-if #'(lambda(occ) |
---|
338 | (eql (instance-of occ) value-type-topic)) |
---|
339 | (occurrences name-top)))) |
---|
340 | (if value-occ |
---|
341 | (charvalue value-occ) |
---|
342 | ""))) |
---|
343 | (reifiers (get-isi-reifiers name-top start-revision))) |
---|
344 | (elephant:ensure-transaction (:txn-nosync t) |
---|
345 | (map 'list #'d::delete-construct type-assocs) |
---|
346 | (map 'list #'d::delete-construct scope-assocs) |
---|
347 | (let ((name (make-construct 'NameC |
---|
348 | :start-revision start-revision |
---|
349 | :parent top |
---|
350 | :charvalue value |
---|
351 | :instance-of type |
---|
352 | :item-identifiers ids |
---|
353 | :themes scopes))) |
---|
354 | (map 'list #'(lambda(variant-topic) |
---|
355 | (map-isi-variant name variant-topic |
---|
356 | start-revision)) |
---|
357 | variant-topics) |
---|
358 | (delete-related-associations name-top start-revision) |
---|
359 | (d::delete-construct name-top) |
---|
360 | (dolist (reifier-topic reifiers) |
---|
361 | (add-reifier name reifier-topic :revision start-revision)) |
---|
362 | name))))) |
---|
363 | |
---|
364 | |
---|
365 | (defun get-isi-names(top start-revision) |
---|
366 | "Returns all topics that represents names for the passed top." |
---|
367 | (declare (TopicC top)) |
---|
368 | (declare (integer start-revision)) |
---|
369 | (let ((assocs (get-associations-by-type |
---|
370 | top start-revision *tm2rdf-name-property* |
---|
371 | *rdf2tm-subject*))) |
---|
372 | (let ((name-topics |
---|
373 | (get-players-by-role-type |
---|
374 | assocs start-revision *rdf2tm-object*))) |
---|
375 | (map 'list #'d::delete-construct assocs) |
---|
376 | name-topics))) |
---|
377 | |
---|
378 | |
---|
379 | (defun map-isi-occurrence(top occ-top start-revision) |
---|
380 | "Maps all topics that represents occurrences of the passed topic top |
---|
381 | to occurrence objects." |
---|
382 | (declare (TopicC top occ-top)) |
---|
383 | (declare (integer start-revision)) |
---|
384 | (let ((err-pref "From map-isi-occurrence(): ") |
---|
385 | (ids (map-isi-identifiers occ-top start-revision)) |
---|
386 | (type-assocs |
---|
387 | (get-associations-by-type |
---|
388 | occ-top start-revision *tm2rdf-occurrencetype-property* |
---|
389 | *rdf2tm-subject*)) |
---|
390 | (scope-assocs |
---|
391 | (get-associations-by-type |
---|
392 | occ-top start-revision *tm2rdf-scope-property* |
---|
393 | *rdf2tm-subject*)) |
---|
394 | (value-type-topic |
---|
395 | (get-item-by-psi *tm2rdf-value-property*))) |
---|
396 | (let ((types (get-players-by-role-type |
---|
397 | type-assocs start-revision *rdf2tm-object*)) |
---|
398 | (scopes (get-players-by-role-type |
---|
399 | scope-assocs start-revision *rdf2tm-object*)) |
---|
400 | (value-and-datatype |
---|
401 | (let ((value-occ |
---|
402 | (find-if #'(lambda(occ) |
---|
403 | (eql (instance-of occ) value-type-topic)) |
---|
404 | (occurrences occ-top)))) |
---|
405 | (if value-occ |
---|
406 | (list :value (charvalue value-occ) |
---|
407 | :datatype (datatype value-occ)) |
---|
408 | (list :value "" |
---|
409 | :datatype *xml-string*)))) |
---|
410 | (reifiers (get-isi-reifiers occ-top start-revision))) |
---|
411 | (elephant:ensure-transaction (:txn-nosync t) |
---|
412 | (map 'list #'d::delete-construct type-assocs) |
---|
413 | (map 'list #'d::delete-construct scope-assocs) |
---|
414 | (when (/= 1 (length types)) |
---|
415 | (error "~aexpect one type topic but found: ~a" |
---|
416 | err-pref (length types))) |
---|
417 | (delete-related-associations occ-top start-revision) |
---|
418 | (d::delete-construct occ-top) |
---|
419 | (let ((occurrence |
---|
420 | (make-construct 'OccurrenceC |
---|
421 | :start-revision start-revision |
---|
422 | :parent top |
---|
423 | :themes scopes |
---|
424 | :item-identifiers ids |
---|
425 | :instance-of (first types) |
---|
426 | :charvalue (getf value-and-datatype :value) |
---|
427 | :datatype (getf value-and-datatype :datatype)))) |
---|
428 | (dolist (reifier-topic reifiers) |
---|
429 | (add-reifier occurrence reifier-topic :revision start-revision)) |
---|
430 | occurrence))))) |
---|
431 | |
---|
432 | |
---|
433 | (defun get-isi-occurrences(top start-revision) |
---|
434 | "Returns all topics that represents occurrences for the passed top." |
---|
435 | (declare (TopicC top)) |
---|
436 | (declare (integer start-revision)) |
---|
437 | (let ((assocs (get-associations-by-type |
---|
438 | top start-revision *tm2rdf-occurrence-property* |
---|
439 | *rdf2tm-subject*))) |
---|
440 | (let ((occurrence-topics |
---|
441 | (get-players-by-role-type |
---|
442 | assocs start-revision *rdf2tm-object*))) |
---|
443 | (map 'list #'d::delete-construct assocs) |
---|
444 | occurrence-topics))) |
---|
445 | |
---|
446 | |
---|
447 | (defun get-isi-topics (tm-id start-revision |
---|
448 | &key (document-id *document-id*) |
---|
449 | (type-psi *tm2rdf-topic-type-uri*)) |
---|
450 | "Returns all topics of the given tm and revision." |
---|
451 | (let ((type-topic (get-item-by-psi type-psi |
---|
452 | :revision start-revision))) |
---|
453 | (when type-topic |
---|
454 | (let ((assocs (get-associations-by-type |
---|
455 | type-topic start-revision *type-instance-psi* |
---|
456 | *type-psi*))) |
---|
457 | (let ((isi-topics (get-players-by-role-type |
---|
458 | assocs start-revision *instance-psi*))) |
---|
459 | (let ((topics-in-tm |
---|
460 | (with-tm (start-revision document-id tm-id) |
---|
461 | (intersection isi-topics (topics xml-importer::tm))))) |
---|
462 | (map 'list |
---|
463 | #'(lambda(top) |
---|
464 | (map 'list |
---|
465 | #'(lambda(role) |
---|
466 | (when (find (parent role :revision start-revision) |
---|
467 | assocs) |
---|
468 | (d::delete-construct |
---|
469 | (parent role :revision start-revision)))) |
---|
470 | (player-in-roles top :revision start-revision))) |
---|
471 | topics-in-tm) |
---|
472 | topics-in-tm)))))) |
---|
473 | |
---|
474 | |
---|
475 | (defun get-associations-by-type (top start-revision association-type-psi |
---|
476 | role-type-psi) |
---|
477 | "Returns all associations of the passed associaiton type where the |
---|
478 | topic top is a player in a role of the given roletype." |
---|
479 | (declare (TopicC top)) |
---|
480 | (declare (string association-type-psi role-type-psi)) |
---|
481 | (declare (integer start-revision)) |
---|
482 | (let ((assoc-type (get-item-by-psi association-type-psi |
---|
483 | :revision start-revision)) |
---|
484 | (role-type (get-item-by-psi role-type-psi |
---|
485 | :revision start-revision))) |
---|
486 | (when (and assoc-type role-type) |
---|
487 | (let ((assocs |
---|
488 | (remove-if |
---|
489 | #'null |
---|
490 | (map 'list |
---|
491 | #'(lambda(role) |
---|
492 | (when (and (eql (instance-of (parent role)) assoc-type) |
---|
493 | (eql (instance-of role) role-type)) |
---|
494 | (parent role))) |
---|
495 | (player-in-roles top))))) |
---|
496 | assocs)))) |
---|
497 | |
---|
498 | |
---|
499 | (defun get-players-by-role-type (associations start-revision |
---|
500 | role-type-psi) |
---|
501 | "Returns all players of the passed associaiton that are contained |
---|
502 | in roles of the given type." |
---|
503 | (declare (list associations)) |
---|
504 | (declare (integer start-revision)) |
---|
505 | (declare (string role-type-psi)) |
---|
506 | (let ((role-type (get-item-by-psi role-type-psi |
---|
507 | :revision start-revision))) |
---|
508 | (let ((players |
---|
509 | (remove-if |
---|
510 | #'null |
---|
511 | (map 'list |
---|
512 | #'(lambda(assoc) |
---|
513 | (let ((role |
---|
514 | (find-if |
---|
515 | #'(lambda(role) |
---|
516 | (eql role-type (instance-of role |
---|
517 | :revision start-revision))) |
---|
518 | (roles assoc :revision start-revision)))) |
---|
519 | (when role |
---|
520 | (player role :revision start-revision)))) |
---|
521 | associations)))) |
---|
522 | players))) |
---|
523 | |
---|
524 | |
---|
525 | (defun get-occurrences-by-type (top start-revision |
---|
526 | &key (occurrence-type-uri |
---|
527 | *tm2rdf-itemIdentity-property*)) |
---|
528 | "Returns all occurrences of the given topic, that is of the type |
---|
529 | bound to occurrence-type-uri." |
---|
530 | (declare (TopicC top)) |
---|
531 | (with-revision start-revision |
---|
532 | (let ((identifier-occs |
---|
533 | (remove-if #'null |
---|
534 | (map 'list |
---|
535 | #'(lambda(occurrence) |
---|
536 | (let ((type |
---|
537 | (instance-of occurrence |
---|
538 | :revision start-revision))) |
---|
539 | (let ((type-psi |
---|
540 | (find-if #'(lambda(psi) |
---|
541 | (string= |
---|
542 | occurrence-type-uri |
---|
543 | (uri psi))) |
---|
544 | (psis type :revision start-revision)))) |
---|
545 | (when type-psi |
---|
546 | occurrence)))) |
---|
547 | (occurrences top :revision start-revision))))) |
---|
548 | identifier-occs))) |
---|
549 | |
---|
550 | |
---|
551 | (defun map-isi-identifiers (top start-revision |
---|
552 | &key (id-type-uri |
---|
553 | *tm2rdf-itemIdentity-property*)) |
---|
554 | "Maps identifiers of the type depending on id-type-uri from topic occurrences |
---|
555 | imported from RDF to the corresponding TM constructs." |
---|
556 | (declare (TopicC top)) |
---|
557 | (let ((id-occs (get-occurrences-by-type top start-revision |
---|
558 | :occurrence-type-uri id-type-uri)) |
---|
559 | (class-symbol (cond |
---|
560 | ((string= id-type-uri |
---|
561 | *tm2rdf-itemIdentity-property*) |
---|
562 | 'ItemIdentifierC) |
---|
563 | ((string= id-type-uri |
---|
564 | *tm2rdf-subjectLocator-property*) |
---|
565 | 'SubjectLocatorC) |
---|
566 | ((string= id-type-uri |
---|
567 | *tm2rdf-subjectIdentifier-property*) |
---|
568 | 'PersistentIdC)))) |
---|
569 | (let ((id-uris (map 'list #'charvalue id-occs))) |
---|
570 | (elephant:ensure-transaction (:txn-nosync t) |
---|
571 | (map 'list #'d::delete-construct id-occs) |
---|
572 | (let ((ids (map 'list |
---|
573 | #'(lambda(id-uri) |
---|
574 | (make-instance class-symbol |
---|
575 | :uri id-uri |
---|
576 | :start-revision start-revision)) |
---|
577 | id-uris))) |
---|
578 | ids))))) |
---|
579 | |
---|
580 | |
---|
581 | (defun bound-item-identifiers (construct identifiers start-revision) |
---|
582 | "Bounds the passed item-identifier to the passed construct." |
---|
583 | (declare (ReifiableConstructC construct)) |
---|
584 | (dolist (id identifiers) |
---|
585 | (declare (ItemIdentifierC id)) |
---|
586 | (if (find-if #'(lambda(ii) |
---|
587 | (and (string= (uri ii) (uri id)) |
---|
588 | (not (eql ii id)))) |
---|
589 | (item-identifiers construct :revision start-revision)) |
---|
590 | (d::delete-construct id) |
---|
591 | (add-item-identifier construct id :revision start-revision))) |
---|
592 | construct) |
---|
593 | |
---|
594 | |
---|
595 | (defun bound-subject-identifiers (top identifiers start-revision) |
---|
596 | "Bounds the passed psis to the passed topic." |
---|
597 | (declare (TopicC top)) |
---|
598 | (dolist (id identifiers) |
---|
599 | (declare (PersistentIdC id)) |
---|
600 | (if (find-if #'(lambda(psi) |
---|
601 | (and (string= (uri psi) (uri id)) |
---|
602 | (not (eql psi id)))) |
---|
603 | (psis top :revision start-revision)) |
---|
604 | (d::delete-construct id) |
---|
605 | (add-psi top id :revision start-revision))) |
---|
606 | top) |
---|
607 | |
---|
608 | |
---|
609 | (defun bound-subject-locators (top locators start-revision) |
---|
610 | "Bounds the passed locators to the passed topic." |
---|
611 | (declare (TopicC top)) |
---|
612 | (dolist (id locators) |
---|
613 | (declare (SubjectLocatorC id)) |
---|
614 | (if (find-if #'(lambda(locator) |
---|
615 | (and (string= (uri locator) (uri id)) |
---|
616 | (not (eql locator id)))) |
---|
617 | (locators top :revision start-revision)) |
---|
618 | (d::delete-construct id) |
---|
619 | (add-locator top id :revision start-revision))) |
---|
620 | top) |
---|
621 | |
---|
622 | |
---|
623 | (defun get-isi-reifiers (construct start-revision) |
---|
624 | "Returns all reifiers from the passed construct." |
---|
625 | (declare (TopicC construct)) |
---|
626 | (let ((reifier-assocs |
---|
627 | (get-associations-by-type |
---|
628 | construct start-revision *tm2rdf-reifier-property* |
---|
629 | *rdf2tm-subject*))) |
---|
630 | (let ((reifiers |
---|
631 | (get-players-by-role-type |
---|
632 | reifier-assocs start-revision *rdf2tm-object*))) |
---|
633 | reifiers))) |
---|