Changeset 456 for trunk/src/json/JTM


Ignore:
Timestamp:
05/07/11 22:02:56 (14 years ago)
Author:
lgiessmann
Message:

JTM: added functions that allow the import of a single topicstub, topic an array of topicstubs and topics

File:
1 edited

Legend:

Unmodified
Added
Removed
  • TabularUnified trunk/src/json/JTM/jtm_importer.lisp

    r455 r456  
    2020           (List jtm-list))
    2121  (rest (find item-keyword jtm-list :key #'first)))
     22
     23
     24(defun import-topic-stubs-from-jtm-lists (jtm-lists parents &key
     25                                          (revision *TM-REVISION*) prefixes)
     26  "Creates and returns a list of topics.
     27   Note only the topic identifiers are imported and set in this function,
     28   entire topics are imported in merge-topics-from-jtm-lists."
     29  (declare (List jtm-lists parents prefixes)
     30           (Integer revision))
     31  (map 'list #'(lambda(jtm-list)
     32                 (import-topic-stub-from-jtm-list
     33                  jtm-list parents :revision revision :prefixes prefixes))
     34       jtm-lists))
     35
     36
     37(defun import-topic-stub-from-jtm-list(jtm-list parents &key
     38                                       (revision *TM-REVISION*) prefixes)
     39  "Creates and returns a topic object from the passed jtm
     40   list generated by json:decode-json-from-string.
     41   Note this function only sets the topic's identifiers."
     42  (declare (List jtm-list parents prefixes)
     43           (Integer revision))
     44  (let* ((t-iis (import-identifiers-from-jtm-strings
     45                 (get-item :ITEM--IDENTIFIERS jtm-list)
     46                 :prefixes prefixes))
     47         (t-psis (import-identifiers-from-jtm-strings
     48                  (get-item :SUBJECT--IDENTIFIERS jtm-list)
     49                  :prefixes prefixes :identifier-type-symbol 'd:PersistentIdC))
     50         (t-sls (import-identifiers-from-jtm-strings
     51                 (get-item :SUBJECT--LOCATORS jtm-list)
     52                 :prefixes prefixes :identifier-type-symbol 'd:SubjectLocatorC))
     53         (parent-references (get-item :PARENT jtm-list))
     54         (local-parents
     55          (if parents
     56              parents
     57              (when parent-references
     58                (get-items-from-jtm-references
     59                 parent-references :revision revision :prefixes prefixes)))))
     60    (unless local-parents
     61      (error (make-condition 'JTM-error :message (format nil "From import-topic-from-jtm-string(): the JTM topic ~a must have at least one parent set in its members." jtm-list))))
     62    (unless (append t-iis t-sls t-psis)
     63      (error (make-condition 'JTM-error :message (format nil "From import-topic-from-jtm-string(): the JTM topic ~a must have at least one identifier set in its members." jtm-list))))
     64    (let* ((top (make-construct 'TopicC :start-revision revision
     65                                :psis t-psis
     66                                :item-identifiers t-iis
     67                                :locators t-sls)))
     68      (dolist (tm local-parents)
     69        (add-to-tm tm top))
     70      top)))
     71
     72
     73(defun make-instance-of-association (instance-top type-top parents &key
     74                                     (revision *TM-REVISION*))
     75  "Creates and returns a type-instance-association for the passed
     76   instance and type topics."
     77  (declare (TopicC instance-top type-top)
     78           (List parents)
     79           (Integer revision))
     80  (let ((t-top (get-item-by-psi *type-psi* :revision revision))
     81        (i-top (get-item-by-psi *instance-psi* :revision revision))
     82        (ti-top (get-item-by-psi *type-instance-psi* :revision revision)))
     83    (let ((assoc (make-construct 'AssociationC :start-revision revision
     84                                 :instance-of ti-top
     85                                 :roles (list (list :start-revision revision
     86                                                    :player instance-top
     87                                                    :instance-of i-top)
     88                                              (list :start-revision revision
     89                                                    :player type-top
     90                                                    :instance-of t-top)))))
     91      (dolist (tm parents)
     92        (add-to-tm tm assoc))
     93      assoc)))
     94
     95
     96(defun merge-topics-from-jtm-lists (jtm-lists parents &key (instance-of-p t)
     97                                    (revision *TM-REVISION*) prefixes)
     98  "Creates and returns a list of topics."
     99  (declare (List jtm-lists parents prefixes)
     100           (Boolean instance-of-p)
     101           (Integer revision))
     102  (map 'list #'(lambda(jtm-list)
     103                 (merge-topic-from-jtm-list
     104                  jtm-list parents :revision revision :prefixes prefixes
     105                  :instance-of-p instance-of-p))
     106       jtm-lists))
     107
     108
     109(defun merge-topic-from-jtm-list(jtm-list parents &key (instance-of-p t)
     110                                  (revision *TM-REVISION*) prefixes)
     111  "Creates and returns a topic object from the passed jtm
     112   list generated by json:decode-json-from-string."
     113  (declare (List jtm-list prefixes parents)
     114           (Boolean instance-of-p)
     115           (Integer revision))
     116  (let* ((ids (append (get-item :ITEM--IDENTIFIERS jtm-list)
     117                      (get-item :SUBJECT--IDENTIFIERS jtm-list)
     118                      (get-item :SUBJECT--LOCATORS jtm-list)))
     119         (top (when ids
     120                (get-item-from-jtm-reference (first ids) :revision revision
     121                                             :prefixes prefixes)))
     122         (instanceof (get-items-from-jtm-references
     123                      (get-item :INSTANCE--OF jtm-list) :revision revision
     124                      :prefixes prefixes))
     125         (top-names (import-characteristics-from-jtm-lists
     126                     (get-item :NAMES jtm-list) top
     127                     #'import-name-from-jtm-list :revision revision
     128                     :prefixes prefixes))
     129         (top-occs (import-characteristics-from-jtm-lists
     130                    (get-item :OCCURRENCES jtm-list) top
     131                    #'import-occurrence-from-jtm-list :revision revision
     132                    :prefixes prefixes)))
     133    (unless ids
     134      (error (make-condition 'JTM-error :message (format nil "From merge-topic-from-jtm-list(): the passed topic has to own at least one identifier: ~a" jtm-list))))
     135    (unless top
     136      (error (make-condition 'JTM-error :message (format nil "From merge-topic-from-jtm-list(): cannot find a topic that matches the corresponding JTM-list: ~a" jtm-list))))
     137    (when (and (not instance-of-p) instanceof)
     138      (error (make-condition 'JTM-error :message (format nil "From merge-topic-from-jtm-list(): the JTM-topic has an instance_of member set, but JTM version 1.0 does not allow an intance_of member within a topic object: ~a" jtm-list))))
     139    (dolist (type-top instanceof)
     140      (make-instance-of-association top type-top parents :revision revision))
     141    (dolist (name top-names)
     142      (add-name top name :revision revision))
     143    (dolist (occ top-occs)
     144      (add-occurrence top occ :revision revision))
     145    top))
    22146
    23147
     
    60184                       (get-item-from-jtm-reference
    61185                        reifier :revision revision :prefixes prefixes)))))
    62       (import-constructs-from-jtm-lists name-variants name
    63                                         #'import-variant-from-jtm-list
    64                                         :revision revision :prefixes prefixes)
     186      (import-characteristics-from-jtm-lists name-variants name
     187                                             #'import-variant-from-jtm-list
     188                                             :revision revision :prefixes prefixes)
    65189      name)))
    66190
     
    106230
    107231
    108 (defun import-constructs-from-jtm-lists(jtm-lists parent next-fun &key
    109                                         (revision *TM-REVISION*) prefixes)
     232(defun import-characteristics-from-jtm-lists(jtm-lists parent next-fun &key
     233                                             (revision *TM-REVISION*) prefixes)
    110234  "Creates and returns a list of TM-Constructs returned by next-fun."
    111235  (declare (List jtm-lists prefixes)
Note: See TracChangeset for help on using the changeset viewer.