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 | |
---|
9 | |
---|
10 | (in-package :xml-importer) |
---|
11 | |
---|
12 | (defun get-reifier-topic-xtm1.0 (reifiable-elem start-revision) |
---|
13 | "Returns a reifier topic of the reifiable-element or nil." |
---|
14 | (declare (dom:element reifiable-elem)) |
---|
15 | (let ((reifier-uri |
---|
16 | (when (dom:get-attribute-node reifiable-elem "id") |
---|
17 | (dom:node-value (dom:get-attribute-node reifiable-elem "id"))))) |
---|
18 | (when (and (stringp reifier-uri) |
---|
19 | (> (length reifier-uri) 0)) |
---|
20 | (let ((psi |
---|
21 | (elephant:get-instance-by-value 'd:PersistentIdC 'd:uri |
---|
22 | (concatenate 'string "#" reifier-uri)))) |
---|
23 | (when psi |
---|
24 | (let ((reifier-topic (identified-construct psi :revision start-revision))) |
---|
25 | (when reifier-topic |
---|
26 | reifier-topic))))))) |
---|
27 | |
---|
28 | |
---|
29 | (defun get-topic-id-xtm1.0 (topic-elem) |
---|
30 | "returns the id attribute of a topic element" |
---|
31 | (declare (dom:element topic-elem)) |
---|
32 | (dom:node-value (dom:get-attribute-node topic-elem "id"))) |
---|
33 | |
---|
34 | |
---|
35 | (defun from-resourceRef-elem-xtm1.0 (resourceRef-elem) |
---|
36 | "returns the href attrubte of the passed resourceRef element" |
---|
37 | (when resourceRef-elem |
---|
38 | (dom:get-attribute-ns resourceRef-elem *xtm1.0-xlink* "href"))) |
---|
39 | |
---|
40 | |
---|
41 | (defun from-resourceX-elem-xtm1.0 (parent-elem) |
---|
42 | "handles the following problem: { resourceRef | resourceData } |
---|
43 | and returns a list with a data and a type node" |
---|
44 | (when parent-elem |
---|
45 | (let ((data |
---|
46 | (let ((resourceRef-elem |
---|
47 | (xpath-single-child-elem-by-qname parent-elem *xtm1.0-ns* "resourceRef"))) |
---|
48 | (if resourceRef-elem |
---|
49 | (from-resourceRef-elem-xtm1.0 resourceRef-elem) |
---|
50 | (let ((resourceData-elem |
---|
51 | (xpath-single-child-elem-by-qname parent-elem *xtm1.0-ns* "resourceData"))) |
---|
52 | (if resourceData-elem |
---|
53 | (xpath-fn-string resourceData-elem) |
---|
54 | nil))))) |
---|
55 | (type |
---|
56 | (let ((data-elem (xpath-single-child-elem-by-qname parent-elem *xtm1.0-ns* "resourceData"))) |
---|
57 | (declare (dom:element parent-elem)) |
---|
58 | (if data-elem |
---|
59 | *XML-STRING* |
---|
60 | *XML-URI*)))) |
---|
61 | (unless data |
---|
62 | (error "from-resourceX-elem-xtm1.0: one of resourceRef or resourceData must be set")) |
---|
63 | (list :data data :type type)))) |
---|
64 | |
---|
65 | |
---|
66 | (defun from-variant-elem-xtm1.0 (variant-elem parent-construct start-revision &key (xtm-id *current-xtm*)) |
---|
67 | "geberates a VariantC object; |
---|
68 | variant = element variant { parameters, variantName?, variant* }" |
---|
69 | (declare (dom:element variant-elem)) |
---|
70 | (declare (CharacteristicC parent-construct)) ;;parent name or parent variant object |
---|
71 | (let ((parameters |
---|
72 | (remove-duplicates |
---|
73 | (remove-if #'null |
---|
74 | (append |
---|
75 | (from-parameters-elem-xtm1.0 |
---|
76 | (xpath-single-child-elem-by-qname variant-elem *xtm1.0-ns* "parameters") |
---|
77 | start-revision :xtm-id xtm-id) |
---|
78 | (themes parent-construct :revision start-revision))))) |
---|
79 | (variantName (from-resourceX-elem-xtm1.0 |
---|
80 | (xpath-single-child-elem-by-qname variant-elem *xtm1.0-ns* "variantName"))) |
---|
81 | (parent-name (cond |
---|
82 | ((typep parent-construct 'NameC) |
---|
83 | parent-construct) |
---|
84 | ((typep parent-construct 'VariantC) |
---|
85 | (parent parent-construct)) |
---|
86 | (t |
---|
87 | (error "from-variant-elem-xtm1.0: parent-construct is neither NameC nor VariantC")))) |
---|
88 | (reifier-topic (get-reifier-topic-xtm1.0 variant-elem start-revision))) |
---|
89 | (unless (and variantName parameters) |
---|
90 | (error "from-variant-elem-xtm1.0: parameters and variantName must be set")) |
---|
91 | (let ((variant (make-construct 'VariantC |
---|
92 | :start-revision start-revision |
---|
93 | :themes parameters |
---|
94 | :charvalue (getf variantName :data) |
---|
95 | :datatype (getf variantName :type) |
---|
96 | :reifier reifier-topic |
---|
97 | :parent parent-name))) |
---|
98 | (let ((inner-variants |
---|
99 | (map 'list #'(lambda(x) |
---|
100 | (from-variant-elem-xtm1.0 x variant start-revision :xtm-id xtm-id)) |
---|
101 | (xpath-child-elems-by-qname variant-elem *xtm1.0-ns* "variant")))) |
---|
102 | (append (list variant) inner-variants))))) |
---|
103 | |
---|
104 | |
---|
105 | (defun from-parameters-elem-xtm1.0 (parameters-elem start-revision &key (xtm-id *current-xtm*)) |
---|
106 | "handles a parameters element and returns all referenced TopicC objects |
---|
107 | parameters = element { (topicRef | subjectIndicatorRef)+ }" |
---|
108 | (when parameters-elem |
---|
109 | (let ((parameters |
---|
110 | (let ((topicRefs |
---|
111 | (map 'list #'from-topicRef-elem-xtm1.0 |
---|
112 | (xpath-child-elems-by-qname parameters-elem *xtm1.0-ns* |
---|
113 | "topicRef"))) |
---|
114 | (subjectIndicatorRefs |
---|
115 | (map 'list #'(lambda(x) |
---|
116 | (get-xlink-attribute x "href")) |
---|
117 | (xpath-child-elems-by-qname parameters-elem *xtm1.0-ns* |
---|
118 | "subjectIndicatorRef")))) |
---|
119 | (let ((topic-list |
---|
120 | (append |
---|
121 | (map 'list #'(lambda(x) |
---|
122 | (get-item-by-id x :xtm-id xtm-id |
---|
123 | :revision start-revision)) |
---|
124 | topicRefs) |
---|
125 | (map 'list #'(lambda(x) |
---|
126 | (get-item-by-psi x :revision start-revision)) |
---|
127 | subjectIndicatorRefs)))) |
---|
128 | (unless (= (+ (length topicRefs) (length subjectIndicatorRefs)) (length topic-list)) |
---|
129 | (error "from-parameters-elem-xtm1.0: a topic reference is missing")) |
---|
130 | (remove-duplicates topic-list))))) |
---|
131 | (declare (dom:element parameters-elem)) |
---|
132 | parameters))) |
---|
133 | |
---|
134 | |
---|
135 | (defun get-xlink-attribute (elem attribute-name) |
---|
136 | "returns the attribute \"attribute-name of\" elem" |
---|
137 | (declare (dom:element elem)) |
---|
138 | (declare (string attribute-name)) |
---|
139 | (dom:get-attribute-ns elem *xtm1.0-xlink* attribute-name)) |
---|
140 | |
---|
141 | |
---|
142 | (defun from-baseName-elem-xtm1.0 (baseName-elem top start-revision &key (xtm-id *current-xtm*)) |
---|
143 | "creates NameC instances for the TopicC top |
---|
144 | baseName = element baseName { scope?, baseNameString, variant* }" |
---|
145 | (declare (dom:element baseName-elem)) |
---|
146 | (declare (TopicC top)) |
---|
147 | (declare (optimize (debug 3))) |
---|
148 | (let ((themes (when (xpath-single-child-elem-by-qname baseName-elem *xtm1.0-ns* "scope") |
---|
149 | (from-scope-elem-xtm1.0 |
---|
150 | (xpath-single-child-elem-by-qname baseName-elem *xtm1.0-ns* "scope") |
---|
151 | start-revision :xtm-id xtm-id))) |
---|
152 | (baseNameString (xpath-fn-string |
---|
153 | (xpath-single-child-elem-by-qname baseName-elem *xtm1.0-ns* "baseNameString"))) |
---|
154 | (reifier-topic (get-reifier-topic-xtm1.0 baseName-elem start-revision))) |
---|
155 | (unless baseNameString |
---|
156 | (error "A baseName must have exactly one baseNameString")) |
---|
157 | (let ((name (make-construct 'NameC |
---|
158 | :start-revision start-revision |
---|
159 | :parent top |
---|
160 | :charvalue baseNameString |
---|
161 | :reifier reifier-topic |
---|
162 | :themes themes))) |
---|
163 | (map 'list #'(lambda(x) |
---|
164 | (from-variant-elem-xtm1.0 x name start-revision :xtm-id xtm-id)) |
---|
165 | (xpath-child-elems-by-qname baseName-elem *xtm1.0-ns* "variant")) |
---|
166 | name))) |
---|
167 | |
---|
168 | |
---|
169 | (defun from-topicRef-elem-xtm1.0 (topicRef-elem) |
---|
170 | "returns all the href attribute of the given topicRef-elem without |
---|
171 | '#' character" |
---|
172 | (when topicRef-elem |
---|
173 | (let ((href (get-xlink-attribute topicRef-elem "href"))) |
---|
174 | (declare (dom:element topicRef-elem)) |
---|
175 | (unless (char= (elt href 0) #\#) |
---|
176 | (error "cannot handle topicrefs that don't start with #")) |
---|
177 | (subseq href 1)))) |
---|
178 | |
---|
179 | |
---|
180 | (defun get-instanceOf-refs-xtm1.0 (parent-elem &key (xtm-id d:*current-xtm*)) |
---|
181 | "returns the topic ids of the topics referenced by the element topicRef and |
---|
182 | subjectIndicatorRef as a list of strings" |
---|
183 | (when parent-elem |
---|
184 | (let ((instanceOf-elems (xpath-child-elems-by-qname parent-elem *xtm1.0-ns* "instanceOf"))) |
---|
185 | (when (> (length instanceOf-elems) 0) |
---|
186 | (let ((topicRefs |
---|
187 | (map 'list #'(lambda(x) |
---|
188 | (when (xpath-single-child-elem-by-qname |
---|
189 | x *xtm1.0-ns* "topicRef") |
---|
190 | (from-topicRef-elem-xtm1.0 |
---|
191 | (xpath-single-child-elem-by-qname x *xtm1.0-ns* |
---|
192 | "topicRef")))) |
---|
193 | instanceOf-elems)) |
---|
194 | (subjectIndicatorRefs |
---|
195 | (map 'list #'(lambda(x) |
---|
196 | (when (xpath-single-child-elem-by-qname |
---|
197 | x *xtm1.0-ns* "subjectIndicatorRef") |
---|
198 | (get-xlink-attribute |
---|
199 | (xpath-single-child-elem-by-qname |
---|
200 | x *xtm1.0-ns* "subjectIndicatorRef") "href"))) |
---|
201 | instanceOf-elems))) |
---|
202 | (let ((ids |
---|
203 | (remove-if #'null |
---|
204 | (append |
---|
205 | (map 'list #'(lambda(x) |
---|
206 | (get-topicid-by-psi x :xtm-id xtm-id)) |
---|
207 | subjectIndicatorRefs) |
---|
208 | topicRefs)))) |
---|
209 | (declare (dom:element parent-elem)) |
---|
210 | ids)))))) |
---|
211 | |
---|
212 | |
---|
213 | (defun from-roleSpec-elem-xtm1.0 (roleSpec-elem start-revision |
---|
214 | &key (xtm-id *current-xtm*)) |
---|
215 | "returns the referenced topic of the roleSpec's topicRef and subjectIndicatorRef element." |
---|
216 | (when roleSpec-elem |
---|
217 | (let ((top-id |
---|
218 | (when (xpath-single-child-elem-by-qname roleSpec-elem *xtm1.0-ns* |
---|
219 | "topicRef") |
---|
220 | (from-topicRef-elem-xtm1.0 |
---|
221 | (xpath-single-child-elem-by-qname roleSpec-elem *xtm1.0-ns* |
---|
222 | "topicRef")))) |
---|
223 | (sIRs (map 'list #'(lambda(uri) |
---|
224 | (get-topicid-by-psi uri :xtm-id xtm-id |
---|
225 | :revision start-revision)) |
---|
226 | (map 'list #'(lambda(x) |
---|
227 | (dom:get-attribute-ns x *xtm1.0-xlink* "href")) |
---|
228 | (xpath-child-elems-by-qname roleSpec-elem *xtm1.0-ns* |
---|
229 | "subjectIndicatorRef"))))) |
---|
230 | (let ((ref-topic |
---|
231 | (first (remove-if #'null |
---|
232 | (append |
---|
233 | (when top-id |
---|
234 | (list (get-item-by-id top-id :xtm-id xtm-id |
---|
235 | :revision start-revision))) |
---|
236 | (map 'list #'(lambda(id) |
---|
237 | (get-item-by-id |
---|
238 | id :xtm-id xtm-id |
---|
239 | :revision start-revision)) |
---|
240 | sIRs)))))) |
---|
241 | (declare (dom:element roleSpec-elem)) |
---|
242 | (unless ref-topic |
---|
243 | (error (make-condition 'missing-reference-error |
---|
244 | :message (format nil "from-roleSpec-elem-xtm1.0: could not resolve topicid ~a" top-id)))) |
---|
245 | ref-topic)))) |
---|
246 | |
---|
247 | |
---|
248 | (defun from-scope-elem-xtm1.0 (scope-elem start-revision &key (xtm-id *current-xtm*)) |
---|
249 | "returns the topics referenced by this scope element. |
---|
250 | the nested elements resourceRef and subjectIndicatorRef are ignored" |
---|
251 | (when scope-elem |
---|
252 | (when (xpath-child-elems-by-qname scope-elem *xtm1.0-ns* "topicRef") |
---|
253 | (let ((refs |
---|
254 | (append (map 'list #'from-topicRef-elem-xtm1.0 |
---|
255 | (xpath-child-elems-by-qname scope-elem *xtm1.0-ns* |
---|
256 | "topicRef")) |
---|
257 | (map 'list #'(lambda(uri)(get-topicid-by-psi uri :xtm-id xtm-id)) |
---|
258 | (map 'list #'(lambda(x) |
---|
259 | (dom:get-attribute-ns x *xtm1.0-xlink* |
---|
260 | "href")) |
---|
261 | (xpath-child-elems-by-qname scope-elem *xtm1.0-ns* |
---|
262 | "subjectIndicatorRef")))))) |
---|
263 | (let ((ref-topics (map 'list |
---|
264 | #'(lambda(x) |
---|
265 | (let ((ref-topic |
---|
266 | (get-item-by-id x :xtm-id xtm-id |
---|
267 | :revision start-revision))) |
---|
268 | (if ref-topic |
---|
269 | ref-topic |
---|
270 | (error (make-condition 'missing-reference-error |
---|
271 | :message (format nil "from-scope-elem-xtm1.0: could not resolve reference ~a" x)))))) |
---|
272 | refs))) |
---|
273 | (declare (dom:element scope-elem)) |
---|
274 | (unless (>= (length ref-topics) 1) |
---|
275 | (error "need at least one topic in a scope")) |
---|
276 | ref-topics))))) |
---|
277 | |
---|
278 | |
---|
279 | (defun from-occurrence-elem-xtm1.0 (occ-elem top start-revision &key (xtm-id *current-xtm*)) |
---|
280 | "creates instances of OccurrenceC with the nested elements instanceOf, |
---|
281 | scope, resourceRef and resourceData" |
---|
282 | (declare (dom:element occ-elem)) |
---|
283 | (declare (TopicC top)) |
---|
284 | (declare (integer start-revision)) |
---|
285 | (let* |
---|
286 | ((instanceOf (when (get-instanceOf-refs-xtm1.0 occ-elem :xtm-id xtm-id) |
---|
287 | (get-item-by-id |
---|
288 | (first (get-instanceOf-refs-xtm1.0 occ-elem |
---|
289 | :xtm-id xtm-id)) |
---|
290 | :xtm-id xtm-id :revision start-revision))) |
---|
291 | (themes (from-scope-elem-xtm1.0 |
---|
292 | (xpath-single-child-elem-by-qname occ-elem *xtm1.0-ns* "scope") |
---|
293 | start-revision :xtm-id xtm-id)) |
---|
294 | (occurrence-value |
---|
295 | (from-resourceX-elem-xtm1.0 occ-elem)) |
---|
296 | (reifier-topic (get-reifier-topic-xtm1.0 occ-elem start-revision))) |
---|
297 | (unless occurrence-value |
---|
298 | (error "from-occurrence-elem-xtm1.0: one of resourceRef and resourceData must be set")) |
---|
299 | (unless instanceOf |
---|
300 | (format t "from-occurrence-elem-xtm1.0: type is missing -> ~a~%" |
---|
301 | *type-instance-psi*) |
---|
302 | (setf instanceOf (get-item-by-psi *type-instance-psi* |
---|
303 | :revision start-revision))) |
---|
304 | (make-construct 'OccurrenceC |
---|
305 | :start-revision start-revision |
---|
306 | :parent top |
---|
307 | :themes themes |
---|
308 | :instance-of instanceOf |
---|
309 | :charvalue (getf occurrence-value :data) |
---|
310 | :reifier reifier-topic |
---|
311 | :datatype (getf occurrence-value :type)))) |
---|
312 | |
---|
313 | |
---|
314 | (defun from-subjectIdentity-elem-xtm1.0 (subjectIdentity-elem start-revision) |
---|
315 | "creates PersistentIdC's from the element subjectIdentity" |
---|
316 | (when subjectIdentity-elem |
---|
317 | (let ((psi-refs |
---|
318 | (map 'list #'(lambda(x) |
---|
319 | (get-xlink-attribute x "href")) |
---|
320 | (xpath-child-elems-by-qname subjectIdentity-elem *xtm1.0-ns* |
---|
321 | "subjectIndicatorRef"))) |
---|
322 | (locator-refs |
---|
323 | (map 'list #'(lambda(x) |
---|
324 | (get-xlink-attribute x "href")) |
---|
325 | (xpath-child-elems-by-qname subjectIdentity-elem *xtm1.0-ns* |
---|
326 | "resourceRef")))) |
---|
327 | (let ((psis |
---|
328 | (map 'list #'(lambda(uri) |
---|
329 | (let ((id |
---|
330 | (make-construct 'PersistentIdC |
---|
331 | :uri uri |
---|
332 | :start-revision start-revision))) |
---|
333 | id)) |
---|
334 | psi-refs)) |
---|
335 | (locators (map 'list |
---|
336 | #'(lambda(uri) |
---|
337 | (let ((loc |
---|
338 | (make-construct 'SubjectLocatorC |
---|
339 | :uri uri |
---|
340 | :start-revision start-revision))) |
---|
341 | loc)) |
---|
342 | locator-refs))) |
---|
343 | (declare (dom:element subjectIdentity-elem)) |
---|
344 | (declare (integer start-revision)) |
---|
345 | (list :psis psis :locators locators))))) |
---|
346 | |
---|
347 | |
---|
348 | (defun from-member-elem-xtm1.0 (member-elem start-revision |
---|
349 | &key (xtm-id *current-xtm*)) |
---|
350 | "returns a list with the role- type, player and itemIdentities" |
---|
351 | (when member-elem |
---|
352 | (elephant:ensure-transaction (:txn-nosync t) |
---|
353 | (let ((type (from-roleSpec-elem-xtm1.0 |
---|
354 | (xpath-single-child-elem-by-qname member-elem *xtm1.0-ns* |
---|
355 | "roleSpec") |
---|
356 | start-revision :xtm-id xtm-id)) |
---|
357 | (player |
---|
358 | (let ((topicRef |
---|
359 | (from-topicRef-elem-xtm1.0 (xpath-single-child-elem-by-qname |
---|
360 | member-elem *xtm1.0-ns* "topicRef"))) |
---|
361 | (sIRs (xpath-child-elems-by-qname |
---|
362 | member-elem *xtm1.0-ns* "subjectIndicatorRef"))) |
---|
363 | (remove-if |
---|
364 | #'null |
---|
365 | (append |
---|
366 | (when topicRef |
---|
367 | (list (get-item-by-id topicRef |
---|
368 | :xtm-id xtm-id |
---|
369 | :revision start-revision))) |
---|
370 | (map 'list #'(lambda(topicid) |
---|
371 | (get-item-by-id |
---|
372 | topicid |
---|
373 | :xtm-id xtm-id |
---|
374 | :revision start-revision)) |
---|
375 | (map 'list #'(lambda(uri) |
---|
376 | (get-topicid-by-psi uri :xtm-id xtm-id)) |
---|
377 | (map 'list #'(lambda(x) |
---|
378 | (get-xlink-attribute x "href")) |
---|
379 | sIRs))))))) |
---|
380 | (reifier-topic (get-reifier-topic-xtm1.0 member-elem start-revision))) |
---|
381 | (declare (dom:element member-elem)) |
---|
382 | (unless player ; if no type is given a standard type will be assigend later in from-assoc... |
---|
383 | (error "from-member-elem-xtm1.0: missing player in role")) |
---|
384 | (list :start-revision start-revision |
---|
385 | :instance-of type |
---|
386 | :player (first player) |
---|
387 | :item-identifiers nil |
---|
388 | :reifier reifier-topic))))) |
---|
389 | |
---|
390 | |
---|
391 | (defun from-topic-elem-to-stub-xtm1.0 (topic-elem start-revision |
---|
392 | &key |
---|
393 | (xtm-id *current-xtm*)) |
---|
394 | "creates a TopicC instance with a start-revision, all psis, the topicid and the xtm-id" |
---|
395 | (declare (dom:element topic-elem)) |
---|
396 | (declare (integer start-revision)) |
---|
397 | (elephant:ensure-transaction (:txn-nosync t) |
---|
398 | (let ((identifiers (from-subjectIdentity-elem-xtm1.0 |
---|
399 | (xpath-single-child-elem-by-qname |
---|
400 | topic-elem |
---|
401 | *xtm1.0-ns* |
---|
402 | "subjectIdentity") |
---|
403 | start-revision)) |
---|
404 | (topic-identifiers |
---|
405 | (list (make-construct 'TopicIdentificationC |
---|
406 | :uri (get-topic-id-xtm1.0 topic-elem) |
---|
407 | :xtm-id xtm-id)))) |
---|
408 | (make-construct 'TopicC :start-revision start-revision |
---|
409 | :psis (getf identifiers :psis) |
---|
410 | :locators (getf identifiers :locators) |
---|
411 | :topic-identifiers topic-identifiers)))) |
---|
412 | |
---|
413 | |
---|
414 | (defun merge-topic-elem-xtm1.0 (topic-elem start-revision |
---|
415 | &key |
---|
416 | tm |
---|
417 | (xtm-id *current-xtm*)) |
---|
418 | "Adds further elements (names, occurrences) and instanceOf |
---|
419 | associations to the topic" |
---|
420 | (declare (dom:element topic-elem)) |
---|
421 | (declare (integer start-revision)) |
---|
422 | (declare (TopicMapC tm)) |
---|
423 | (elephant:ensure-transaction (:txn-nosync t) |
---|
424 | (let ((top |
---|
425 | (get-item-by-id |
---|
426 | (get-topic-id-xtm1.0 topic-elem) |
---|
427 | :xtm-id xtm-id :revision start-revision)) |
---|
428 | (instanceOf-topicRefs |
---|
429 | (remove-if #'null (get-instanceOf-refs-xtm1.0 topic-elem |
---|
430 | :xtm-id xtm-id))) |
---|
431 | (baseName-elems |
---|
432 | (xpath-child-elems-by-qname topic-elem *xtm1.0-ns* "baseName")) |
---|
433 | (occ-elems (xpath-child-elems-by-qname topic-elem *xtm1.0-ns* "occurrence"))) |
---|
434 | (unless top |
---|
435 | (error (make-condition 'missing-reference-error |
---|
436 | :message (format nil "topic ~a could not be found" |
---|
437 | (get-attribute topic-elem "id"))))) |
---|
438 | ;;names |
---|
439 | (map 'list #'(lambda(x) |
---|
440 | (from-baseName-elem-xtm1.0 x top start-revision :xtm-id xtm-id)) |
---|
441 | baseName-elems) |
---|
442 | ;;occurrences |
---|
443 | (map 'list #'(lambda(x) |
---|
444 | (from-occurrence-elem-xtm1.0 x top start-revision :xtm-id xtm-id)) |
---|
445 | occ-elems) |
---|
446 | ;;instanceOf |
---|
447 | (dolist (instanceOf-topicRef instanceOf-topicRefs) |
---|
448 | (create-instanceof-association instanceOf-topicRef top start-revision |
---|
449 | :xtm-id xtm-id :tm tm)) |
---|
450 | (add-to-tm tm top)))) |
---|
451 | |
---|
452 | |
---|
453 | (defun from-association-elem-xtm1.0 (assoc-elem start-revision |
---|
454 | &key tm (xtm-id *current-xtm*)) |
---|
455 | (declare (dom:element assoc-elem)) |
---|
456 | (declare (integer start-revision)) |
---|
457 | (declare (TopicMapC tm)) |
---|
458 | (elephant:ensure-transaction (:txn-nosync t) |
---|
459 | (let ((type (when (get-instanceOf-refs-xtm1.0 assoc-elem :xtm-id xtm-id) |
---|
460 | (get-item-by-id (first (get-instanceOf-refs-xtm1.0 assoc-elem |
---|
461 | :xtm-id xtm-id)) |
---|
462 | :xtm-id xtm-id |
---|
463 | :revision start-revision))) |
---|
464 | (themes |
---|
465 | (from-scope-elem-xtm1.0 |
---|
466 | (xpath-single-child-elem-by-qname assoc-elem *xtm1.0-ns* "scope") |
---|
467 | start-revision :xtm-id xtm-id)) |
---|
468 | (roles (map 'list |
---|
469 | #'(lambda(member-elem) |
---|
470 | (from-member-elem-xtm1.0 member-elem start-revision |
---|
471 | :xtm-id xtm-id)) |
---|
472 | (xpath-child-elems-by-qname assoc-elem *xtm1.0-ns* "member"))) |
---|
473 | (reifier-topic (get-reifier-topic-xtm1.0 assoc-elem start-revision))) |
---|
474 | (unless roles |
---|
475 | (error "from-association-elem-xtm1.0: roles are missing in association")) |
---|
476 | (setf roles (set-standard-role-types roles start-revision)) |
---|
477 | (unless type |
---|
478 | (format t "from-association-elem-xtm1.0: type is missing -> http://www.topicmaps.org/xtm/1.0/core.xtm#association~%") |
---|
479 | (setf type (get-item-by-id "association" :xtm-id "core.xtm" |
---|
480 | :revision start-revision))) |
---|
481 | (add-to-tm tm |
---|
482 | (make-construct 'AssociationC |
---|
483 | :start-revision start-revision |
---|
484 | :instance-of type |
---|
485 | :themes themes |
---|
486 | :reifier reifier-topic |
---|
487 | :roles roles))))) |
---|
488 | |
---|
489 | |
---|
490 | (defun set-standard-role-types (roles start-revision) |
---|
491 | "sets the missing role types of the passed roles to the default types." |
---|
492 | (when roles |
---|
493 | (let ((empty-roles (loop for role in roles |
---|
494 | when (not (getf role :instance-of)) |
---|
495 | collect role))) |
---|
496 | (when empty-roles |
---|
497 | (let ((is-type (loop for role in roles |
---|
498 | when (and (getf role :instance-of) |
---|
499 | (loop for psi in (psis (getf role :instance-of)) |
---|
500 | when (string= (uri psi) *type-psi*) |
---|
501 | return t)) |
---|
502 | return t))) |
---|
503 | (declare (list roles)) |
---|
504 | (when (not is-type) |
---|
505 | (loop for role in roles |
---|
506 | when (not (getf role :instance-of)) |
---|
507 | do (setf (getf role :instance-of) |
---|
508 | (get-item-by-psi *type-psi* :revision start-revision)) |
---|
509 | (format t "set-standard-role-types: role type is missing -> ~a~%" |
---|
510 | *type-psi*) |
---|
511 | (return t))) |
---|
512 | (when (or (> (length empty-roles) 1) (and empty-roles (not is-type))) |
---|
513 | (loop for role in roles |
---|
514 | when (not (getf role :instance-of)) |
---|
515 | do (setf (getf role :instance-of) |
---|
516 | (get-item-by-psi *instance-psi* :revision start-revision)) |
---|
517 | (format t "set-standard-role-types: role type is missing -> ~a~%" |
---|
518 | *instance-psi*)))))) |
---|
519 | roles)) |
---|
520 | |
---|
521 | |
---|
522 | (defun importer-xtm1.0 (xtm-dom |
---|
523 | &key |
---|
524 | (tm-id (error "you must provide a stable identifier (PSI-style) for this TM")) |
---|
525 | (xtm-id d:*current-xtm*) |
---|
526 | (revision (get-revision))) |
---|
527 | "imports the elements topic and association from a passed dom by caling |
---|
528 | the from-<elem>-xtm1.0 functions" |
---|
529 | ;TODO: remove code duplication between importer-xtm1.0 and importer |
---|
530 | (declare (dom:element xtm-dom)) |
---|
531 | (declare (integer revision)) |
---|
532 | (assert elephant:*store-controller*) |
---|
533 | (with-writer-lock |
---|
534 | (with-tm (revision xtm-id tm-id) |
---|
535 | (let |
---|
536 | ((topic-vector (xpath-child-elems-by-qname xtm-dom *xtm1.0-ns* "topic")) |
---|
537 | (assoc-vector (xpath-child-elems-by-qname xtm-dom *xtm1.0-ns* "association"))) |
---|
538 | (loop for topic across topic-vector |
---|
539 | do (from-topic-elem-to-stub-xtm1.0 topic revision |
---|
540 | :xtm-id xtm-id)) |
---|
541 | (loop for top-elem across topic-vector |
---|
542 | do |
---|
543 | (format t "t") |
---|
544 | (merge-topic-elem-xtm1.0 top-elem revision |
---|
545 | :tm tm |
---|
546 | :xtm-id xtm-id)) |
---|
547 | (loop for assoc-elem across assoc-vector |
---|
548 | do |
---|
549 | (format t "a") |
---|
550 | (from-association-elem-xtm1.0 assoc-elem revision |
---|
551 | :tm tm |
---|
552 | :xtm-id xtm-id)))))) |
---|