Changeset 99 for trunk/src/xml/rdf
- Timestamp:
- 07/30/09 14:25:23 (16 years ago)
- Location:
- trunk/src/xml/rdf
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
TabularUnified trunk/src/xml/rdf/importer.lisp ¶
r98 r99 22 22 &key 23 23 (tm-id nil) 24 (document-id (get-uuid))) 24 (document-id (get-uuid)) 25 (revision (get-revision))) 25 26 (setf *document-id* document-id) 26 27 (tm-id-p tm-id "rdf-importer") … … 32 33 (elephant:open-store 33 34 (get-store-spec repository-path))) 34 (import-dom rdf-dom :tm-id tm-id :document-id document-id)))35 36 37 38 (defun import-dom (rdf-dom &key (tm-id nil) (document-id *document-id*))35 (import-dom rdf-dom revision :tm-id tm-id :document-id document-id)) 36 (setf *_n-map* nil)) 37 38 39 (defun import-dom (rdf-dom revision &key (tm-id nil) (document-id *document-id*)) 39 40 (tm-id-p tm-id "import-dom") 40 41 (let ((xml-base (get-xml-base rdf-dom)) … … 48 49 (when children 49 50 (loop for child across children 50 do (import-node child tm-id :document-id document-id51 do (import-node child tm-id revision :document-id document-id 51 52 :xml-base xml-base :xml-lang xml-lang)))) 52 (import-node rdf-dom tm-id :document-id document-id53 (import-node rdf-dom tm-id revision :document-id document-id 53 54 :xml-base xml-base :xml-lang xml-lang)))) 54 55 55 56 56 (defun import-node (elem tm-id &key (document-id *document-id*)57 (defun import-node (elem tm-id revision &key (document-id *document-id*) 57 58 (xml-base nil) (xml-lang nil)) 58 (declare (ignorable document-id)) ;TODO: remove59 59 (tm-id-p tm-id "import-node") 60 60 (parse-node elem) 61 61 (let ((fn-xml-base (get-xml-base elem :old-base xml-base))) 62 (when (child-nodes-or-text elem) 63 (loop for property across (child-nodes-or-text elem) 64 do (parse-property property))) 62 (parse-properties-of-node elem) 65 63 (let ((about (get-absolute-attribute elem tm-id xml-base "about")) 66 64 (nodeID (get-ns-attribute elem "nodeID")) … … 75 73 (get-types-of-node-content elem tm-id fn-xml-base))) 76 74 (super-classes (get-super-classes-of-node-content elem tm-id xml-base))) 77 ;TODO: create elephant-objects 78 ;TODO: recursion on all nodes/arcs 79 (declare (ignorable about nodeID ID UUID literals associations ;TODO: remove 80 types super-classes))))) 75 76 ;TODO: 77 ;get-topic by topic id 78 ;make psis 79 ;if no ones exist create one with topic id 80 ;add psis 81 ;make nametype topic with topic id 82 ;make instance-of associations 83 ;make topictype topics with topic id 84 ;make super-sub-class assoications 85 ;make and add names 86 ;make occurrencetype topics with topic id 87 ;make and add occurrences 88 ;make referenced topic with topic id 89 ;make and add associations 90 91 92 ;TODO: start recursion ... 93 (remove-node-properties-from-*_n-map* elem) 94 (or tm-id document-id revision about nodeID ID UUID literals ;TODO: remove 95 associations types super-classes)))) 81 96 82 97 … … 127 142 :datatype datatype))))))) 128 143 literals))) 129 130 131 (defun get-type-of-node-name (node)132 "Returns the type of the node name (namespace + tagname)."133 (let ((node-name (get-node-name node))134 (node-ns (dom:namespace-uri node)))135 (concatenate-uri node-ns node-name)))136 144 137 145 -
TabularUnified trunk/src/xml/rdf/rdf_tools.lisp ¶
r98 r99 38 38 push-string 39 39 node-to-string) 40 (:import-from :datamodel 41 get-revision) 40 42 (:import-from :xml-importer 41 43 get-uuid … … 60 62 "member" "seeAlso" "isDefinedBy")) 61 63 62 (defun _n-p (node-name) 64 (defvar *_n-map* nil) 65 66 67 (defun _n-p (node) 63 68 "Returns t if the given value is of the form _[0-9]+" 64 (when (and node-name 65 (> (length node-name) 0) 66 (eql (elt node-name 0) #\_)) 67 (let ((rest 68 (subseq node-name 1 (length node-name)))) 69 (declare (string node-name)) 70 (handler-case (let ((int 71 (parse-integer rest))) 72 int) 73 (condition () nil))))) 69 (let ((node-name (get-node-name node))) 70 (when (and node-name 71 (> (length node-name) 0) 72 (eql (elt node-name 0) #\_)) 73 (let ((rest 74 (subseq node-name 1 (length node-name)))) 75 (declare (string node-name)) 76 (handler-case (let ((int 77 (parse-integer rest))) 78 int) 79 (condition () nil)))))) 80 81 82 (defun set-_n-name (property _n-counter) 83 "Returns a name of the form <rdf>_[1-9][0-9]* and adds a tupple 84 of the form :elem <dom-elem> :type<<rdf>_[1-9][0-9]*> to the 85 list *_n-map*. 86 If the dom-elem is already contained in the list only the 87 <rdf>_[1-9][0-9]* name is returned." 88 (let ((map-item (find-if #'(lambda(x) 89 (eql (getf x :elem) property)) 90 *_n-map*))) 91 (if map-item 92 (getf map-item :type) 93 (let ((new-type-name 94 (concatenate 'string *rdf-ns* "_" (write-to-string _n-counter)))) 95 (push (list :elem property 96 :type new-type-name) 97 *_n-map*) 98 new-type-name)))) 99 100 101 (defun unset-_n-name (property) 102 (setf *_n-map* (remove-if 103 #'(lambda(x) 104 (eql (getf x :elem) property)) 105 *_n-map*))) 106 107 108 (defun remove-node-properties-from-*_n-map* (node) 109 "Removes all node's properties from the list *_n-map*." 110 (declare (dom:element node)) 111 (let ((properties (child-nodes-or-text node))) 112 (when properties 113 (loop for property across properties 114 do (unset-_n-name property))))) 115 116 117 (defun get-type-of-node-name (node) 118 "Returns the type of the node name (namespace + tagname). 119 When the node is contained in *_n-map* the corresponding 120 value of this map will be returned." 121 (let ((map-item (find-if #'(lambda(x) 122 (eql (getf x :elem) node)) 123 *_n-map*))) 124 (if map-item 125 (getf map-item :type) 126 (let ((node-name (get-node-name node)) 127 (node-ns (dom:namespace-uri node))) 128 (concatenate-uri node-ns node-name))))) 74 129 75 130 … … 170 225 171 226 172 (defun parse-property-name (property )227 (defun parse-property-name (property _n-counter) 173 228 "Parses the given property's name to the known rdf/rdfs nodes and arcs. 174 229 If the given name es equal to an node an error is thrown otherwise … … 194 249 (unless (find property-name *rdfs-properties* :test #'string=) 195 250 (format t "~aWarning: rdfs:~a is not a known rdfs:type!~%" 196 err-pref property-name)))) 251 err-pref property-name))) 252 (when (and (string= property-ns *rdf-ns*) 253 (string= property-name "li")) 254 (set-_n-name property _n-counter))) 197 255 t) 198 256 199 257 200 (defun parse-property (property )258 (defun parse-property (property _n-counter) 201 259 "Parses a property that represents a rdf-arc." 202 260 (declare (dom:element property)) … … 213 271 (literals (get-literals-of-property property nil)) 214 272 (content (child-nodes-or-text property :trim t))) 215 (parse-property-name property )273 (parse-property-name property _n-counter) 216 274 (when (and parseType 217 275 (or nodeID resource datatype type literals)) … … 303 361 304 362 363 (defun parse-properties-of-node (node) 364 (let ((child-nodes (child-nodes-or-text node)) 365 (_n-counter 0)) 366 (when child-nodes 367 (loop for property across child-nodes 368 do (let ((prop-name (get-node-name property)) 369 (prop-ns (dom:namespace-uri node))) 370 (when (and (string= prop-name "li") 371 (string= prop-ns *rdf-ns*)) 372 (incf _n-counter)) 373 (parse-property property _n-counter))))) 374 t) 375 376 305 377 (defun get-absolute-attribute (elem tm-id xml-base attr-name 306 378 &key (ns-uri *rdf-ns*))
Note: See TracChangeset
for help on using the changeset viewer.