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 | (defpackage :reification-test |
---|
11 | (:use |
---|
12 | :common-lisp |
---|
13 | :datamodel |
---|
14 | :it.bese.FiveAM |
---|
15 | :unittests-constants |
---|
16 | :fixtures |
---|
17 | :exporter) |
---|
18 | (:import-from :constants |
---|
19 | *xtm2.0-ns* |
---|
20 | *xtm1.0-ns* |
---|
21 | *xtm1.0-xlink* |
---|
22 | *rdf-ns* |
---|
23 | *rdfs-ns* |
---|
24 | *type-psi* |
---|
25 | *instance-psi* |
---|
26 | *type-instance-psi* |
---|
27 | *rdf2tm-subject* |
---|
28 | *rdf2tm-object*) |
---|
29 | (:import-from :xml-tools |
---|
30 | xpath-child-elems-by-qname xpath-single-child-elem-by-qname |
---|
31 | xpath-fn-string) |
---|
32 | (:export |
---|
33 | :reification-test |
---|
34 | :run-reification-tests |
---|
35 | :test-merge-reifier-topics |
---|
36 | :test-xtm1.0-reification |
---|
37 | :test-xtm2.0-reification |
---|
38 | :test-xtm1.0-reification-exporter |
---|
39 | :test-xtm2.0-reification-exporter |
---|
40 | :test-rdf-importer-reification |
---|
41 | :test-rdf-importer-reification-2 |
---|
42 | :test-rdf-importer-reification-3 |
---|
43 | :test-rdf-importer-reification-4 |
---|
44 | :test-rdf-exporter-reification |
---|
45 | :test-rdf-exporter-reification-2 |
---|
46 | :test-rdf-exporter-reification-3 |
---|
47 | :test-rdf-exporter-reification-4 |
---|
48 | :test-fragment-reification)) |
---|
49 | |
---|
50 | |
---|
51 | (in-package :reification-test) |
---|
52 | |
---|
53 | |
---|
54 | (def-suite reification-test |
---|
55 | :description "tests various functions of the reification functions") |
---|
56 | |
---|
57 | (in-suite reification-test) |
---|
58 | |
---|
59 | |
---|
60 | (test test-merge-reifier-topics |
---|
61 | "Tests the function merge-constructs." |
---|
62 | (let ((db-dir "data_base") |
---|
63 | (revision-1 100) |
---|
64 | (revision-2 200)) |
---|
65 | (clean-out-db db-dir) |
---|
66 | (elephant:open-store (xml-importer:get-store-spec db-dir)) |
---|
67 | (let ((ii-1-1 (make-instance 'ItemIdentifierC |
---|
68 | :uri "ii-1-1" |
---|
69 | :start-revision revision-1)) |
---|
70 | (ii-1-2 (make-instance 'ItemIdentifierC |
---|
71 | :uri "ii-1-2" |
---|
72 | :start-revision revision-1)) |
---|
73 | (ii-2-1 (make-instance 'ItemIdentifierC |
---|
74 | :uri "ii-2-1" |
---|
75 | :start-revision revision-2)) |
---|
76 | (ii-2-2 (make-instance 'ItemIdentifierC |
---|
77 | :uri "ii-2-2" |
---|
78 | :start-revision revision-2)) |
---|
79 | (psi-1-1 (make-instance 'PersistentIdC |
---|
80 | :uri "psi-1-1" |
---|
81 | :start-revision revision-1)) |
---|
82 | (psi-1-2 (make-instance 'PersistentIdC |
---|
83 | :uri "psi-1-2" |
---|
84 | :start-revision revision-1)) |
---|
85 | (locator-2-1 (make-instance 'SubjectLocatorC |
---|
86 | :uri "locator-2-1" |
---|
87 | :start-revision revision-2)) |
---|
88 | (xtm-id-1 "xtm-id-1") |
---|
89 | (xtm-id-2 "xtm-id-2") |
---|
90 | (topic-id-1 "topic-id-1") |
---|
91 | (topic-id-2 "topic-id-1")) ;should no be merged, since the xtm-id differs |
---|
92 | (let ((topic-1 (make-construct 'TopicC |
---|
93 | :item-identifiers (list ii-1-1 ii-1-2) |
---|
94 | :locators nil |
---|
95 | :psis (list psi-1-1 psi-1-2) |
---|
96 | :topicid topic-id-1 |
---|
97 | :xtm-id xtm-id-1 |
---|
98 | :start-revision revision-1)) |
---|
99 | (topic-2 (make-construct 'TopicC |
---|
100 | :item-identifiers (list ii-2-1 ii-2-2) |
---|
101 | :locators (list locator-2-1) |
---|
102 | :psis nil |
---|
103 | :topicid topic-id-2 |
---|
104 | :xtm-id xtm-id-2 |
---|
105 | :start-revision revision-2)) |
---|
106 | (scope-1 (make-construct 'TopicC |
---|
107 | :psis (list (make-instance 'PersistentIdC |
---|
108 | :uri "psi-scope-1" |
---|
109 | :start-revision revision-1)) |
---|
110 | :topicid "scope-1" |
---|
111 | :xtm-id xtm-id-1 |
---|
112 | :start-revision revision-1)) |
---|
113 | (scope-2 (make-construct 'TopicC |
---|
114 | :psis (list (make-instance 'PersistentIdC |
---|
115 | :uri "psi-scope-2" |
---|
116 | :start-revision revision-1)) |
---|
117 | :topicid "scope-2" |
---|
118 | :xtm-id xtm-id-1 |
---|
119 | :start-revision revision-1)) |
---|
120 | (name-type (make-construct 'TopicC |
---|
121 | :psis (list (make-instance 'PersistentIdC |
---|
122 | :uri "psi-name-type" |
---|
123 | :start-revision revision-1)) |
---|
124 | :topicid "name-type" |
---|
125 | :xtm-id xtm-id-1 |
---|
126 | :start-revision revision-1)) |
---|
127 | (assoc-type (make-construct 'TopicC |
---|
128 | :psis (list (make-instance 'PersistentIdC |
---|
129 | :uri "psi-assoc-type" |
---|
130 | :start-revision revision-1)) |
---|
131 | :topicid "assoc-type" |
---|
132 | :xtm-id xtm-id-1 |
---|
133 | :start-revision revision-1)) |
---|
134 | (role-type (make-construct 'TopicC |
---|
135 | :psis (list (make-instance 'PersistentIdC |
---|
136 | :uri "psi-role-type" |
---|
137 | :start-revision revision-1)) |
---|
138 | :topicid "assoc-type" |
---|
139 | :xtm-id xtm-id-1 |
---|
140 | :start-revision revision-1)) |
---|
141 | (occurrence-type (make-construct 'TopicC |
---|
142 | :psis (list (make-instance 'PersistentIdC |
---|
143 | :uri "psi-occurrence-type" |
---|
144 | :start-revision revision-1)) |
---|
145 | :topicid "occurrence-type" |
---|
146 | :xtm-id xtm-id-1 |
---|
147 | :start-revision revision-1))) |
---|
148 | (let ((name-1-1 (make-construct 'NameC |
---|
149 | :item-identifiers nil |
---|
150 | :parent topic-1 |
---|
151 | :themes (list scope-1) |
---|
152 | :instance-of name-type |
---|
153 | :charvalue "name-1-1" |
---|
154 | :start-revision revision-1)) |
---|
155 | (name-2-1 (make-construct 'NameC |
---|
156 | :item-identifiers (list (make-instance 'ItemIdentifierC |
---|
157 | :uri "name-2-1-ii-1" |
---|
158 | :start-revision revision-1)) |
---|
159 | :parent topic-2 |
---|
160 | :themes (list scope-2) |
---|
161 | :instance-of nil |
---|
162 | :charvalue "name-2-1" |
---|
163 | :start-revision revision-2)) |
---|
164 | (occurrence-2-1 (make-construct 'OccurrenceC |
---|
165 | :item-identifiers (list (make-instance 'ItemIdentifierC |
---|
166 | :uri "occurrence-1-1-ii-1" |
---|
167 | :start-revision revision-1)) |
---|
168 | :parent topic-2 |
---|
169 | :themes (list scope-1 scope-2) |
---|
170 | :instance-of occurrence-type |
---|
171 | :charvalue "occurrence-2-1" |
---|
172 | :datatype "datatype" |
---|
173 | :start-revision revision-2)) |
---|
174 | (occurrence-2-2 (make-construct 'OccurrenceC |
---|
175 | :item-identifiers nil |
---|
176 | :parent topic-2 |
---|
177 | :themes nil |
---|
178 | :instance-of occurrence-type |
---|
179 | :charvalue "occurrence-2-2" |
---|
180 | :datatype "datatype" |
---|
181 | :start-revision revision-2)) |
---|
182 | (test-name (make-construct 'NameC |
---|
183 | :item-identifiers nil |
---|
184 | :parent scope-2 |
---|
185 | :themes (list scope-1 topic-2) |
---|
186 | :instance-of topic-2 |
---|
187 | :charvalue "test-name" |
---|
188 | :start-revision revision-2)) |
---|
189 | (assoc (make-construct 'AssociationC |
---|
190 | :item-identifiers nil |
---|
191 | :instance-of assoc-type |
---|
192 | :themes nil |
---|
193 | :roles |
---|
194 | (list |
---|
195 | (list :instance-of role-type |
---|
196 | :player topic-1 |
---|
197 | :start-revision revision-2 |
---|
198 | :item-identifiers |
---|
199 | (list (make-instance 'ItemIdentifierC |
---|
200 | :uri "role-1" |
---|
201 | :start-revision revision-2))) |
---|
202 | (list :instance-of role-type |
---|
203 | :player topic-2 |
---|
204 | :start-revision revision-2 |
---|
205 | :item-identifiers |
---|
206 | (list (make-instance 'ItemIdentifierC |
---|
207 | :uri "role-2" |
---|
208 | :start-revision revision-2)))) |
---|
209 | :start-revision revision-2))) |
---|
210 | (is (= (length (elephant:get-instances-by-class 'TopicC)) 8)) |
---|
211 | (d::merge-constructs topic-1 topic-2 :revision revision-2) |
---|
212 | (is (= (length (elephant:get-instances-by-class 'TopicC)) 7)) |
---|
213 | (is (= (length (union (list ii-1-1 ii-1-2 ii-2-1 ii-2-2) |
---|
214 | (item-identifiers topic-1))) |
---|
215 | (length (list ii-1-1 ii-1-2 ii-2-1 ii-2-2)))) |
---|
216 | (is (= (length (union (list psi-1-1 psi-1-2) |
---|
217 | (psis topic-1))) |
---|
218 | (length (list psi-1-1 psi-1-2)))) |
---|
219 | (is (= (length (union (list locator-2-1) |
---|
220 | (locators topic-1))) |
---|
221 | (length (list locator-2-1)))) |
---|
222 | (is (= (length (union (names topic-1) |
---|
223 | (list name-1-1 name-2-1))) |
---|
224 | (length (list name-1-1 name-2-1)))) |
---|
225 | (is (= (length (union (occurrences topic-1 :revision 0) |
---|
226 | (list occurrence-2-1 occurrence-2-2))) |
---|
227 | (length (list occurrence-2-1 occurrence-2-2)))) |
---|
228 | (is (= (length (union (d:used-as-type topic-1) |
---|
229 | (list test-name))) |
---|
230 | (length (list test-name)))) |
---|
231 | (is (= (length (union (d:used-as-theme topic-1) |
---|
232 | (list test-name))) |
---|
233 | (length (list test-name)))) |
---|
234 | (is (= (length (roles assoc :revision 0)) 1)) |
---|
235 | (is (= (length (d::slot-p assoc 'd::roles)) 2)) |
---|
236 | (is (eql (player (first (roles assoc :revision 0)) :revision 0) topic-1)) |
---|
237 | (elephant:close-store)))))) |
---|
238 | |
---|
239 | |
---|
240 | (test test-xtm1.0-reification |
---|
241 | "Tests the reification in the xtm1.0-importer." |
---|
242 | (let |
---|
243 | ((dir "data_base")) |
---|
244 | (with-fixture initialize-destination-db (dir) |
---|
245 | (xml-importer:import-xtm *reification_xtm1.0.xtm* dir |
---|
246 | :tm-id "http://www.isidor.us/unittests/reification-xtm1.0-tests" |
---|
247 | :xtm-id "reification-xtm" |
---|
248 | :xtm-format '1.0) |
---|
249 | (is (= (length (elephant:get-instances-by-class 'TopicC)) 12)) |
---|
250 | (is (= (length (elephant:get-instances-by-class 'AssociationC)) 1)) |
---|
251 | (let ((homer |
---|
252 | (identified-construct |
---|
253 | (elephant:get-instance-by-value 'PersistentIdC 'uri "http://simpsons.tv/homer"))) |
---|
254 | (married-assoc |
---|
255 | (first (elephant:get-instances-by-class 'AssociationC)))) |
---|
256 | (let ((homer-occurrence (first (occurrences homer))) |
---|
257 | (homer-name (first (names homer))) |
---|
258 | (homer-variant (first (variants (first (names homer))))) |
---|
259 | (husband-role (find-if #'(lambda(x) |
---|
260 | (eql (instance-of x) |
---|
261 | (identified-construct |
---|
262 | (elephant:get-instance-by-value |
---|
263 | 'PersistentIdC 'uri "http://simpsons.tv/husband")))) |
---|
264 | (roles married-assoc))) |
---|
265 | (reifier-occurrence |
---|
266 | (identified-construct (elephant:get-instance-by-value 'PersistentIdC 'uri "#homer-occurrence"))) |
---|
267 | (reifier-name |
---|
268 | (identified-construct (elephant:get-instance-by-value 'PersistentIdC 'uri "#homer-name"))) |
---|
269 | (reifier-variant |
---|
270 | (identified-construct (elephant:get-instance-by-value 'PersistentIdC 'uri "#homer-name-variant"))) |
---|
271 | (reifier-married-assoc |
---|
272 | (identified-construct (elephant:get-instance-by-value 'PersistentIdC 'uri "#a-married"))) |
---|
273 | (reifier-husband-role |
---|
274 | (identified-construct (elephant:get-instance-by-value 'PersistentIdC 'uri "#married-husband-role")))) |
---|
275 | (is-true homer) |
---|
276 | (is-true homer-occurrence) |
---|
277 | (is-true homer-name) |
---|
278 | (is-true homer-variant) |
---|
279 | (is-true married-assoc) |
---|
280 | (is-true husband-role) |
---|
281 | (is-true reifier-occurrence) |
---|
282 | (is-true reifier-name) |
---|
283 | (is-true reifier-variant) |
---|
284 | (is-true reifier-married-assoc) |
---|
285 | (is-true reifier-husband-role) |
---|
286 | (is (eql (reifier homer-occurrence) reifier-occurrence)) |
---|
287 | (is (eql (reified-construct reifier-occurrence) homer-occurrence)) |
---|
288 | (is (eql (reifier homer-name) reifier-name)) |
---|
289 | (is (eql (reified-construct reifier-name) homer-name)) |
---|
290 | (is (eql (reifier homer-variant) reifier-variant)) |
---|
291 | (is (eql (reified-construct reifier-variant) homer-variant)) |
---|
292 | (is (eql (reifier married-assoc) reifier-married-assoc)) |
---|
293 | (is (eql (reified-construct reifier-married-assoc) married-assoc)) |
---|
294 | (is (eql (reifier husband-role) reifier-husband-role)) |
---|
295 | (is (eql (reified-construct reifier-husband-role) husband-role)) |
---|
296 | (is-true (handler-case |
---|
297 | (progn (d::delete-construct homer-occurrence) |
---|
298 | t) |
---|
299 | (condition () nil))) |
---|
300 | (is-false (occurrences homer)) |
---|
301 | (is (= (length (elephant:get-instances-by-class 'd:TopicC)) 12)) |
---|
302 | (elephant:close-store)))))) |
---|
303 | |
---|
304 | |
---|
305 | (test test-xtm2.0-reification |
---|
306 | "Tests the reification in the xtm2.0-importer." |
---|
307 | (let |
---|
308 | ((dir "data_base")) |
---|
309 | (with-fixture initialize-destination-db (dir) |
---|
310 | (xml-importer:import-xtm *reification_xtm2.0.xtm* dir |
---|
311 | :tm-id "http://www.isidor.us/unittests/reification-xtm2.0-tests" |
---|
312 | :xtm-id "reification-xtm") |
---|
313 | (is (= (length (elephant:get-instances-by-class 'TopicC)) 12)) |
---|
314 | (is (= (length (elephant:get-instances-by-class 'AssociationC)) 1)) |
---|
315 | (let ((homer |
---|
316 | (identified-construct |
---|
317 | (elephant:get-instance-by-value 'PersistentIdC 'uri "http://simpsons.tv/homer"))) |
---|
318 | (married-assoc |
---|
319 | (first (elephant:get-instances-by-class 'AssociationC)))) |
---|
320 | (let ((homer-occurrence (first (occurrences homer))) |
---|
321 | (homer-name (first (names homer))) |
---|
322 | (homer-variant (first (variants (first (names homer))))) |
---|
323 | (husband-role (find-if #'(lambda(x) |
---|
324 | (eql (instance-of x) |
---|
325 | (identified-construct |
---|
326 | (elephant:get-instance-by-value |
---|
327 | 'PersistentIdC 'uri "http://simpsons.tv/husband")))) |
---|
328 | (roles married-assoc))) |
---|
329 | (reifier-occurrence |
---|
330 | (identified-construct (elephant:get-instance-by-value 'ItemIdentifierC 'uri "http://simpsons.tv/homer-occurrence"))) |
---|
331 | (reifier-name |
---|
332 | (identified-construct (elephant:get-instance-by-value 'ItemIdentifierC 'uri "http://simpsons.tv/homer-name"))) |
---|
333 | (reifier-variant |
---|
334 | (identified-construct (elephant:get-instance-by-value 'ItemIdentifierC 'uri "http://simpsons.tv/homer-name-variant"))) |
---|
335 | (reifier-married-assoc |
---|
336 | (identified-construct (elephant:get-instance-by-value 'ItemIdentifierC 'uri "http://simpsons.tv/married-association"))) |
---|
337 | (reifier-husband-role |
---|
338 | (identified-construct (elephant:get-instance-by-value 'ItemIdentifierC 'uri "http://simpsons.tv/married-husband-role")))) |
---|
339 | (is-true homer) |
---|
340 | (is-true homer-occurrence) |
---|
341 | (is-true homer-name) |
---|
342 | (is-true homer-variant) |
---|
343 | (is-true married-assoc) |
---|
344 | (is-true husband-role) |
---|
345 | (is-true reifier-occurrence) |
---|
346 | (is-true reifier-name) |
---|
347 | (is-true reifier-variant) |
---|
348 | (is-true reifier-married-assoc) |
---|
349 | (is-true reifier-husband-role) |
---|
350 | (is (eql (reifier homer-occurrence) reifier-occurrence)) |
---|
351 | (is (eql (reified-construct reifier-occurrence) homer-occurrence)) |
---|
352 | (is (eql (reifier homer-name) reifier-name)) |
---|
353 | (is (eql (reified-construct reifier-name) homer-name)) |
---|
354 | (is (eql (reifier homer-variant) reifier-variant)) |
---|
355 | (is (eql (reified-construct reifier-variant) homer-variant)) |
---|
356 | (is (eql (reifier married-assoc) reifier-married-assoc)) |
---|
357 | (is (eql (reified-construct reifier-married-assoc) married-assoc)) |
---|
358 | (is (eql (reifier husband-role) reifier-husband-role)) |
---|
359 | (is (eql (reified-construct reifier-husband-role) husband-role)) |
---|
360 | (is-true (handler-case |
---|
361 | (progn (d::delete-construct homer-occurrence) |
---|
362 | t) |
---|
363 | (condition () nil))) |
---|
364 | (is-false (occurrences homer)) |
---|
365 | (is (= (length (elephant:get-instances-by-class 'd:TopicC)) 12)) |
---|
366 | (elephant:close-store)))))) |
---|
367 | |
---|
368 | |
---|
369 | (test test-xtm1.0-reification-exporter |
---|
370 | "Tests the reification in the xtm1.0-exporter." |
---|
371 | (let |
---|
372 | ((dir "data_base") |
---|
373 | (output-file "__out__.xtm") |
---|
374 | (tm-id "http://www.isidor.us/unittests/reification-xtm1.0-tests")) |
---|
375 | (with-fixture initialize-destination-db (dir) |
---|
376 | (handler-case (delete-file output-file) |
---|
377 | (error () )) ;do nothing |
---|
378 | (xml-importer:import-xtm *reification_xtm1.0.xtm* dir |
---|
379 | :tm-id tm-id |
---|
380 | :xtm-id "reification-xtm" |
---|
381 | :xtm-format '1.0) |
---|
382 | (export-xtm output-file :xtm-format '1.0 :tm-id tm-id) |
---|
383 | (let ((document |
---|
384 | (dom:document-element |
---|
385 | (cxml:parse-file output-file (cxml-dom:make-dom-builder))))) |
---|
386 | (let ((homer-topic |
---|
387 | (loop for topic across (xpath-child-elems-by-qname document *xtm1.0-ns* "topic") |
---|
388 | when (loop for subjectIndicatorRef across (xpath-child-elems-by-qname |
---|
389 | (xpath-single-child-elem-by-qname |
---|
390 | topic *xtm1.0-ns* "subjectIdentity") |
---|
391 | *xtm1.0-ns* "subjectIndicatorRef") |
---|
392 | when (string= (dom:get-attribute-ns subjectIndicatorRef *xtm1.0-xlink* "href") |
---|
393 | "http://simpsons.tv/homer") |
---|
394 | return t) |
---|
395 | return topic)) |
---|
396 | (married-assoc (xpath-single-child-elem-by-qname document *xtm1.0-ns* "association"))) |
---|
397 | (is-true homer-topic) |
---|
398 | (is-true married-assoc) |
---|
399 | (loop for occurrence across (xpath-child-elems-by-qname homer-topic *xtm1.0-ns* "occurrence") |
---|
400 | do (is (string= (dom:get-attribute occurrence "id") "homer-occurrence"))) |
---|
401 | (loop for name across (xpath-child-elems-by-qname homer-topic *xtm1.0-ns* "baseName") |
---|
402 | do (progn (is (string= (dom:get-attribute name "id") "homer-name")) |
---|
403 | (loop for variant across (xpath-child-elems-by-qname name *xtm1.0-ns* "variant") |
---|
404 | do (is (string= (dom:get-attribute variant "id") "homer-name-variant"))))) |
---|
405 | (is (string= (dom:get-attribute married-assoc "id") "a-married")) |
---|
406 | (is-true (loop for role across (xpath-child-elems-by-qname married-assoc *xtm1.0-ns* "member") |
---|
407 | when (string= (dom:get-attribute role "id") |
---|
408 | "married-husband-role") |
---|
409 | return t))) |
---|
410 | (is-true (loop for topic across (xpath-child-elems-by-qname document *xtm1.0-ns* "topic") |
---|
411 | when (loop for subjectIndicatorRef across (xpath-child-elems-by-qname |
---|
412 | (xpath-single-child-elem-by-qname |
---|
413 | topic *xtm1.0-ns* "subjectIdentity") |
---|
414 | *xtm1.0-ns* "subjectIndicatorRef") |
---|
415 | when (string= (dom:get-attribute-ns subjectIndicatorRef *xtm1.0-xlink* "href") |
---|
416 | "#homer-occurrence") |
---|
417 | return t) |
---|
418 | return t)) |
---|
419 | (is-true (loop for topic across (xpath-child-elems-by-qname document *xtm1.0-ns* "topic") |
---|
420 | when (loop for subjectIndicatorRef across (xpath-child-elems-by-qname |
---|
421 | (xpath-single-child-elem-by-qname |
---|
422 | topic *xtm1.0-ns* "subjectIdentity") |
---|
423 | *xtm1.0-ns* "subjectIndicatorRef") |
---|
424 | when (string= (dom:get-attribute-ns subjectIndicatorRef *xtm1.0-xlink* "href") |
---|
425 | "#homer-name") |
---|
426 | return t) |
---|
427 | return t)) |
---|
428 | (is-true (loop for topic across (xpath-child-elems-by-qname document *xtm1.0-ns* "topic") |
---|
429 | when (loop for subjectIndicatorRef across (xpath-child-elems-by-qname |
---|
430 | (xpath-single-child-elem-by-qname |
---|
431 | topic *xtm1.0-ns* "subjectIdentity") |
---|
432 | *xtm1.0-ns* "subjectIndicatorRef") |
---|
433 | when (string= (dom:get-attribute-ns subjectIndicatorRef *xtm1.0-xlink* "href") |
---|
434 | "#homer-name-variant") |
---|
435 | return t) |
---|
436 | return t)) |
---|
437 | (is-true (loop for topic across (xpath-child-elems-by-qname document *xtm1.0-ns* "topic") |
---|
438 | when (loop for subjectIndicatorRef across (xpath-child-elems-by-qname |
---|
439 | (xpath-single-child-elem-by-qname |
---|
440 | topic *xtm1.0-ns* "subjectIdentity") |
---|
441 | *xtm1.0-ns* "subjectIndicatorRef") |
---|
442 | when (string= (dom:get-attribute-ns subjectIndicatorRef *xtm1.0-xlink* "href") |
---|
443 | "#a-married") |
---|
444 | return t) |
---|
445 | return t)) |
---|
446 | (is-true (loop for topic across (xpath-child-elems-by-qname document *xtm1.0-ns* "topic") |
---|
447 | when (loop for subjectIndicatorRef across (xpath-child-elems-by-qname |
---|
448 | (xpath-single-child-elem-by-qname |
---|
449 | topic *xtm1.0-ns* "subjectIdentity") |
---|
450 | *xtm1.0-ns* "subjectIndicatorRef") |
---|
451 | when (string= (dom:get-attribute-ns subjectIndicatorRef *xtm1.0-xlink* "href") |
---|
452 | "#married-husband-role") |
---|
453 | return t) |
---|
454 | return t))) |
---|
455 | (handler-case (delete-file output-file) |
---|
456 | (error () )) ;do nothing |
---|
457 | (elephant:close-store)))) |
---|
458 | |
---|
459 | |
---|
460 | (test test-xtm2.0-reification-exporter |
---|
461 | "Tests the reification in the xtm2.0-exporter." |
---|
462 | (let |
---|
463 | ((dir "data_base") |
---|
464 | (output-file "__out__.xtm") |
---|
465 | (tm-id "http://www.isidor.us/unittests/reification-xtm2.0-tests")) |
---|
466 | (with-fixture initialize-destination-db (dir) |
---|
467 | (handler-case (delete-file output-file) |
---|
468 | (error () )) ;do nothing |
---|
469 | (xml-importer:import-xtm *reification_xtm2.0.xtm* dir |
---|
470 | :tm-id tm-id |
---|
471 | :xtm-id "reification-xtm") |
---|
472 | (export-xtm output-file :tm-id tm-id) |
---|
473 | (let ((document |
---|
474 | (dom:document-element |
---|
475 | (cxml:parse-file output-file (cxml-dom:make-dom-builder))))) |
---|
476 | (let ((homer-topic |
---|
477 | (loop for topic across (xpath-child-elems-by-qname document *xtm2.0-ns* "topic") |
---|
478 | when (loop for psi across (xpath-child-elems-by-qname topic *xtm2.0-ns* "subjectIdentifier") |
---|
479 | when (string= (dom:get-attribute psi "href") "http://simpsons.tv/homer") |
---|
480 | return t) |
---|
481 | return topic)) |
---|
482 | (married-assoc (xpath-single-child-elem-by-qname document *xtm2.0-ns* "association"))) |
---|
483 | (is-true homer-topic) |
---|
484 | (is-true married-assoc) |
---|
485 | (loop for occurrence across (xpath-child-elems-by-qname homer-topic *xtm2.0-ns* "occurrence") |
---|
486 | do (is (string= (dom:get-attribute occurrence "reifier") "http://simpsons.tv/homer-occurrence"))) |
---|
487 | (loop for name across (xpath-child-elems-by-qname homer-topic *xtm2.0-ns* "name") |
---|
488 | do (is (string= (dom:get-attribute name "reifier") "http://simpsons.tv/homer-name"))) |
---|
489 | (loop for name across (xpath-child-elems-by-qname homer-topic *xtm2.0-ns* "name") |
---|
490 | do (loop for variant across (xpath-child-elems-by-qname name *xtm2.0-ns* "variant") |
---|
491 | do (is (string= (dom:get-attribute variant "reifier") "http://simpsons.tv/homer-name-variant")))) |
---|
492 | (is (string= (dom:get-attribute married-assoc "reifier") "http://simpsons.tv/married-association")) |
---|
493 | (is-true (loop for role across (xpath-child-elems-by-qname married-assoc *xtm2.0-ns* "role") |
---|
494 | when (string= (dom:get-attribute role "reifier") "http://simpsons.tv/married-husband-role") |
---|
495 | return t)) |
---|
496 | (is-true (loop for topic across (xpath-child-elems-by-qname document *xtm2.0-ns* "topic") |
---|
497 | when (loop for ii across (xpath-child-elems-by-qname topic *xtm2.0-ns* "itemIdentity") |
---|
498 | when (string= (dom:get-attribute ii "href") "http://simpsons.tv/homer-occurrence") |
---|
499 | return t) |
---|
500 | return t)) |
---|
501 | (is-true (loop for topic across (xpath-child-elems-by-qname document *xtm2.0-ns* "topic") |
---|
502 | when (loop for ii across (xpath-child-elems-by-qname topic *xtm2.0-ns* "itemIdentity") |
---|
503 | when (string= (dom:get-attribute ii "href") "http://simpsons.tv/homer-name") |
---|
504 | return t) |
---|
505 | return t)) |
---|
506 | (is-true (loop for topic across (xpath-child-elems-by-qname document *xtm2.0-ns* "topic") |
---|
507 | when (loop for ii across (xpath-child-elems-by-qname topic *xtm2.0-ns* "itemIdentity") |
---|
508 | when (string= (dom:get-attribute ii "href") "http://simpsons.tv/homer-name-variant") |
---|
509 | return t) |
---|
510 | return t)) |
---|
511 | (is-true (loop for topic across (xpath-child-elems-by-qname document *xtm2.0-ns* "topic") |
---|
512 | when (loop for ii across (xpath-child-elems-by-qname topic *xtm2.0-ns* "itemIdentity") |
---|
513 | when (string= (dom:get-attribute ii "href") "http://simpsons.tv/married-association") |
---|
514 | return t) |
---|
515 | return t)) |
---|
516 | (is-true (loop for topic across (xpath-child-elems-by-qname document *xtm2.0-ns* "topic") |
---|
517 | when (loop for ii across (xpath-child-elems-by-qname topic *xtm2.0-ns* "itemIdentity") |
---|
518 | when (string= (dom:get-attribute ii "href") "http://simpsons.tv/married-husband-role") |
---|
519 | return t) |
---|
520 | return t))))) |
---|
521 | (handler-case (delete-file output-file) |
---|
522 | (error () )) ;do nothing |
---|
523 | (elephant:close-store))) |
---|
524 | |
---|
525 | |
---|
526 | (test test-rdf-importer-reification |
---|
527 | "Tests the function import-node non-recursively. Especially the reification |
---|
528 | of association- and occurrence-arcs." |
---|
529 | (let ((db-dir "data_base") |
---|
530 | (tm-id "http://test-tm/") |
---|
531 | (revision-1 100) |
---|
532 | (document-id "doc-id") |
---|
533 | (doc-1 |
---|
534 | (concatenate 'string "<rdf:RDF xmlns:rdf=\"" *rdf-ns* "\" " |
---|
535 | "xmlns:arcs=\"http://test/arcs/\" " |
---|
536 | "xmlns:rdfs=\"" *rdfs-ns* "\">" |
---|
537 | "<rdf:Description rdf:about=\"first-node\">" |
---|
538 | "<arcs:arc1 rdf:ID=\"reification-1\">" |
---|
539 | "<rdf:Description rdf:about=\"second-node\" />" |
---|
540 | "</arcs:arc1>" |
---|
541 | "</rdf:Description>" |
---|
542 | "<rdf:Description rdf:ID=\"#reification-1\">" |
---|
543 | "<arcs:arc2 rdf:resource=\"third-node\"/>" |
---|
544 | "</rdf:Description>" |
---|
545 | "<rdf:Description rdf:nodeID=\"fourth-node\">" |
---|
546 | "<arcs:arc3 rdf:ID=\"reification-2\" rdf:datatype=\"dt\">" |
---|
547 | "occurrence data" |
---|
548 | "</arcs:arc3>" |
---|
549 | "</rdf:Description>" |
---|
550 | "<rdf:Description rdf:ID=\"#reification-2\">" |
---|
551 | "<arcs:arc4 rdf:resource=\"fifth-node\" />" |
---|
552 | "</rdf:Description>" |
---|
553 | "</rdf:RDF>"))) |
---|
554 | (clean-out-db db-dir) |
---|
555 | (let ((dom-1 (cxml:parse doc-1 (cxml-dom:make-dom-builder)))) |
---|
556 | (is-true dom-1) |
---|
557 | (is (= (length (dom:child-nodes dom-1)) 1)) |
---|
558 | (let ((rdf-node (elt (dom:child-nodes dom-1) 0))) |
---|
559 | (is (= (length (dom:child-nodes rdf-node)) 4)) |
---|
560 | (rdf-init-db :db-dir db-dir :start-revision revision-1) |
---|
561 | (dotimes (iter (length (dom:child-nodes rdf-node))) |
---|
562 | (rdf-importer::import-node (elt (dom:child-nodes rdf-node) iter) |
---|
563 | tm-id revision-1 |
---|
564 | :document-id document-id)) |
---|
565 | (is (= (length (dom:child-nodes rdf-node)) 4)) |
---|
566 | (rdf-init-db :db-dir db-dir :start-revision revision-1) |
---|
567 | (dotimes (iter (length (dom:child-nodes rdf-node))) |
---|
568 | (rdf-importer::import-node (elt (dom:child-nodes rdf-node) iter) |
---|
569 | tm-id revision-1 |
---|
570 | :document-id document-id)) |
---|
571 | (let ((reification-1 (d:get-item-by-id "http://test-tm#reification-1" |
---|
572 | :xtm-id document-id)) |
---|
573 | (reification-2 (d:get-item-by-id "http://test-tm#reification-2" |
---|
574 | :xtm-id document-id)) |
---|
575 | (first-node (d:get-item-by-id "http://test-tm/first-node" |
---|
576 | :xtm-id document-id)) |
---|
577 | (second-node (d:get-item-by-id "http://test-tm/second-node" |
---|
578 | :xtm-id document-id)) |
---|
579 | (third-node (d:get-item-by-id "http://test-tm/third-node" |
---|
580 | :xtm-id document-id)) |
---|
581 | (fourth-node (d:get-item-by-id "fourth-node" |
---|
582 | :xtm-id document-id)) |
---|
583 | (fifth-node (d:get-item-by-id "http://test-tm/fifth-node" |
---|
584 | :xtm-id document-id)) |
---|
585 | (arc1 (d:get-item-by-id "http://test/arcs/arc1" |
---|
586 | :xtm-id document-id)) |
---|
587 | (arc2 (d:get-item-by-id "http://test/arcs/arc2" |
---|
588 | :xtm-id document-id)) |
---|
589 | (arc3 (d:get-item-by-id "http://test/arcs/arc3" |
---|
590 | :xtm-id document-id)) |
---|
591 | (arc4 (d:get-item-by-id "http://test/arcs/arc4" |
---|
592 | :xtm-id document-id))) |
---|
593 | (is (= (length (d:psis reification-1)) 1)) |
---|
594 | (is (string= (d:uri (first (d:psis reification-1))) |
---|
595 | "http://test-tm#reification-1")) |
---|
596 | (is (= (length (d:psis reification-2)) 1)) |
---|
597 | (is (string= (d:uri (first (d:psis reification-2))) |
---|
598 | "http://test-tm#reification-2")) |
---|
599 | (is (= (length (d:psis first-node)) 1)) |
---|
600 | (is (string= (d:uri (first (d:psis first-node))) |
---|
601 | "http://test-tm/first-node")) |
---|
602 | (is (= (length (d:psis second-node)) 1)) |
---|
603 | (is (string= (d:uri (first (d:psis second-node))) |
---|
604 | "http://test-tm/second-node")) |
---|
605 | (is (= (length (d:psis third-node)) 1)) |
---|
606 | (is (string= (d:uri (first (d:psis third-node))) |
---|
607 | "http://test-tm/third-node")) |
---|
608 | (is (= (length (d:psis fourth-node)) 0)) |
---|
609 | (is (= (length (d:psis fifth-node)) 1)) |
---|
610 | (is (string= (d:uri (first (d:psis fifth-node))) |
---|
611 | "http://test-tm/fifth-node")) |
---|
612 | (is (= (length (d:psis arc1)) 1)) |
---|
613 | (is (string= (d:uri (first (d:psis arc1))) |
---|
614 | "http://test/arcs/arc1")) |
---|
615 | (is (= (length (d:psis arc2)))) |
---|
616 | (is (string= (d:uri (first (d:psis arc2))) |
---|
617 | "http://test/arcs/arc2")) |
---|
618 | (is (= (length (d:psis arc3)))) |
---|
619 | (is (string= (d:uri (first (d:psis arc3))) |
---|
620 | "http://test/arcs/arc3")) |
---|
621 | (is (= (length (d:psis arc4)))) |
---|
622 | (is (string= (d:uri (first (d:psis arc4))) |
---|
623 | "http://test/arcs/arc4")) |
---|
624 | (is (= (length (d:used-as-type arc1)) 1)) |
---|
625 | (is (eql (reifier (first (d:used-as-type arc1))) reification-1)) |
---|
626 | (is (eql (reified-construct reification-1) (first (d:used-as-type arc1)))) |
---|
627 | (is (eql (reifier (first (d:used-as-type arc3))) reification-2)) |
---|
628 | (is (eql (reified-construct reification-2) (first (d:used-as-type arc3)))))))) |
---|
629 | (elephant:close-store)) |
---|
630 | |
---|
631 | |
---|
632 | (test test-rdf-importer-reification-2 |
---|
633 | "Tests the rdf-importer, especially some reification cases of |
---|
634 | the tm2rdf mapping." |
---|
635 | (let ((db-dir "data_base") |
---|
636 | (tm-id "http://test-tm/") |
---|
637 | (revision-1 100) |
---|
638 | (document-id "doc-id")) |
---|
639 | (clean-out-db db-dir) |
---|
640 | (rdf-importer:rdf-importer |
---|
641 | *reification.rdf* db-dir :tm-id tm-id |
---|
642 | :document-id document-id :start-revision revision-1) |
---|
643 | (elephant:open-store (xml-importer:get-store-spec db-dir)) |
---|
644 | (let ((homer (get-item-by-id "http://simpsons.tv/homer" :xtm-id document-id)) |
---|
645 | (bart (get-item-by-id "http://simpsons.tv/bart" :xtm-id document-id)) |
---|
646 | (married (get-item-by-id "http://simpsons.tv/arcs/married" :xtm-id document-id))) |
---|
647 | (is-true homer) |
---|
648 | (is-true bart) |
---|
649 | (is-true married) |
---|
650 | (is (= (length (used-as-type married)) 1)) |
---|
651 | (is-true (reifier (first (used-as-type married)))) |
---|
652 | (is-true (reified-construct (reifier (first (used-as-type married))))) |
---|
653 | (is (= (length (psis (reifier (first (used-as-type married))))) 1)) |
---|
654 | (is (string= (uri (first (psis (reifier (first (used-as-type married)))))) |
---|
655 | "http://test-tm#married-arc")) |
---|
656 | (is (= (length (occurrences bart)) 1)) |
---|
657 | (is-true (reifier (first (occurrences bart)))) |
---|
658 | (is-true (reified-construct (reifier (first (occurrences bart))))) |
---|
659 | (is (string= (uri (first (psis (reifier (first (occurrences bart)))))) |
---|
660 | "http://test-tm#lastName-arc")))) |
---|
661 | (elephant:close-store)) |
---|
662 | |
---|
663 | |
---|
664 | (test test-rdf-importer-reification-3 |
---|
665 | "Tests the rdf-importer, especially some reification cases of |
---|
666 | the tm2rdf mapping." |
---|
667 | (let ((db-dir "data_base") |
---|
668 | (tm-id "http://test-tm/") |
---|
669 | (revision-1 100) |
---|
670 | (document-id "doc-id")) |
---|
671 | (clean-out-db db-dir) |
---|
672 | (rdf-importer:rdf-importer |
---|
673 | *reification.rdf* db-dir :tm-id tm-id |
---|
674 | :document-id document-id :start-revision revision-1) |
---|
675 | (elephant:open-store (xml-importer:get-store-spec db-dir)) |
---|
676 | (let ((lisa (get-item-by-id "http://simpsons.tv/lisa" :xtm-id document-id))) |
---|
677 | (is-true lisa) |
---|
678 | (is (= (length (names lisa)) 1)) |
---|
679 | (is (= (length (occurrences lisa)) 1)) |
---|
680 | (let ((name (first (names lisa))) |
---|
681 | (occurrence (first (occurrences lisa)))) |
---|
682 | (is (= (length (variants name)) 1)) |
---|
683 | (let ((variant (first (variants name)))) |
---|
684 | (is-true (reifier name)) |
---|
685 | (is-true (reified-construct (reifier name))) |
---|
686 | (is (= (length (psis (reifier name))) 1)) |
---|
687 | (is (string= (uri (first (psis (reifier name)))) |
---|
688 | (concatenate 'string tm-id "lisa-name"))) |
---|
689 | (is-true (reifier variant)) |
---|
690 | (is-true (reified-construct (reifier variant))) |
---|
691 | (is (= (length (psis (reifier variant))) 1)) |
---|
692 | (is (string= (uri (first (psis (reifier variant)))) |
---|
693 | (concatenate 'string tm-id "lisa-name-variant"))) |
---|
694 | (is-true (reifier occurrence)) |
---|
695 | (is-true (reified-construct (reifier occurrence))) |
---|
696 | (is (= (length (psis (reifier occurrence))) 1)) |
---|
697 | (is (string= (uri (first (psis (reifier occurrence)))) |
---|
698 | (concatenate 'string tm-id "lisa-occurrence"))))))) |
---|
699 | (elephant:close-store)) |
---|
700 | |
---|
701 | |
---|
702 | (test test-rdf-importer-reification-4 |
---|
703 | "Tests the rdf-importer, especially some reification cases of |
---|
704 | the tm2rdf mapping." |
---|
705 | (let ((db-dir "data_base") |
---|
706 | (tm-id "http://test-tm/") |
---|
707 | (revision-1 100) |
---|
708 | (document-id "doc-id")) |
---|
709 | (clean-out-db db-dir) |
---|
710 | (rdf-importer:rdf-importer |
---|
711 | *reification.rdf* db-dir :tm-id tm-id |
---|
712 | :document-id document-id :start-revision revision-1) |
---|
713 | (elephant:open-store (xml-importer:get-store-spec db-dir)) |
---|
714 | (let ((friendship (get-item-by-id "http://simpsons.tv/friendship" :xtm-id document-id)) |
---|
715 | (carl (get-item-by-id "http://simpsons.tv/carl" :xtm-id document-id))) |
---|
716 | (is-true friendship) |
---|
717 | (is-true carl) |
---|
718 | (is (= (length (used-as-type friendship)) 1)) |
---|
719 | (is (typep (first (used-as-type friendship)) 'd:AssociationC)) |
---|
720 | (let ((friendship-association (first (used-as-type friendship)))) |
---|
721 | (is-true (reifier friendship-association)) |
---|
722 | (is-true (reified-construct (reifier friendship-association))) |
---|
723 | (is (= (length (psis (reifier friendship-association))) 1)) |
---|
724 | (is (string= (uri (first (psis (reifier friendship-association)))) |
---|
725 | (concatenate 'string tm-id "friendship-association"))) |
---|
726 | (is (= (length (roles friendship-association)) 2)) |
---|
727 | (let ((carl-role |
---|
728 | (find-if #'(lambda(role) |
---|
729 | (eql (player role) carl)) |
---|
730 | (roles friendship-association)))) |
---|
731 | (is-true carl-role) |
---|
732 | (is-true (reifier carl-role)) |
---|
733 | (is-true (reified-construct (reifier carl-role))) |
---|
734 | (is (= (length (psis (reifier carl-role))) 1)) |
---|
735 | (is (string= (uri (first (psis (reifier carl-role)))) |
---|
736 | (concatenate 'string tm-id "friend-role"))))))) |
---|
737 | (elephant:close-store)) |
---|
738 | |
---|
739 | |
---|
740 | (test test-rdf-exporter-reification |
---|
741 | "Tests the reification in the rdf-exporter." |
---|
742 | (let |
---|
743 | ((dir "data_base") |
---|
744 | (output-file "__out__.rdf") |
---|
745 | (tm-id "http://simpsons.tv")) |
---|
746 | (handler-case (delete-file output-file) |
---|
747 | (error () )) ;do nothing |
---|
748 | (clean-out-db dir) |
---|
749 | (rdf-importer:rdf-importer *reification.rdf* dir |
---|
750 | :tm-id tm-id |
---|
751 | :document-id "reification-xtm") |
---|
752 | (elephant:open-store (xml-importer:get-store-spec dir)) |
---|
753 | (rdf-exporter:export-rdf output-file :tm-id tm-id) |
---|
754 | (let ((document |
---|
755 | (dom:document-element |
---|
756 | (cxml:parse-file output-file (cxml-dom:make-dom-builder))))) |
---|
757 | (let ((married-arc |
---|
758 | (loop for reifier-node across (xpath-child-elems-by-qname document *rdf-ns* "Description") |
---|
759 | when (let ((about (dom:get-attribute-ns reifier-node *rdf-ns* "about"))) |
---|
760 | (and (stringp about) (string= about "#married-arc"))) |
---|
761 | return reifier-node)) |
---|
762 | (lastName-arc |
---|
763 | (loop for reifier-node across (xpath-child-elems-by-qname document *rdf-ns* "Description") |
---|
764 | when (let ((about (dom:get-attribute-ns reifier-node *rdf-ns* "about"))) |
---|
765 | (and (stringp about) (string= about "#lastName-arc"))) |
---|
766 | return reifier-node)) |
---|
767 | (lisa-name |
---|
768 | (loop for reifier-node across (xpath-child-elems-by-qname document *rdf-ns* "Description") |
---|
769 | when (let ((about (dom:get-attribute-ns reifier-node *rdf-ns* "about"))) |
---|
770 | (and (stringp about) (string= about "#lisa-name"))) |
---|
771 | return reifier-node)) |
---|
772 | (lisa-name-variant |
---|
773 | (loop for reifier-node across (xpath-child-elems-by-qname document *rdf-ns* "Description") |
---|
774 | when (let ((about (dom:get-attribute-ns reifier-node *rdf-ns* "about"))) |
---|
775 | (and (stringp about) (string= about "#lisa-name-variant"))) |
---|
776 | return reifier-node)) |
---|
777 | (lisa-occurrence |
---|
778 | (loop for reifier-node across (xpath-child-elems-by-qname document *rdf-ns* "Description") |
---|
779 | when (let ((about (dom:get-attribute-ns reifier-node *rdf-ns* "about"))) |
---|
780 | (and (stringp about) (string= about "#lisa-occurrence"))) |
---|
781 | return reifier-node)) |
---|
782 | (friendship-association |
---|
783 | (loop for reifier-node across (xpath-child-elems-by-qname document *rdf-ns* "Description") |
---|
784 | when (let ((about (dom:get-attribute-ns reifier-node *rdf-ns* "about"))) |
---|
785 | (and (stringp about) (string= about "#friendship-association"))) |
---|
786 | return reifier-node)) |
---|
787 | (friend-role |
---|
788 | (loop for reifier-node across (xpath-child-elems-by-qname document *rdf-ns* "Description") |
---|
789 | when (let ((about (dom:get-attribute-ns reifier-node *rdf-ns* "about"))) |
---|
790 | (and (stringp about) (string= about "#friend-role"))) |
---|
791 | return reifier-node))) |
---|
792 | (is-true married-arc) |
---|
793 | (is-true lastName-arc) |
---|
794 | (is-true lisa-name) |
---|
795 | (is-true lisa-name-variant) |
---|
796 | (is-true lisa-occurrence) |
---|
797 | (is-true friendship-association) |
---|
798 | (is-true friend-role) |
---|
799 | (dolist (reifier-node (list married-arc lastName-arc lisa-name |
---|
800 | lisa-name-variant lisa-occurrence |
---|
801 | friendship-association friend-role)) |
---|
802 | (let ((author-arc |
---|
803 | (xpath-single-child-elem-by-qname reifier-node "http://simpsons.tv/arcs/" "author"))) |
---|
804 | (is-true author-arc) |
---|
805 | (let ((resource (dom:get-attribute-ns author-arc *rdf-ns* "resource"))) |
---|
806 | (is (and (stringp resource) (string= resource "http://some.where/me")))))))) |
---|
807 | (handler-case (delete-file output-file) |
---|
808 | (error () ))) ;do nothing |
---|
809 | (elephant:close-store)) |
---|
810 | |
---|
811 | |
---|
812 | (test test-rdf-exporter-reification-2 |
---|
813 | "Tests the reification in the rdf-exporter." |
---|
814 | (let |
---|
815 | ((dir "data_base") |
---|
816 | (output-file "__out__.rdf") |
---|
817 | (tm-id "http://simpsons.tv")) |
---|
818 | (handler-case (delete-file output-file) |
---|
819 | (error () )) ;do nothing |
---|
820 | (clean-out-db dir) |
---|
821 | (rdf-importer:rdf-importer *reification.rdf* dir |
---|
822 | :tm-id tm-id |
---|
823 | :document-id "reification-xtm") |
---|
824 | (elephant:open-store (xml-importer:get-store-spec dir)) |
---|
825 | (rdf-exporter:export-rdf output-file :tm-id tm-id) |
---|
826 | (let ((document |
---|
827 | (dom:document-element |
---|
828 | (cxml:parse-file output-file (cxml-dom:make-dom-builder))))) |
---|
829 | (let ((lisa |
---|
830 | (loop for resource across (xpath-child-elems-by-qname document *rdf-ns* "Description") |
---|
831 | when (let ((about (dom:get-attribute-ns resource *rdf-ns* "about"))) |
---|
832 | (and (stringp about) (string= about "http://simpsons.tv/lisa"))) |
---|
833 | return resource))) |
---|
834 | (is-true lisa) |
---|
835 | (let ((lisa-name |
---|
836 | (let ((arc |
---|
837 | (xpath-single-child-elem-by-qname lisa "http://isidorus/tm2rdf_mapping/" "name"))) |
---|
838 | (when arc |
---|
839 | (xpath-single-child-elem-by-qname arc *rdf-ns* "Description")))) |
---|
840 | (lisa-occurrence |
---|
841 | (xpath-single-child-elem-by-qname lisa "http://simpsons.tv/" "profession"))) |
---|
842 | (is-true lisa-name) |
---|
843 | (is-true lisa-occurrence) |
---|
844 | (let ((lisa-name-variant |
---|
845 | (let ((arc |
---|
846 | (xpath-single-child-elem-by-qname lisa-name "http://isidorus/tm2rdf_mapping/" "variant"))) |
---|
847 | (when arc |
---|
848 | (xpath-single-child-elem-by-qname arc *rdf-ns* "Description"))))) |
---|
849 | (is-true lisa-name-variant) |
---|
850 | (let ((name-reifier |
---|
851 | (let ((elem |
---|
852 | (xpath-single-child-elem-by-qname |
---|
853 | lisa-name "http://isidorus/tm2rdf_mapping/" "reifier"))) |
---|
854 | (when elem |
---|
855 | (dom:get-attribute-ns elem *rdf-ns* "resource")))) |
---|
856 | (variant-reifier |
---|
857 | (let ((elem |
---|
858 | (xpath-single-child-elem-by-qname |
---|
859 | lisa-name-variant "http://isidorus/tm2rdf_mapping/" "reifier"))) |
---|
860 | (when elem |
---|
861 | (dom:get-attribute-ns elem *rdf-ns* "resource")))) |
---|
862 | (occurrence-reifier (dom:get-attribute-ns lisa-occurrence *rdf-ns* "ID"))) |
---|
863 | (is (and (stringp name-reifier) |
---|
864 | (string= name-reifier "lisa-name"))) |
---|
865 | (is (and (stringp variant-reifier) |
---|
866 | (string= variant-reifier "lisa-name-variant"))) |
---|
867 | (is (and (stringp occurrence-reifier) |
---|
868 | (string= occurrence-reifier "lisa-occurrence")))))))) |
---|
869 | (handler-case (delete-file output-file) |
---|
870 | (error () ))) ;do nothing |
---|
871 | (elephant:close-store)) |
---|
872 | |
---|
873 | |
---|
874 | (test test-rdf-exporter-reification-3 |
---|
875 | "Tests the reification in the rdf-exporter." |
---|
876 | (let |
---|
877 | ((dir "data_base") |
---|
878 | (output-file "__out__.rdf") |
---|
879 | (tm-id "http://simpsons.tv")) |
---|
880 | (handler-case (delete-file output-file) |
---|
881 | (error () )) ;do nothing |
---|
882 | (clean-out-db dir) |
---|
883 | (rdf-importer:rdf-importer *reification.rdf* dir |
---|
884 | :tm-id tm-id |
---|
885 | :document-id "reification-xtm") |
---|
886 | (elephant:open-store (xml-importer:get-store-spec dir)) |
---|
887 | (rdf-exporter:export-rdf output-file :tm-id tm-id) |
---|
888 | (let ((document |
---|
889 | (dom:document-element |
---|
890 | (cxml:parse-file output-file (cxml-dom:make-dom-builder))))) |
---|
891 | (let ((homer |
---|
892 | (loop for resource across (xpath-child-elems-by-qname document *rdf-ns* "Description") |
---|
893 | when (let ((about (dom:get-attribute-ns resource *rdf-ns* "about"))) |
---|
894 | (and (stringp about) (string= about "http://simpsons.tv/homer"))) |
---|
895 | return resource))) |
---|
896 | (is-true homer) |
---|
897 | (let ((married-arc |
---|
898 | (xpath-single-child-elem-by-qname homer "http://simpsons.tv/arcs/" "married"))) |
---|
899 | (is-true married-arc) |
---|
900 | (let ((reifier-id (dom:get-attribute-ns married-arc *rdf-ns* "ID"))) |
---|
901 | (is (and (stringp reifier-id) |
---|
902 | (string= reifier-id "married-arc"))))))) |
---|
903 | (handler-case (delete-file output-file) |
---|
904 | (error () ))) ;do nothing |
---|
905 | (elephant:close-store)) |
---|
906 | |
---|
907 | |
---|
908 | (test test-rdf-exporter-reification-4 |
---|
909 | "Tests the reification in the rdf-exporter." |
---|
910 | (let |
---|
911 | ((dir "data_base") |
---|
912 | (output-file "__out__.rdf") |
---|
913 | (tm-id "http://simpsons.tv")) |
---|
914 | (handler-case (delete-file output-file) |
---|
915 | (error () )) ;do nothing |
---|
916 | (clean-out-db dir) |
---|
917 | (rdf-importer:rdf-importer *reification.rdf* dir |
---|
918 | :tm-id tm-id |
---|
919 | :document-id "reification-xtm") |
---|
920 | (elephant:open-store (xml-importer:get-store-spec dir)) |
---|
921 | (rdf-exporter:export-rdf output-file :tm-id tm-id) |
---|
922 | (let ((document |
---|
923 | (dom:document-element |
---|
924 | (cxml:parse-file output-file (cxml-dom:make-dom-builder))))) |
---|
925 | (let ((association |
---|
926 | (loop for resource across (xpath-child-elems-by-qname document *rdf-ns* "Description") |
---|
927 | when (let ((type (xpath-single-child-elem-by-qname resource *rdf-ns* "type"))) |
---|
928 | (when type |
---|
929 | (let ((type-uri |
---|
930 | (dom:get-attribute-ns type *rdf-ns* "resource"))) |
---|
931 | (and (stringp type-uri) |
---|
932 | (string= type-uri "http://isidorus/tm2rdf_mapping/types/Association"))))) |
---|
933 | return resource))) |
---|
934 | (is-true association) |
---|
935 | (let ((role |
---|
936 | (loop for resource across |
---|
937 | (xpath-child-elems-by-qname association "http://isidorus/tm2rdf_mapping/" "role") |
---|
938 | when (let ((description (xpath-single-child-elem-by-qname resource *rdf-ns* "Description"))) |
---|
939 | (when description |
---|
940 | (xpath-single-child-elem-by-qname |
---|
941 | description "http://isidorus/tm2rdf_mapping/" "reifier"))) |
---|
942 | return (xpath-single-child-elem-by-qname resource *rdf-ns* "Description")))) |
---|
943 | (is-true role) |
---|
944 | (let ((association-reifier |
---|
945 | (let ((elem (xpath-single-child-elem-by-qname |
---|
946 | association "http://isidorus/tm2rdf_mapping/" "reifier"))) |
---|
947 | (when elem |
---|
948 | (dom:get-attribute-ns elem *rdf-ns* "resource")))) |
---|
949 | (role-reifier |
---|
950 | (let ((elem (xpath-single-child-elem-by-qname |
---|
951 | role "http://isidorus/tm2rdf_mapping/" "reifier"))) |
---|
952 | (when elem |
---|
953 | (dom:get-attribute-ns elem *rdf-ns* "resource"))))) |
---|
954 | (is-true association-reifier) |
---|
955 | (is-true role-reifier) |
---|
956 | (is (and (stringp association-reifier) |
---|
957 | (string= association-reifier "friendship-association"))) |
---|
958 | (is (and (stringp role-reifier) |
---|
959 | (string= role-reifier "friend-role"))))))) |
---|
960 | (handler-case (delete-file output-file) |
---|
961 | (error () ))) ;do nothing |
---|
962 | (elephant:close-store)) |
---|
963 | |
---|
964 | |
---|
965 | (test test-fragment-reification |
---|
966 | "Tests the reification in the rdf-exporter." |
---|
967 | (let |
---|
968 | ((dir "data_base") |
---|
969 | (output-file "__out__.rdf") |
---|
970 | (tm-id "http://simpsons.tv")) |
---|
971 | (handler-case (delete-file output-file) |
---|
972 | (error () )) ;do nothing |
---|
973 | (clean-out-db dir) |
---|
974 | (rdf-importer:rdf-importer *reification.rdf* dir |
---|
975 | :tm-id tm-id |
---|
976 | :document-id "reification-xtm") |
---|
977 | (elephant:open-store (xml-importer:get-store-spec dir)) |
---|
978 | (let ((fragment (d:create-latest-fragment-of-topic "http://simpsons.tv/lisa"))) |
---|
979 | (is-true fragment) |
---|
980 | (is (= (length (union (referenced-topics fragment) |
---|
981 | (list (d:get-item-by-psi "http://simpsons.tv/lastName") |
---|
982 | (d:get-item-by-psi "http://simpsons.tv/sortName") |
---|
983 | (d:get-item-by-psi "http://simpsons.tv/profession") |
---|
984 | (d:get-item-by-psi "http://simpsons.tv/lisa-name") |
---|
985 | (d:get-item-by-psi "http://simpsons.tv/lisa-name-variant") |
---|
986 | (d:get-item-by-psi "http://simpsons.tv/lisa-occurrence")))) |
---|
987 | 6))) |
---|
988 | (let ((fragment (d:create-latest-fragment-of-topic "http://simpsons.tv/carl"))) |
---|
989 | (is-true fragment) |
---|
990 | (is (= (length (union (referenced-topics fragment) |
---|
991 | (list (d:get-item-by-psi "http://simpsons.tv/friendship") |
---|
992 | (d:get-item-by-psi "http://simpsons.tv/friendship-association") |
---|
993 | (d:get-item-by-psi "http://simpsons.tv/friend") |
---|
994 | (d:get-item-by-psi "http://simpsons.tv/lenny") |
---|
995 | (d:get-item-by-psi "http://simpsons.tv/friend-role")))) |
---|
996 | 5)))) |
---|
997 | (elephant:close-store)) |
---|
998 | |
---|
999 | |
---|
1000 | (defun run-reification-tests () |
---|
1001 | (it.bese.fiveam:run! 'test-merge-reifier-topics) |
---|
1002 | (it.bese.fiveam:run! 'test-xtm1.0-reification) |
---|
1003 | (it.bese.fiveam:run! 'test-xtm2.0-reification) |
---|
1004 | (it.bese.fiveam:run! 'test-xtm1.0-reification-exporter) |
---|
1005 | (it.bese.fiveam:run! 'test-xtm2.0-reification-exporter) |
---|
1006 | (it.bese.fiveam:run! 'test-rdf-importer-reification) |
---|
1007 | (it.bese.fiveam:run! 'test-rdf-importer-reification-2) |
---|
1008 | (it.bese.fiveam:run! 'test-rdf-importer-reification-3) |
---|
1009 | (it.bese.fiveam:run! 'test-rdf-importer-reification-4) |
---|
1010 | (it.bese.fiveam:run! 'test-rdf-exporter-reification) |
---|
1011 | (it.bese.fiveam:run! 'test-rdf-exporter-reification-2) |
---|
1012 | (it.bese.fiveam:run! 'test-rdf-exporter-reification-3) |
---|
1013 | (it.bese.fiveam:run! 'test-rdf-exporter-reification-4) |
---|
1014 | (it.bese.fiveam:run! 'test-fragment-reification)) |
---|