Author: lgiessmann Date: Thu Nov 26 05:40:44 2009 New Revision: 154
Log: changed the reification handling in the rdf-importer, so all reifiable-constructs are reified by other resources by the reifier-slot --> added some unit-tests
Modified: trunk/src/unit_tests/rdf_importer_test.lisp trunk/src/unit_tests/reification_test.lisp trunk/src/xml/rdf/importer.lisp
Modified: trunk/src/unit_tests/rdf_importer_test.lisp ============================================================================== --- trunk/src/unit_tests/rdf_importer_test.lisp (original) +++ trunk/src/unit_tests/rdf_importer_test.lisp Thu Nov 26 05:40:44 2009 @@ -58,7 +58,6 @@ :test-get-associations-of-node-content :test-parse-properties-of-node :test-import-node-1 - :test-import-node-reification :test-import-dom :test-poems-rdf-occurrences :test-poems-rdf-associations @@ -1218,236 +1217,6 @@ (is-false (d:psis (d:player object-role)))))))))))) (elephant:close-store))
- -(test test-import-node-reification - "Tests the function import-node non-recursively. Especially the reification - of association- and occurrence-arcs." - (let ((db-dir "data_base") - (tm-id "http://test-tm/") - (revision-1 100) - (document-id "doc-id") - (doc-1 - (concatenate 'string "<rdf:RDF xmlns:rdf="" *rdf-ns* "" " - "xmlns:arcs="http://test/arcs/%5C" " - "xmlns:rdfs="" *rdfs-ns* "">" - "<rdf:Description rdf:about="first-node">" - "<arcs:arc1 rdf:ID="reification-1">" - "<rdf:Description rdf:about="second-node" />" - "</arcs:arc1>" - "</rdf:Description>" - "<rdf:Description rdf:ID="#reification-1">" - "<arcs:arc2 rdf:resource="third-node"/>" - "</rdf:Description>" - "<rdf:Description rdf:nodeID="fourth-node">" - "<arcs:arc3 rdf:ID="reification-2" rdf:datatype="dt">" - "occurrence data" - "</arcs:arc3>" - "</rdf:Description>" - "<rdf:Description rdf:ID="#reification-2">" - "<arcs:arc4 rdf:resource="fifth-node" />" - "</rdf:Description>" - "</rdf:RDF>"))) - (let ((dom-1 (cxml:parse doc-1 (cxml-dom:make-dom-builder)))) - (is-true dom-1) - (is (= (length (dom:child-nodes dom-1)) 1)) - (let ((rdf-node (elt (dom:child-nodes dom-1) 0))) - (is (= (length (dom:child-nodes rdf-node)) 4)) - (rdf-init-db :db-dir db-dir :start-revision revision-1) - (dotimes (iter (length (dom:child-nodes rdf-node))) - (rdf-importer::import-node (elt (dom:child-nodes rdf-node) iter) - tm-id revision-1 - :document-id document-id)) - (let ((reification-1 (d:get-item-by-id "http://test-tm#reification-1" - :xtm-id document-id)) - (reification-2 (d:get-item-by-id "http://test-tm#reification-2" - :xtm-id document-id)) - (first-node (d:get-item-by-id "http://test-tm/first-node" - :xtm-id document-id)) - (second-node (d:get-item-by-id "http://test-tm/second-node" - :xtm-id document-id)) - (third-node (d:get-item-by-id "http://test-tm/third-node" - :xtm-id document-id)) - (fourth-node (d:get-item-by-id "fourth-node" - :xtm-id document-id)) - (fifth-node (d:get-item-by-id "http://test-tm/fifth-node" - :xtm-id document-id)) - (arc1 (d:get-item-by-id "http://test/arcs/arc1" - :xtm-id document-id)) - (arc2 (d:get-item-by-id "http://test/arcs/arc2" - :xtm-id document-id)) - (arc3 (d:get-item-by-id "http://test/arcs/arc3" - :xtm-id document-id)) - (arc4 (d:get-item-by-id "http://test/arcs/arc4" - :xtm-id document-id)) - (statement (d:get-item-by-psi *rdf-statement*)) - (object (d:get-item-by-psi *rdf-object*)) - (subject (d:get-item-by-psi *rdf-subject*)) - (predicate (d:get-item-by-psi *rdf-predicate*)) - (type (d:get-item-by-psi *type-psi*)) - (instance (d:get-item-by-psi *instance-psi*)) - (type-instance (d:get-item-by-psi *type-instance-psi*)) - (isi-subject (d:get-item-by-psi *rdf2tm-subject*)) - (isi-object (d:get-item-by-psi *rdf2tm-object*))) - (is (= (length (d:psis reification-1)) 1)) - (is (string= (d:uri (first (d:psis reification-1))) - "http://test-tm#reification-1")) - (is (= (length (d:psis reification-2)) 1)) - (is (string= (d:uri (first (d:psis reification-2))) - "http://test-tm#reification-2")) - (is (= (length (d:psis first-node)) 1)) - (is (string= (d:uri (first (d:psis first-node))) - "http://test-tm/first-node")) - (is (= (length (d:psis second-node)) 1)) - (is (string= (d:uri (first (d:psis second-node))) - "http://test-tm/second-node")) - (is (= (length (d:psis third-node)) 1)) - (is (string= (d:uri (first (d:psis third-node))) - "http://test-tm/third-node")) - (is (= (length (d:psis fourth-node)) 0)) - (is (= (length (d:psis fifth-node)) 1)) - (is (string= (d:uri (first (d:psis fifth-node))) - "http://test-tm/fifth-node")) - (is (= (length (d:psis arc1)) 1)) - (is (string= (d:uri (first (d:psis arc1))) - "http://test/arcs/arc1")) - (is (= (length (d:psis arc2)))) - (is (string= (d:uri (first (d:psis arc2))) - "http://test/arcs/arc2")) - (is (= (length (d:psis arc3)))) - (is (string= (d:uri (first (d:psis arc3))) - "http://test/arcs/arc3")) - (is (= (length (d:psis arc4)))) - (is (string= (d:uri (first (d:psis arc4))) - "http://test/arcs/arc4")) - (is-true statement) - (is-true object) - (is-true subject) - (is-true predicate) - (is-true type) - (is-true instance) - (is-true type-instance) - (is (= (length (d:player-in-roles first-node)) 2)) - (is-true (find-if #'(lambda(x) - (and (eql (d:instance-of x) isi-subject) - (eql (d:instance-of (d:parent x)) arc1))) - (d:player-in-roles first-node))) - (is-true (find-if #'(lambda(x) - (and (eql (d:instance-of x) isi-object) - (eql (d:instance-of (d:parent x)) - subject))) - (d:player-in-roles first-node))) - (is (= (length (d:player-in-roles second-node)) 2)) - (is-true (find-if #'(lambda(x) - (and (eql (d:instance-of x) isi-object) - (eql (d:instance-of (d:parent x)) arc1))) - (d:player-in-roles second-node))) - (is-true (find-if #'(lambda(x) - (and (eql (d:instance-of x) isi-object) - (eql (d:instance-of (d:parent x)) - object))) - (d:player-in-roles second-node))) - (is (= (length (d:player-in-roles statement)) 2)) - (is-true (find-if #'(lambda(x) - (and (eql (d:instance-of x) type) - (eql (d:instance-of (d:parent x)) - type-instance))) - (d:player-in-roles statement))) - (is (= (length (d:player-in-roles arc1)) 1)) - (is-true (find-if #'(lambda(x) - (and (eql (d:instance-of x) isi-object) - (eql (d:instance-of (d:parent x)) - predicate))) - (d:player-in-roles arc1))) - (is (= (length (d:player-in-roles third-node)) 1)) - (is-true (find-if #'(lambda(x) - (and (eql (d:instance-of x) isi-object) - (eql (d:instance-of (d:parent x)) - arc2))) - (d:player-in-roles third-node))) - (is (= (length (d:player-in-roles reification-1)) 5)) - (is-true (find-if #'(lambda(x) - (and (eql (d:instance-of x) isi-subject) - (eql (d:instance-of (d:parent x)) - subject))) - (d:player-in-roles reification-1))) - (is-true (find-if #'(lambda(x) - (and (eql (d:instance-of x) isi-subject) - (eql (d:instance-of (d:parent x)) - object))) - (d:player-in-roles reification-1))) - (is-true (find-if #'(lambda(x) - (and (eql (d:instance-of x) instance) - (eql (d:instance-of (d:parent x)) - type-instance))) - (d:player-in-roles reification-1))) - (is-true (find-if #'(lambda(x) - (and (eql (d:instance-of x) isi-subject) - (eql (d:instance-of (d:parent x)) - object))) - (d:player-in-roles reification-1))) - (is-true (find-if #'(lambda(x) - (and (eql (d:instance-of x) isi-subject) - (eql (d:instance-of (d:parent x)) - predicate))) - (d:player-in-roles reification-1))) - (is-true (find-if #'(lambda(x) - (and (eql (d:instance-of x) isi-subject) - (eql (d:instance-of (d:parent x)) - arc2))) - (d:player-in-roles reification-1))) - (is (= (length (d:occurrences fourth-node)) 1)) - (is (string= (d:charvalue (first (d:occurrences fourth-node))) - "occurrence data")) - (is (string= (d:datatype (first (d:occurrences fourth-node))) - "http://test-tm/dt")) - (is (eql (d:instance-of (first (d:occurrences fourth-node))) - arc3)) - (is (= (length (d:player-in-roles fourth-node)) 1)) - (is-true (find-if #'(lambda(x) - (and (eql (d:instance-of x) isi-object) - (eql (d:instance-of (d:parent x)) - subject))) - (d:player-in-roles fourth-node))) - (is (= (length (d:player-in-roles arc3)) 1)) - (is-true (find-if #'(lambda(x) - (and (eql (d:instance-of x) isi-object) - (eql (d:instance-of (d:parent x)) - predicate))) - (d:player-in-roles arc3))) - (is (= (length (d:player-in-roles fifth-node)) 1)) - (is-true (find-if #'(lambda(x) - (and (eql (d:instance-of x) isi-object) - (eql (d:instance-of (d:parent x)) - arc4))) - (d:player-in-roles fifth-node))) - (is (= (length (d:occurrences reification-2)) 1)) - (is (string= (d:charvalue (first (d:occurrences reification-2))) - "occurrence data")) - (is (string= (d:datatype (first (d:occurrences reification-2))) - "http://test-tm/dt")) - (is (= (length (d:player-in-roles reification-2)) 4)) - (is-true (find-if #'(lambda(x) - (and (eql (d:instance-of x) isi-subject) - (eql (d:instance-of (d:parent x)) - subject))) - (d:player-in-roles reification-2))) - (is-true (find-if #'(lambda(x) - (and (eql (d:instance-of x) isi-subject) - (eql (d:instance-of (d:parent x)) - predicate))) - (d:player-in-roles reification-2))) - (is-true (find-if #'(lambda(x) - (and (eql (d:instance-of x) isi-subject) - (eql (d:instance-of (d:parent x)) - arc4))) - (d:player-in-roles reification-2))) - (is-true (find-if #'(lambda(x) - (and (eql (d:instance-of x) instance) - (eql (d:instance-of (d:parent x)) - type-instance))) - (d:player-in-roles reification-2))) - (elephant:close-store)))))) -
(test test-import-dom "Tests the function import-node when used recursively." @@ -3385,7 +3154,6 @@ (it.bese.fiveam:run! 'test-get-associations-of-node-content) (it.bese.fiveam:run! 'test-parse-properties-of-node) (it.bese.fiveam:run! 'test-import-node-1) - (it.bese.fiveam:run! 'test-import-node-reification) (it.bese.fiveam:run! 'test-import-dom) (it.bese.fiveam:run! 'test-poems-rdf-occurrences) (it.bese.fiveam:run! 'test-poems-rdf-associations)
Modified: trunk/src/unit_tests/reification_test.lisp ============================================================================== --- trunk/src/unit_tests/reification_test.lisp (original) +++ trunk/src/unit_tests/reification_test.lisp Thu Nov 26 05:40:44 2009 @@ -18,7 +18,14 @@ (:import-from :constants *xtm2.0-ns* *xtm1.0-ns* - *xtm1.0-xlink*) + *xtm1.0-xlink* + *rdf-ns* + *rdfs-ns* + *type-psi* + *instance-psi* + *type-instance-psi* + *rdf2tm-subject* + *rdf2tm-object*) (:import-from :xml-tools xpath-child-elems-by-qname xpath-single-child-elem-by-qname xpath-fn-string) @@ -29,7 +36,8 @@ :test-xtm1.0-reification :test-xtm2.0-reification :test-xtm1.0-reification-exporter - :test-xtm2.0-reification-exporter)) + :test-xtm2.0-reification-exporter + :test-rdf-importer-reification))
(in-package :reification-test) @@ -448,6 +456,7 @@ (error () )) ;do nothing (elephant:close-store))))
+ (test test-xtm2.0-reification-exporter "Tests the reification in the xtm2.0-exporter." (let @@ -510,12 +519,119 @@ return t) return t))))) (elephant:close-store))) - + + +(test test-rdf-importer-reification + "Tests the function import-node non-recursively. Especially the reification + of association- and occurrence-arcs." + (let ((db-dir "data_base") + (tm-id "http://test-tm/") + (revision-1 100) + (document-id "doc-id") + (doc-1 + (concatenate 'string "<rdf:RDF xmlns:rdf="" *rdf-ns* "" " + "xmlns:arcs="http://test/arcs/%5C" " + "xmlns:rdfs="" *rdfs-ns* "">" + "<rdf:Description rdf:about="first-node">" + "<arcs:arc1 rdf:ID="reification-1">" + "<rdf:Description rdf:about="second-node" />" + "</arcs:arc1>" + "</rdf:Description>" + "<rdf:Description rdf:ID="#reification-1">" + "<arcs:arc2 rdf:resource="third-node"/>" + "</rdf:Description>" + "<rdf:Description rdf:nodeID="fourth-node">" + "<arcs:arc3 rdf:ID="reification-2" rdf:datatype="dt">" + "occurrence data" + "</arcs:arc3>" + "</rdf:Description>" + "<rdf:Description rdf:ID="#reification-2">" + "<arcs:arc4 rdf:resource="fifth-node" />" + "</rdf:Description>" + "</rdf:RDF>"))) + (let ((dom-1 (cxml:parse doc-1 (cxml-dom:make-dom-builder)))) + (is-true dom-1) + (is (= (length (dom:child-nodes dom-1)) 1)) + (let ((rdf-node (elt (dom:child-nodes dom-1) 0))) + (is (= (length (dom:child-nodes rdf-node)) 4)) + (rdf-init-db :db-dir db-dir :start-revision revision-1) + (dotimes (iter (length (dom:child-nodes rdf-node))) + (rdf-importer::import-node (elt (dom:child-nodes rdf-node) iter) + tm-id revision-1 + :document-id document-id)) + (is (= (length (dom:child-nodes rdf-node)) 4)) + (rdf-init-db :db-dir db-dir :start-revision revision-1) + (dotimes (iter (length (dom:child-nodes rdf-node))) + (rdf-importer::import-node (elt (dom:child-nodes rdf-node) iter) + tm-id revision-1 + :document-id document-id)) + (let ((reification-1 (d:get-item-by-id "http://test-tm#reification-1" + :xtm-id document-id)) + (reification-2 (d:get-item-by-id "http://test-tm#reification-2" + :xtm-id document-id)) + (first-node (d:get-item-by-id "http://test-tm/first-node" + :xtm-id document-id)) + (second-node (d:get-item-by-id "http://test-tm/second-node" + :xtm-id document-id)) + (third-node (d:get-item-by-id "http://test-tm/third-node" + :xtm-id document-id)) + (fourth-node (d:get-item-by-id "fourth-node" + :xtm-id document-id)) + (fifth-node (d:get-item-by-id "http://test-tm/fifth-node" + :xtm-id document-id)) + (arc1 (d:get-item-by-id "http://test/arcs/arc1" + :xtm-id document-id)) + (arc2 (d:get-item-by-id "http://test/arcs/arc2" + :xtm-id document-id)) + (arc3 (d:get-item-by-id "http://test/arcs/arc3" + :xtm-id document-id)) + (arc4 (d:get-item-by-id "http://test/arcs/arc4" + :xtm-id document-id))) + (is (= (length (d:psis reification-1)) 1)) + (is (string= (d:uri (first (d:psis reification-1))) + "http://test-tm#reification-1")) + (is (= (length (d:psis reification-2)) 1)) + (is (string= (d:uri (first (d:psis reification-2))) + "http://test-tm#reification-2")) + (is (= (length (d:psis first-node)) 1)) + (is (string= (d:uri (first (d:psis first-node))) + "http://test-tm/first-node")) + (is (= (length (d:psis second-node)) 1)) + (is (string= (d:uri (first (d:psis second-node))) + "http://test-tm/second-node")) + (is (= (length (d:psis third-node)) 1)) + (is (string= (d:uri (first (d:psis third-node))) + "http://test-tm/third-node")) + (is (= (length (d:psis fourth-node)) 0)) + (is (= (length (d:psis fifth-node)) 1)) + (is (string= (d:uri (first (d:psis fifth-node))) + "http://test-tm/fifth-node")) + (is (= (length (d:psis arc1)) 1)) + (is (string= (d:uri (first (d:psis arc1))) + "http://test/arcs/arc1")) + (is (= (length (d:psis arc2)))) + (is (string= (d:uri (first (d:psis arc2))) + "http://test/arcs/arc2")) + (is (= (length (d:psis arc3)))) + (is (string= (d:uri (first (d:psis arc3))) + "http://test/arcs/arc3")) + (is (= (length (d:psis arc4)))) + (is (string= (d:uri (first (d:psis arc4))) + "http://test/arcs/arc4")) + (is (= (length (d:used-as-type arc1)) 1)) + (is (eql (reifier (first (d:used-as-type arc1))) reification-1)) + (is (eql (reified reification-1) (first (d:used-as-type arc1)))) + (is (eql (reifier (first (d:used-as-type arc3))) reification-2)) + (is (eql (reified reification-2) (first (d:used-as-type arc3)))))))) + (elephant:close-store)) +
;;TODO: check rdf importer -;;TODO: check fragment exporter +;;TODO: check rdf exporter +;;TODO: check rdf-tm-reification-mapping ;;TODO: check merge-reifier-topics (--> versioning) +;;TODO: check fragment exporter ;;TODO: extend the fragment-importer in the RESTful-interface
@@ -524,4 +640,5 @@ (it.bese.fiveam:run! 'test-xtm1.0-reification) (it.bese.fiveam:run! 'test-xtm2.0-reification) (it.bese.fiveam:run! 'test-xtm1.0-reification-exporter) - (it.bese.fiveam:run! 'test-xtm2.0-reification-exporter)) \ No newline at end of file + (it.bese.fiveam:run! 'test-xtm2.0-reification-exporter) + (it.bese.fiveam:run! 'test-rdf-importer-reification)) \ No newline at end of file
Modified: trunk/src/xml/rdf/importer.lisp ============================================================================== --- trunk/src/xml/rdf/importer.lisp (original) +++ trunk/src/xml/rdf/importer.lisp Thu Nov 26 05:40:44 2009 @@ -354,10 +354,10 @@ :player super-top) (list :instance-of role-type-2 :player sub-top)))) - (when reifier-id - (make-reification reifier-id sub-top super-top - assoc-type start-revision tm - :document-id document-id)) + ;(when reifier-id + ;(make-reification reifier-id sub-top super-top + ; assoc-type start-revision tm + ; :document-id document-id)) (let ((assoc (add-to-topicmap tm @@ -365,6 +365,9 @@ :start-revision start-revision :instance-of assoc-type :roles a-roles)))) + (when reifier-id + (make-reification reifier-id assoc start-revision tm + :document-id document-id)) (format t "a") assoc)))))
@@ -396,10 +399,10 @@ :player type-top) (list :instance-of roletype-2 :player instance-top)))) - (when reifier-id - (make-reification reifier-id instance-top type-top - assoc-type start-revision tm - :document-id document-id)) + ;(when reifier-id + ; (make-reification reifier-id instance-top type-top + ; assoc-type start-revision tm + ; :document-id document-id)) (let ((assoc (add-to-topicmap tm @@ -407,6 +410,9 @@ :start-revision start-revision :instance-of assoc-type :roles a-roles)))) + (when reifier-id + (make-reification reifier-id assoc start-revision tm + :document-id document-id)) (format t "a") assoc)))))
@@ -503,14 +509,17 @@ :player player-1) (list :instance-of role-type-2 :player top)))) - (when ID - (make-reification ID top player-1 type-top start-revision - tm :document-id document-id)) + ;(when ID + ; (make-reification ID top player-1 type-top start-revision + ; tm :document-id document-id)) (let ((assoc (add-to-topicmap tm (make-construct 'AssociationC :start-revision start-revision :instance-of type-top :roles roles)))) + (when ID + (make-reification ID assoc start-revision tm + :document-id document-id)) (format t "a") assoc))))))
@@ -542,43 +551,52 @@ assoc)))))
-(defun make-reification (reifier-id subject object predicate start-revision tm - &key document-id) - "Creates a reification construct." + +(defun make-reification(reifier-id reifiable-construct start-revision tm &key (document-id *document-id*)) (declare (string reifier-id)) - (declare ((or OccurrenceC TopicC) object)) - (declare (TopicC subject predicate)) + (declare (ReifiableConstructC reifiable-construct)) (declare (TopicMapC tm)) - (elephant:ensure-transaction (:txn-nosync t) - (let ((reifier (make-topic-stub reifier-id nil nil nil start-revision tm - :document-id document-id)) - (predicate-arc (make-topic-stub *rdf-predicate* nil nil nil - start-revision - tm :document-id document-id)) - (object-arc (make-topic-stub *rdf-object* nil nil nil start-revision - tm :document-id document-id)) - (subject-arc (make-topic-stub *rdf-subject* nil nil nil - start-revision - tm :document-id document-id)) - (statement (make-topic-stub *rdf-statement* nil nil nil start-revision - tm :document-id document-id))) - (make-instance-of-association reifier statement nil start-revision tm - :document-id document-id) - (make-association-with-nodes reifier subject subject-arc tm - start-revision :document-id document-id) - (make-association-with-nodes reifier predicate predicate-arc - tm start-revision :document-id document-id) - (if (typep object 'd:TopicC) - (make-association-with-nodes reifier object object-arc - tm start-revision - :document-id document-id) - (make-construct 'd:OccurrenceC - :start-revision start-revision - :topic reifier - :themes (themes object) - :instance-of (instance-of object) - :charvalue (charvalue object) - :datatype (datatype object)))))) + (let ((reifier-topic (make-topic-stub reifier-id nil nil nil start-revision tm + :document-id document-id))) + (add-reifier reifiable-construct reifier-topic))) + +;(defun make-reification (reifier-id subject object predicate start-revision tm +; &key document-id) +; "Creates a reification construct." +; (declare (string reifier-id)) +; (declare ((or OccurrenceC TopicC) object)) +; (declare (TopicC subject predicate)) +; (declare (TopicMapC tm)) +; (elephant:ensure-transaction (:txn-nosync t) +; (let ((reifier (make-topic-stub reifier-id nil nil nil start-revision tm +; :document-id document-id)) +; (predicate-arc (make-topic-stub *rdf-predicate* nil nil nil +; start-revision +; tm :document-id document-id)) +; (object-arc (make-topic-stub *rdf-object* nil nil nil start-revision +; tm :document-id document-id)) +; (subject-arc (make-topic-stub *rdf-subject* nil nil nil +; start-revision +; tm :document-id document-id)) +; (statement (make-topic-stub *rdf-statement* nil nil nil start-revision +; tm :document-id document-id))) +; (make-instance-of-association reifier statement nil start-revision tm +; :document-id document-id) +; (make-association-with-nodes reifier subject subject-arc tm +; start-revision :document-id document-id) +; (make-association-with-nodes reifier predicate predicate-arc +; tm start-revision :document-id document-id) +; (if (typep object 'd:TopicC) +; (make-association-with-nodes reifier object object-arc +; tm start-revision +; :document-id document-id) +; (make-construct 'd:OccurrenceC +; :start-revision start-revision +; :topic reifier +; :themes (themes object) +; :instance-of (instance-of object) +; :charvalue (charvalue object) +; :datatype (datatype object))))))
(defun make-occurrence (top literal start-revision tm-id @@ -610,8 +628,10 @@ :charvalue value :datatype datatype))) (when ID - (make-reification ID top occurrence type-top start-revision - xml-importer::tm :document-id document-id)) + ;(make-reification ID top occurrence type-top start-revision + ; xml-importer::tm :document-id document-id)) + (make-reification ID occurrence start-revision xml-importer::tm + :document-id document-id)) occurrence))))))