Changeset 130 for trunk/src/xml


Ignore:
Timestamp:
09/02/09 14:15:46 (16 years ago)
Author:
lgiessmann
Message:

rdf-importer: added the functionality of importing isidorus:Occurrence nodes; added also some unti tests

Location:
trunk/src/xml/rdf
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • TabularUnified trunk/src/xml/rdf/importer.lisp

    r129 r130  
    105105          (UUID (get-ns-attribute elem "UUID" :ns-uri *rdf2tm-ns*)))
    106106      (parse-properties-of-node elem (or about nodeID ID UUID))
    107       ;TODO: create associaitons and roles
     107      ;TODO: create associations and roles -> and iterate in import-dom
     108      ;      over those elements
    108109    (let ((literals (append (get-literals-of-node elem fn-xml-lang)
    109110                            (get-literals-of-node-content
     
    127128                :subject-locators subject-locators)))
    128129          (make-isidorus-names elem this tm-id start-revision
    129                                :owner-xml-base fn-xml-base)
    130           ;TODO: create topic occurrences
     130                               :owner-xml-base fn-xml-base
     131                               :document-id document-id)
     132          (make-isidorus-occurrences elem this tm-id start-revision
     133                                     :owner-xml-base fn-xml-base
     134                                     :document-id document-id)
    131135          (make-literals this literals tm-id start-revision
    132136                         :document-id document-id)
     
    144148
    145149
     150(defun make-isidorus-occurrences (owner-elem owner-topic tm-id start-revision
     151                                  &key (owner-xml-base nil)
     152                                  (document-id *document-id*))
     153  "Creates all occurrences of resource nodes that are in a
     154   property isidorus:occurrence and have the type isidorus:Occurrence."
     155  (declare (dom:element owner-elem))
     156  (declare (string tm-id))
     157  (declare (TopicC owner-topic))
     158  (let ((content (child-nodes-or-text owner-elem :trim t))
     159        (root (elt (dom:child-nodes (dom:owner-document owner-elem)) 0))
     160        (err-pref "From make-isidorus-occurrence(): "))
     161    (when (and (not (stringp content))
     162               (> (length content) 0))
     163      (loop for property across content
     164         when (isidorus-type-p property tm-id 'occurrence
     165                               :parent-xml-base owner-xml-base)
     166         collect
     167           (let ((xml-base (get-xml-base property
     168                                         :old-base owner-xml-base)))
     169             (let ((nodes
     170                    (let ((nodeID (nodeID-of-property-or-child property)))
     171                      (if nodeID
     172                          (get-all-isidorus-nodes-by-id
     173                           nodeID root *tm2rdf-occurrence-type-uri*)
     174                          (list (self-or-child-node
     175                                 property *tm2rdf-occurrence-type-uri*
     176                                 :xml-base xml-base))))))
     177               (let ((item-identities
     178                      (remove-if #'null
     179                                 (loop for node in nodes
     180                                    append (make-isidorus-identifiers
     181                                            (getf node :elem) start-revision))))
     182                     (occurrence-type (make-x-type
     183                                       nodes tm-id start-revision
     184                                       *tm2rdf-occurrencetype-property*
     185                                       :document-id document-id))
     186                     (value-and-datatype (make-value nodes tm-id))
     187                     (occurrence-scopes (make-scopes nodes tm-id start-revision
     188                                                     :document-id document-id)))
     189                 (unless occurrence-type
     190                   (error "~aoccurrencetype is missing!"
     191                          err-pref))
     192                 (make-construct 'OccurrenceC
     193                                 :start-revision start-revision
     194                                 :topic owner-topic
     195                                 :themes occurrence-scopes
     196                                 :item-identifiers item-identities
     197                                 :instance-of occurrence-type
     198                                 :charvalue (getf value-and-datatype :value)
     199                                 :datatype (getf value-and-datatype
     200                                                 :datatype)))))))))
     201
    146202
    147203(defun make-isidorus-names (owner-elem owner-topic tm-id start-revision
    148204                            &key (owner-xml-base nil)
    149205                            (document-id *document-id*))
    150   "Creates all names of a resource node that are in a property isidorus:name
     206  "Creates all names of resource nodes that are in a property isidorus:name
    151207   and have the type isidorus:Name."
    152208  (declare (dom:element owner-elem))
     
    154210  (declare (TopicC owner-topic))
    155211  (let ((content (child-nodes-or-text owner-elem :trim t))
    156         (root (elt (dom:child-nodes (dom:owner-document owner-elem)) 0)))
     212        (root (elt (dom:child-nodes (dom:owner-document owner-elem)) 0))
     213        (err-pref "From make-isidorus-name(): "))
    157214    (when (and (not (stringp content))
    158215               (> (length content) 0))
     
    164221                                         :old-base owner-xml-base)))
    165222             (let ((nodes
    166                     (let ((nodeID (get-ns-attribute property "nodeID")))
     223                    (let ((nodeID (nodeID-of-property-or-child property)))
    167224                      (if nodeID
    168225                          (get-all-isidorus-nodes-by-id
     
    176233                                    append (make-isidorus-identifiers
    177234                                            (getf node :elem) start-revision))))
    178                      (name-type (make-name-type nodes tm-id start-revision
    179                                                 :document-id document-id))
     235                     (name-type (make-x-type nodes tm-id start-revision
     236                                             *tm2rdf-nametype-property*
     237                                             :document-id document-id))
    180238                     (name-value (getf (make-value nodes tm-id) :value))
    181239                     (name-scopes (make-scopes nodes tm-id start-revision
    182240                                               :document-id document-id)))
     241                 (unless name-type
     242                   (error "~anametype is missing!"
     243                          err-pref))
    183244                 (let ((this
    184245                        (make-construct 'NameC
     
    201262         (when name-nodes
    202263           (elt (dom:child-nodes
    203                  (dom:owner-document (getf (first name-nodes) :elem))) 0))))
     264                 (dom:owner-document (getf (first name-nodes) :elem))) 0)))
     265        (err-pref "From make-isidorus-variant(): "))
    204266    (remove-if
    205267     #'null
     
    238300                                                :document-id document-id)
    239301                                   (themes owner-name))) ;XTM 2.0: 4.12
    240                                  (value-and-type (make-value nodes tm-id)))       
     302                                 (value-and-type (make-value nodes tm-id)))
     303                             (unless variant-scopes
     304                               (error "~ascope is missing!"
     305                                      err-pref))
    241306                             (make-construct 'VariantC
    242307                                             :start-revision start-revision
     
    337402 
    338403
    339 (defun make-name-type (node-list tm-id start-revision
     404(defun make-x-type (node-list tm-id start-revision uri-of-property
    340405                       &key (document-id *document-id*))
    341406  "Creates a topic stub that is the type of the name represented by the
     
    349414                                 (prop-name (get-node-name property)))
    350415                             (string= (concatenate-uri prop-ns prop-name)
    351                                       *tm2rdf-nametype-property*))
     416                                      uri-of-property))
    352417                      return property))
    353418            return (let ((content (child-nodes-or-text (getf node :elem)
     
    357422                                   (prop-name (get-node-name property)))
    358423                               (string= (concatenate-uri prop-ns prop-name)
    359                                         *tm2rdf-nametype-property*))
     424                                        uri-of-property))
    360425                        return (list
    361426                                :elem property
     
    369434                                           (getf property :xml-base))))
    370435        (unless type-uri
    371           (error "From make-name-type(): type-uri is missing!"))
     436          (error "From make-x-type(): type-uri is missing!"))
    372437        (with-tm (start-revision document-id tm-id)
    373438          (make-topic-stub (getf type-uri :psi) nil
     
    431496                                                :owner-xml-base xml-base
    432497                                                :document-id document-id)
    433                            ;TDOD: create topic occurrences
     498                           (make-isidorus-occurrences
     499                            elem this tm-id start-revision
     500                            :owner-xml-base xml-base :document-id document-id)
    434501                           (make-literals this literals tm-id start-revision
    435502                                          :document-id document-id)
  • TabularUnified trunk/src/xml/rdf/isidorus_constructs_tools.lisp

    r129 r130  
    319319        (list :elem property-node
    320320              :xml-base xml-base))))
     321
     322
     323(defun nodeID-of-property-or-child (elem)
     324  "Returns either the nodeID of the given element or if tere isn't one
     325   the nodeID of the element's first child node. If there is no nodeID
     326   at all, nil is returned."
     327  (declare (dom:element elem))
     328  (let ((elem-nodeID (get-ns-attribute elem "nodeID")))
     329    (if elem-nodeID
     330        elem-nodeID
     331        (let ((elem-content (child-nodes-or-text elem :trim t)))
     332          (when (and (> (length elem-content) 0)
     333                     (not (stringp elem-content)))
     334            (get-ns-attribute (elt elem-content 0) "nodeID"))))))
     335             
Note: See TracChangeset for help on using the changeset viewer.