Changeset 101
- Timestamp:
- 07/31/09 22:41:02 (16 years ago)
- Location:
- trunk/src
- Files:
-
- 1 added
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
TabularUnified trunk/src/constants.lisp ¶
r96 r101 1 1 2 ;;+----------------------------------------------------------------------------- 2 3 ;;+ Isidorus … … 27 28 :*xmlns-ns* 28 29 :*xml-string* 29 :*rdf2tm-ns*)) 30 :*rdf2tm-ns* 31 :*rdf-statement* 32 :*rdf-object* 33 :*rdf-subject* 34 :*rdf-predicate* 35 :*rdf2tm-object* 36 :*rdf2tm-subject*)) 30 37 31 38 (in-package :constants) … … 64 71 (defparameter *xml-string* "http://www.w3.org/2001/XMLSchema#string") 65 72 66 (defparameter *rdf2tm-ns* "http://isidorus/rdf2tm_mapping/") 73 (defparameter *rdf2tm-ns* "http://isidorus/rdf2tm_mapping#") 74 75 (defparameter *rdf-statement* "http://www.w3.org/1999/02/22-rdf-syntax-ns#Statement") 76 77 (defparameter *rdf-object* "http://www.w3.org/1999/02/22-rdf-syntax-ns#object") 78 79 (defparameter *rdf-subject* "http://www.w3.org/1999/02/22-rdf-syntax-ns#subject") 80 81 (defparameter *rdf-predicate* "http://www.w3.org/1999/02/22-rdf-syntax-ns#predicate") 82 83 (defparameter *rdf2tm-object* "http://isidorus/rdf2tm_mapping#object") 84 85 (defparameter *rdf2tm-subject* "http://isidorus/rdf2tm_mapping#subject") -
TabularUnified trunk/src/isidorus.asd ¶
r97 r101 21 21 (:file "constants") 22 22 (:static-file "xml/xtm/core_psis.xtm") 23 (:static-file "xml/rdf/rdf_core_psis.xtm") 23 24 (:file "xml-constants" 24 25 :depends-on ("xml/xtm/core_psis.xtm" -
TabularUnified trunk/src/xml-constants.lisp ¶
r92 r101 14 14 *isidorus-system*) 15 15 (:export :*xml-component* 16 :*core_psis.xtm*)) 16 :*core_psis.xtm* 17 :*rdf_core_psis.xtm*)) 17 18 18 19 (in-package :xml-constants) … … 25 26 (asdf:find-component *isidorus-system* "xml/xtm/core_psis.xtm"))) 26 27 28 (defparameter *rdf_core_psis.xtm* 29 (asdf:component-pathname 30 (asdf:find-component *isidorus-system* "xml/rdf/rdf_core_psis.xtm"))) -
TabularUnified trunk/src/xml/rdf/importer.lisp ¶
r100 r101 12 12 13 13 14 (defun setup-rdf-module (rdf-xml-path repository-path 15 &key tm-id (document-id (get-uuid))) 16 "Sets up the data base by importing core_psis.xtm and 17 rdf_core_psis.xtm afterwards the file corresponding 18 to the give file path is imported." 19 (declare ((or pathname string) rdf-xml-path)) 20 (declare ((or pathname string) repository-path)) 21 (unless elephant:*store-controller* 22 (elephant:open-store 23 (get-store-spec repository-path))) 24 (xml-importer:init-isidorus) 25 (init-rdf-module) 26 (rdf-importer rdf-xml-path repository-path :tm-id tm-id) 27 :document-id document-id 28 (when elephant:*store-controller* 29 (elephant:close-store))) 30 31 32 (defun rdf-importer (rdf-xml-path repository-path 33 &key 34 (tm-id nil) 35 (document-id (get-uuid)) 36 (start-revision (d:get-revision))) 37 "Imports the file correponding to the given path." 38 (setf *document-id* document-id) 39 (tm-id-p tm-id "rdf-importer") 40 (unless elephant:*store-controller* 41 (elephant:open-store 42 (get-store-spec repository-path))) 43 (let ((rdf-dom 44 (dom:document-element (cxml:parse-file 45 (truename rdf-xml-path) 46 (cxml-dom:make-dom-builder))))) 47 (import-dom rdf-dom start-revision :tm-id tm-id :document-id document-id)) 48 (setf *_n-map* nil)) 49 50 51 (defun init-rdf-module (&optional (revision (get-revision))) 52 "Imports the file rdf_core_psis.xtm. core_psis.xtm has to be imported 53 before." 54 (with-writer-lock 55 (with-tm (revision "rdf.xtm" "http://isidorus/rdf2tm_mapping/rdf.xtm") 56 (let 57 ((core-dom 58 (cxml:parse-file *rdf_core_psis.xtm* (cxml-dom:make-dom-builder)))) 59 (loop for top-elem across 60 (xpath-child-elems-by-qname (dom:document-element core-dom) 61 *xtm2.0-ns* "topic") 62 do 63 (let 64 ((top 65 (from-topic-elem-to-stub top-elem revision 66 :xtm-id *rdf-core-xtm*))) 67 (add-to-topicmap xml-importer::tm top))))))) 68 69 14 70 (defun tm-id-p (tm-id fun-name) 15 71 "Checks the validity of the passed tm-id." … … 19 75 20 76 21 (defun rdf-importer (rdf-xml-path repository-path22 &key23 (tm-id nil)24 (document-id (get-uuid))25 (start-revision (d:get-revision)))26 (setf *document-id* document-id)27 (tm-id-p tm-id "rdf-importer")28 (let ((rdf-dom29 (dom:document-element (cxml:parse-file30 (truename rdf-xml-path)31 (cxml-dom:make-dom-builder)))))32 (unless elephant:*store-controller*33 (elephant:open-store34 (get-store-spec repository-path)))35 (import-dom rdf-dom start-revision :tm-id tm-id :document-id document-id))36 (setf *_n-map* nil))37 38 39 77 (defun import-dom (rdf-dom start-revision 40 78 &key (tm-id nil) (document-id *document-id*)) 79 "Imports the entire dom of a rdf-xml-file." 41 80 (tm-id-p tm-id "import-dom") 42 81 (let ((xml-base (get-xml-base rdf-dom)) … … 44 83 (elem-name (get-node-name rdf-dom)) 45 84 (elem-ns (dom:namespace-uri rdf-dom))) 46 47 85 (if (and (string= elem-ns *rdf-ns*) 48 86 (string= elem-name "RDF")) … … 52 90 do (import-node child tm-id start-revision :document-id document-id 53 91 :xml-base xml-base :xml-lang xml-lang)))) 54 55 92 (import-node rdf-dom tm-id start-revision :document-id document-id 93 :xml-base xml-base :xml-lang xml-lang)))) 56 94 57 95 … … 76 114 :ID nil)) 77 115 (get-types-of-node-content elem tm-id fn-xml-base))) 78 (super-classes (get-super-classes-of-node-content elem tm-id xml-base))) 79 (let ((topic-stub (make-topic-stub-from-node about ID nodeID UUID 80 start-revision 116 (super-classes 117 (get-super-classes-of-node-content elem tm-id xml-base))) 118 (with-tm (start-revision document-id tm-id) 119 (let ((topic-stub 120 (make-topic-stub 121 about ID nodeID UUID start-revision xml-importer::tm 122 :document-id document-id))) 123 (map 'list #'(lambda(literal) 124 (make-occurrence topic-stub literal start-revision 125 tm-id :document-id document-id)) 126 literals) 127 (format t "~a~%" literals) 128 (map 'list #'(lambda(assoc) 129 (make-association topic-stub assoc xml-importer::tm 130 start-revision 131 :document-id document-id)) 132 associations) 133 (map 'list 134 #'(lambda(type) 135 (let ((type-topic 136 (make-topic-stub (getf type :psi) 137 (getf type :topicid) 138 nil nil start-revision 139 xml-importer::tm 140 :document-id document-id)) 141 (ID (getf type :ID))) 142 (make-instance-of-association topic-stub type-topic 143 ID start-revision 144 xml-importer::tm 81 145 :document-id document-id))) 146 types) 82 147 83 148 ;TODO: 149 ;*import standard topics from isidorus' rdf2tm namespace 150 ; (must be explicitly called by the user) 84 151 ;*get-topic by topic id 85 152 ;*make psis 86 153 ;*if the topic does not exist create one with topic id 87 154 ;*add psis 88 ;make instance-of associations 89 ;make topictype topics with topic id 90 ;make super-sub-class associations 91 ;make occurrencetype topics with topic id 92 ;make and add occurrences 93 ;make referenced topic with topic id 94 ;make and add associations 155 ;*make instance-of associations + reification 156 ;make super-sub-class associations + reification 157 ;*make occurrences + reification 158 ;*make associations + reification 95 159 96 160 97 161 ;TODO: start recursion ... 98 (remove-node-properties-from-*_n-map* elem) 99 (or tm-id document-id topic-stub nodeID UUID literals ;TODO: remove 100 associations types super-classes))))) 101 102 103 (defun make-topic-stub-from-node (about ID nodeId UUID start-revision 104 &key (document-id *document-id*)) 162 (remove-node-properties-from-*_n-map* elem) 163 (or super-classes) ;TODO: remove 164 ))))) 165 166 167 168 (defun make-instance-of-association (instance-top type-top reifier-id 169 start-revision tm 170 &key (document-id *document-id*)) 171 "Creates and returns an instance-of association." 172 (declare (TopicC type-top instance-top)) 173 (declare (TopicMapC tm)) 174 (let ((assoc-type 175 (get-item-by-psi *type-instance-psi*)) 176 (roletype-1 177 (get-item-by-psi *type-psi*)) 178 (roletype-2 179 (get-item-by-psi *instance-psi*))) 180 (let ((a-roles (list (list :instance-of roletype-1 181 :player type-top) 182 (list :instance-of roletype-2 183 :player instance-top)))) 184 (when reifier-id 185 (make-reification reifier-id instance-top type-top 186 assoc-type start-revision tm 187 :document-id document-id)) 188 (add-to-topicmap 189 tm 190 (make-construct 'AssociationC 191 :start-revision start-revision 192 :instance-of assoc-type 193 :roles a-roles))))) 194 195 196 (defun make-topic-stub (about ID nodeId UUID start-revision 197 tm &key (document-id *document-id*)) 105 198 "Returns a topic corresponding to the passed parameters. 106 199 When the searched topic does not exist there will be created one. 107 If about or ID is set there will aslo be created a new PSI." 108 ; (let ((topic-id (or about ID nodeID UUID)) 109 ; (psi-value (or about ID)) 110 ; (err-pref "From make-topic-stub-from-node(): ")) 111 ; (unless topic-id 112 ; (error "~aone of about ID nodeID UUID must be set!" 113 ; err-pref)) 114 ; (elephant:ensure-transaction (:txn-nosync t) 115 ; (let ((top (get-item-by-id topic-id :xtm-id document-id 116 ; :revision start-revision))) 117 ; (let ((topic-psis (map 'list #'d:uri (d:psis top)))) 118 ; (if (and psi-value 119 ; (not (find psi-value topic-psis :test #'string=))) 120 ; (let ((psis (list (d::make-instance 121 ; 'd:PersistentIdC 122 ; :uri psi-value 123 ; :start-revision start-revision)))) 124 ; ;create only a new topic if there existed no one 125 ; (d::make-instance 'd:TopicC 126 ; :topicid topic-id 127 ; :psis psis 128 ; :xtm-id document-id 129 ; :start-revision start-revision)) 130 ; top)))))) 131 ) 132 133 134 (defun make-occurrence-from-node (top literals start-revision 135 &key (document-id *document-id*)) 136 ; (loop for literal in literals 137 ; do (let ((type 138 ) 139 200 If about or ID is set there will also be created a new PSI." 201 (declare (TopicMapC tm)) 202 (let ((topic-id (or about ID nodeID UUID)) 203 (psi-uri (or about ID))) 204 (let ((top (get-item-by-id topic-id :xtm-id document-id 205 :revision start-revision))) 206 (if top 207 top 208 (elephant:ensure-transaction (:txn-nosync t) 209 (let ((psi (when psi-uri 210 (make-instance 'PersistentIdC 211 :uri psi-uri 212 :start-revision start-revision)))) 213 (add-to-topicmap 214 tm 215 (make-construct 'TopicC 216 :topicid topic-id 217 :psis (when psi (list psi)) 218 :xtm-id document-id 219 :start-revision start-revision)))))))) 220 221 222 (defun make-lang-topic (lang tm-id start-revision tm 223 &key (document-id *document-id*)) 224 "Returns a topic with the topicid tm-id/lang. If no such topic exist 225 there will be created one." 226 (declare (TopicMapC tm)) 227 (when (and lang tm-id) 228 (tm-id-p tm-id "make-lang-topic") 229 (let ((psi-and-topic-id 230 (absolutize-value lang nil tm-id))) 231 (let ((top (get-item-by-id psi-and-topic-id :xtm-id document-id 232 :revision start-revision))) 233 (if top 234 top 235 (make-topic-stub psi-and-topic-id nil nil nil start-revision 236 tm :document-id document-id)))))) 237 238 239 (defun make-association (top association tm start-revision 240 &key (document-id *document-id*)) 241 "Creates an association depending on the given parameters and 242 returns the elephat-associaton object." 243 (declare (TopicC top)) 244 (declare (TopicMapC tm)) 245 (let ((type (getf association :type)) 246 (player-id (getf association :topicid)) 247 (player-psi (getf association :psi)) 248 (ID (getf association :ID))) 249 (let ((player-1 (make-topic-stub player-psi player-id nil nil start-revision 250 tm :document-id document-id)) 251 (role-type-1 (get-item-by-psi *rdf2tm-object*)) 252 (role-type-2 (get-item-by-psi *rdf2tm-subject*)) 253 (type-top (make-topic-stub type nil nil nil start-revision 254 tm :document-id document-id))) 255 (let ((roles (list (list :instance-of role-type-1 256 :player player-1) 257 (list :instance-of role-type-2 258 :player top)))) 259 (when ID 260 (make-reification ID top type-top player-1 start-revision 261 tm :document-id document-id)) 262 (add-to-topicmap tm (make-construct 'AssociationC 263 :start-revision start-revision 264 :instance-of type-top 265 :roles roles)))))) 266 267 268 (defun make-association-with-nodes (subject-topic object-topic 269 associationtype-topic tm start-revision) 270 "Creates an association with two roles that contains the given players." 271 (declare (TopicC subject-topic object-topic associationtype-topic)) 272 (declare (TopicMapC tm)) 273 (let ((role-type-1 (get-item-by-psi *rdf2tm-subject*)) 274 (role-type-2 (get-item-by-psi *rdf2tm-object*))) 275 (let ((roles (list (list :instance-of role-type-1 276 :player subject-topic) 277 (list :instance-of role-type-2 278 :player object-topic)))) 279 (add-to-topicmap tm (make-construct 'AssociationC 280 :start-revision start-revision 281 :instance-of associationtype-topic 282 :roles roles))))) 283 284 285 (defun make-reification (reifier-id subject object predicate start-revision tm 286 &key document-id) 287 "Creates a reification construct." 288 (declare (string reifier-id)) 289 (declare ((or OccurrenceC TopicC) object)) 290 (declare (TopicC subject predicate)) 291 (declare (TopicMapC tm)) 292 (let ((reifier (make-topic-stub reifier-id nil nil nil start-revision tm 293 :document-id document-id)) 294 (predicate-arc (make-topic-stub *rdf-predicate* nil nil nil start-revision 295 tm :document-id document-id)) 296 (object-arc (make-topic-stub *rdf-object* nil nil nil start-revision 297 tm :document-id document-id)) 298 (subject-arc (make-topic-stub *rdf-object* nil nil nil start-revision 299 tm :document-id document-id)) 300 (statement (make-topic-stub *rdf-statement* nil nil nil start-revision 301 tm :document-id document-id))) 302 (make-instance-of-association reifier statement nil start-revision tm 303 :document-id document-id) 304 (make-association-with-nodes reifier subject subject-arc tm start-revision) 305 (make-association-with-nodes reifier predicate-arc predicate 306 tm start-revision) 307 (if (typep object 'TopicC) 308 (make-association-with-nodes reifier object object-arc 309 tm start-revision) 310 (make-construct 'OccurrenceC 311 :start-revision start-revision 312 :topic reifier 313 :themes (themes object) 314 :instance-of (instance-of object) 315 :charvalue (charvalue object) 316 :datatype (datatype object))))) 317 318 319 (defun make-occurrence (top literal start-revision tm-id 320 &key (document-id *document-id*)) 321 "Creates an accorrence from the literal list and returns 322 the created elephant-occurrence-object." 323 (declare (TopicC top)) 324 (tm-id-p tm-id "make-occurrence") 325 (with-tm (start-revision document-id tm-id) 326 (let ((type (getf literal :type)) 327 (value (getf literal :value)) 328 (lang (getf literal :lang)) 329 (datatype (getf literal :datatype)) 330 (ID (getf literal :ID))) 331 (let ((type-top (make-topic-stub type nil nil nil start-revision 332 xml-importer::tm 333 :document-id document-id)) 334 (lang-top (make-lang-topic lang tm-id start-revision 335 xml-importer::tm 336 :document-id document-id))) 337 (let ((occurrence 338 (make-construct 'OccurrenceC 339 :start-revision start-revision 340 :topic top 341 :themes (when lang-top 342 (list lang-top)) 343 :instance-of type-top 344 :charvalue value 345 :datatype datatype))) 346 (when ID 347 (make-reification ID top type-top occurrence start-revision 348 xml-importer::tm :document-id document-id)) 349 occurrence))))) 350 140 351 141 352 (defun get-literals-of-node-content (node tm-id xml-base xml-lang) -
TabularUnified trunk/src/xml/rdf/rdf_tools.lisp ¶
r100 r101 15 15 *xmlns-ns* 16 16 *xml-string* 17 *rdf2tm-ns*) 17 *rdf2tm-ns* 18 *xtm2.0-ns* 19 *type-instance-psi* 20 *type-psi* 21 *instance-psi* 22 *rdf-statement* 23 *rdf-object* 24 *rdf-subject* 25 *rdf-predicate* 26 *rdf2tm-object* 27 *rdf2tm-subject*) 28 (:import-from :xml-constants 29 *rdf_core_psis.xtm*) 18 30 (:import-from :xml-constants 19 31 *core_psis.xtm*) … … 40 52 (:import-from :xml-importer 41 53 get-uuid 42 get-store-spec) 54 get-store-spec 55 with-tm 56 from-topic-elem-to-stub) 57 (:import-from :isidorus-threading 58 with-reader-lock 59 with-writer-lock) 43 60 (:import-from :exceptions 44 61 missing-reference-error … … 59 76 "range" "range" "label" "comment" 60 77 "member" "seeAlso" "isDefinedBy")) 78 79 (defvar *rdf-core-xtm* "rdf_core.xtm") 61 80 62 81 (defvar *_n-map* nil)
Note: See TracChangeset
for help on using the changeset viewer.