Changeset 156 for trunk/src/xml


Ignore:
Timestamp:
12/01/09 12:50:56 (15 years ago)
Author:
lgiessmann
Message:

added a mapping-schema for reification (tm->rdf; rdf->tm) to the rdf-module; unit-tests are currently missing

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

Legend:

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

    r155 r156  
    2727                *tm2rdf-topic-type-uri*
    2828                *tm2rdf-association-type-uri*
    29                 *tm2rdf-role-type-uri*)
     29                *tm2rdf-role-type-uri*
     30                *tm2rdf-association-reifier-property*)
    3031  (:import-from :isidorus-threading
    3132                with-reader-lock
     
    443444      (cxml:attribute "rdf:nodeID" (make-object-id association))
    444445      (make-isi-type *tm2rdf-association-type-uri*)
     446      (when (reifier association)
     447        (cxml:with-element *tm2rdf-association-reifier-property*
     448          (make-topic-reference (reifier association))))
    445449      (cxml:with-element "isi:associationtype"
    446450        (make-topic-reference association-type))
     
    459463      (cxml:with-element "rdf:Description"
    460464        (cxml:attribute "rdf:nodeID" (make-object-id construct))
    461         ;(cxml:attribute "rdf:parseType" "Resource")
     465        (when (reifier construct)
     466          (cxml:with-element *tm2rdf-association-reifier-property*
     467            (make-topic-reference (reifier construct))))
    462468        (make-isi-type *tm2rdf-role-type-uri*)
    463469        (map 'list #'to-rdf-elem ii)
     
    472478   This is indicated by the existence of exactly two roles. One
    473479   of the type isi:object, the other of the type isi:subject.
    474    Scopes or itemIdentifiers are also forbidden."
     480   Scopes or itemIdentifiers are also forbidden.
     481   If the contained roles own any reifiers they are ignored."
    475482  (declare (AssociationC association))
    476483  (let ((isi-subject (get-item-by-psi *rdf2tm-subject*))
     
    486493                 (= (length association-roles) 2))
    487494        (with-property association
     495          (when (reifier association)
     496            (let ((reifier-uri (get-reifier-uri (reifier association))))
     497              (when reifier-uri
     498                (cxml:attribute "rdf:ID" reifier-uri))))
    488499          (make-topic-reference (player object-role)))))))
    489500
  • TabularUnified trunk/src/xml/rdf/map_to_tm.lisp

    r155 r156  
    106106                                   *tm2rdf-role-property*
    107107                                   *rdf2tm-subject*)))
    108     (let ((players
    109            (get-players-by-role-type role-assocs start-revision
    110                                      *rdf2tm-object*)))
     108    (let ((players-and-reifiers
     109           (get-players-and-reifiers-by-role-type
     110            role-assocs start-revision *rdf2tm-object*)))
    111111      (map 'list #'d::delete-construct role-assocs)
    112       players)))
    113 
    114 
    115 (defun map-isi-role(role-top start-revision)
     112      players-and-reifiers)))
     113
     114
     115(defun map-isi-role(role-top reifier-topic start-revision)
    116116  "Maps a passed topic with all its isidorus:types to a
    117117   property list representing an association-role."
     
    145145        (list :instance-of (first types)
    146146              :player (first role-players)
    147               :item-identifiers ids)))))
     147              :item-identifiers ids
     148              :reifier reifier-topic)))))
    148149
    149150
     
    160161          assoc-top start-revision *tm2rdf-associationtype-property*
    161162          *rdf2tm-subject*))
     163        (reifier-assocs
     164         (get-associations-by-type
     165          assoc-top start-revision *tm2rdf-association-reifier-property*
     166          *rdf2tm-subject*))
    162167        (scope-assocs
    163168         (get-associations-by-type
    164169          assoc-top start-revision *tm2rdf-scope-property*
    165170          *rdf2tm-subject*))
    166         (role-tops (get-isi-roles assoc-top start-revision)))
     171        (role-and-reifier-topics (get-isi-roles assoc-top start-revision)))
    167172    (let ((types (get-players-by-role-type
    168173                  type-assocs start-revision *rdf2tm-object*))
    169174          (scopes (get-players-by-role-type
    170175                   scope-assocs start-revision *rdf2tm-object*))
     176          (reifier-topics (get-players-by-role-type
     177                           reifier-assocs start-revision  *rdf2tm-object*))
    171178          (assoc-roles
    172179           (remove-if #'null (map 'list
    173                                   #'(lambda(role-top)
    174                                       (map-isi-role role-top start-revision))
    175                                   role-tops))))
     180                                  #'(lambda(role-and-reifier)
     181                                      (map-isi-role (getf role-and-reifier :player)
     182                                                    (getf role-and-reifier :reifier)
     183                                                    start-revision))
     184                                  role-and-reifier-topics))))
    176185      (elephant:ensure-transaction  (:txn-nosync t)
    177186        (map 'list #'d::delete-construct type-assocs)
     
    188197          (add-to-topicmap
    189198           xml-importer::tm
    190            (make-construct 'AssociationC
    191                            :start-revision start-revision
    192                            :item-identifiers ids
    193                            :instance-of (first types)
    194                            :themes scopes
    195                            :roles assoc-roles)))))))
     199           (let ((association
     200                  (make-construct 'AssociationC
     201                                  :start-revision start-revision
     202                                  :item-identifiers ids
     203                                  :instance-of (first types)
     204                                  :themes scopes
     205                                  :roles assoc-roles)))
     206             (map 'list #'(lambda(association-role)
     207                            (let ((found-item
     208                                   (find-if #'(lambda(list-item)
     209                                                (and (eql (instance-of association-role)
     210                                                          (getf list-item :instance-of))
     211                                                     (eql (player association-role)
     212                                                          (getf list-item :player))
     213                                                     (getf list-item :reifier)))
     214                                            assoc-roles)))
     215                              (when found-item
     216                                (add-reifier association-role (getf found-item :reifier)))))
     217                  (roles association))
     218             (when reifier-topics
     219               (add-reifier association (first reifier-topics)))
     220             association)))))))
    196221
    197222
     
    208233                       :id-type-uri *tm2rdf-subjectlocator-property*))
    209234        (new-item-ids (map-isi-identifiers top start-revision))
    210         (occurrence-topics (get-isi-occurrences top start-revision))
    211         (name-topics (get-isi-names top start-revision)))
     235        (occurrence-and-reifier-topics (get-isi-occurrences top start-revision))
     236        (name-and-reifier-topics (get-isi-names top start-revision)))
    212237    (bound-subject-identifiers top new-psis)
    213238    (bound-subject-locators top new-locators)
    214239    (bound-item-identifiers top new-item-ids)
    215     (map 'list #'(lambda(occ-top)
    216                    (map-isi-occurrence top occ-top start-revision))
    217          occurrence-topics)
    218     (map 'list #'(lambda(name-top)
    219                    (map-isi-name top name-top start-revision))
    220          name-topics))
     240    (map 'list #'(lambda(occurrence-and-reifier)
     241                   (map-isi-occurrence top (getf occurrence-and-reifier :player)
     242                                       (getf occurrence-and-reifier :reifier)
     243                                       start-revision))
     244         occurrence-and-reifier-topics)
     245    (map 'list #'(lambda(name-and-reifier)
     246                   (map-isi-name top (getf name-and-reifier :player)
     247                                 (getf name-and-reifier :reifier)
     248                                 start-revision))
     249         name-and-reifier-topics))
    221250  top)
    222251
     
    230259                                   *tm2rdf-variant-property*
    231260                                   *rdf2tm-subject*)))
    232     (let ((players
    233            (get-players-by-role-type variant-assocs start-revision
    234                                     *rdf2tm-object*)))
     261    (let ((players-and-reifiers
     262           (get-players-and-reifiers-by-role-type
     263            variant-assocs start-revision *rdf2tm-object*)))
    235264      (map 'list #'d::delete-construct variant-assocs)
    236       players)))
    237 
    238 
    239 (defun map-isi-variant (name variant-top start-revision)
     265      players-and-reifiers)))
     266
     267
     268(defun map-isi-variant (name variant-top reifier-topic start-revision)
    240269  "Maps the passed variant-topic to a TM variant."
    241270  (declare (TopicC variant-top))
     
    265294        (delete-related-associations variant-top)
    266295        (d::delete-construct variant-top)
    267         (make-construct 'VariantC
    268                         :start-revision start-revision
    269                         :item-identifiers ids
    270                         :themes scopes
    271                         :charvalue (getf value-and-datatype :value)
    272                         :datatype (getf value-and-datatype :datatype)
    273                         :name name)))))
    274 
    275 
    276 (defun map-isi-name (top name-top start-revision)
     296        (let ((variant
     297               (make-construct 'VariantC
     298                               :start-revision start-revision
     299                               :item-identifiers ids
     300                               :themes scopes
     301                               :charvalue (getf value-and-datatype :value)
     302                               :datatype (getf value-and-datatype :datatype)
     303                               :name name)))
     304          (add-reifier variant reifier-topic)
     305          variant)))))
     306
     307
     308(defun map-isi-name (top name-top reifier-topic start-revision)
    277309  "Maps the passed occurrence-topic to a TM occurrence."
    278310  (declare (TopicC top name-top))
     
    289321        (value-type-topic
    290322         (get-item-by-psi *tm2rdf-value-property*))
    291         (variant-topics (get-isi-variants name-top start-revision)))
    292     (let ((types (let ((fn-types
     323        (variant-and-reifier-topics (get-isi-variants name-top start-revision)))
     324    (let ((type (let ((fn-types
    293325                        (get-players-by-role-type
    294326                         type-assocs start-revision *rdf2tm-object*)))
     
    312344                                    :topic top
    313345                                    :charvalue value
    314                                     :instance-of types
     346                                    :instance-of type
    315347                                    :item-identifiers ids
    316348                                    :themes scopes)))
    317           (map 'list #'(lambda(variant-top)
    318                          (map-isi-variant name variant-top start-revision))
    319                variant-topics)
     349          (add-reifier name reifier-topic)
     350          (map 'list #'(lambda(variant-and-reifier)
     351                         (map-isi-variant name (getf variant-and-reifier :player)
     352                                          (getf variant-and-reifier :reifier)
     353                                          start-revision))
     354               variant-and-reifier-topics)
    320355          (delete-related-associations name-top)
    321356          (d::delete-construct name-top)
     
    330365                 top start-revision *tm2rdf-name-property*
    331366                 *rdf2tm-subject*)))
    332     (let ((occ-tops (get-players-by-role-type
    333                      assocs start-revision *rdf2tm-object*)))
     367    (let ((name-and-reifier-topics
     368           (get-players-and-reifiers-by-role-type
     369            assocs start-revision *rdf2tm-object*)))
    334370      (map 'list #'d::delete-construct assocs)
    335       occ-tops)))
    336 
    337 
    338 (defun map-isi-occurrence(top occ-top start-revision)
     371      name-and-reifier-topics)))
     372
     373
     374(defun map-isi-occurrence(top occ-top reifier-topic start-revision)
    339375  "Maps all topics that represents occurrences of the passed topic top
    340376   to occurrence objects."
     
    375411        (delete-related-associations occ-top)
    376412        (d::delete-construct occ-top)
    377         (make-construct 'OccurrenceC
    378                         :start-revision start-revision
    379                         :topic top
    380                         :themes scopes
    381                         :item-identifiers ids
    382                         :instance-of (first types)
    383                         :charvalue (getf value-and-datatype :value)
    384                         :datatype (getf value-and-datatype :datatype))))))
     413        (let ((occurrence
     414               (make-construct 'OccurrenceC
     415                               :start-revision start-revision
     416                               :topic top
     417                               :themes scopes
     418                               :item-identifiers ids
     419                               :instance-of (first types)
     420                               :charvalue (getf value-and-datatype :value)
     421                               :datatype (getf value-and-datatype :datatype))))
     422          (add-reifier occurrence reifier-topic)
     423          occurrence)))))
    385424
    386425
     
    392431                 top start-revision *tm2rdf-occurrence-property*
    393432                 *rdf2tm-subject*)))
    394     (let ((occ-tops (get-players-by-role-type
    395                      assocs start-revision *rdf2tm-object*)))
     433    (let ((occurrences-and-reifiers
     434           (get-players-and-reifiers-by-role-type
     435            assocs start-revision *rdf2tm-object*)))
    396436      (map 'list #'d::delete-construct assocs)
    397       occ-tops)))
     437      occurrences-and-reifiers)))
    398438
    399439
     
    469509                 associations))))
    470510      players)))
     511
     512
     513(defun get-players-and-reifiers-by-role-type (associations start-revision
     514                                             role-type-psi)
     515  "Returns tuples of the form (:player <player> :reifier <reifier>)"
     516    (declare (list associations))
     517  (declare (integer start-revision))
     518  (declare (string role-type-psi))
     519  (let ((role-type (get-item-by-psi role-type-psi
     520                                    :revision start-revision)))
     521    (let ((tuples
     522           (remove-if
     523            #'null
     524            (map 'list
     525                 #'(lambda(assoc)
     526                     (let ((role
     527                            (find-if #'(lambda(role)
     528                                         (eql role-type (instance-of role)))
     529                                     (roles assoc))))
     530                       (when role
     531                         (let ((reifier-topic (reifier assoc)))
     532                           (list :player (player role)
     533                                 :reifier reifier-topic)))))
     534                 associations))))
     535      tuples)))
    471536 
    472537
  • TabularUnified trunk/src/xml/rdf/rdf_tools.lisp

    r139 r156  
    5555                *tm2rdf-player-property*
    5656                *tm2rdf-associationtype-property*
    57                 *rdf2tm-blank-node-prefix*)
     57                *rdf2tm-blank-node-prefix*
     58                *tm2rdf-association-reifier-property*)
    5859  (:import-from :xml-constants
    5960                *rdf_core_psis.xtm*
Note: See TracChangeset for help on using the changeset viewer.