Ignore:
Timestamp:
03/20/10 22:00:40 (15 years ago)
Author:
lgiessmann
Message:

new-datamodel: finalized "make-construct"

File:
1 edited

Legend:

Unmodified
Added
Removed
  • TabularUnified branches/new-datamodel/src/model/datamodel.lisp

    r234 r235  
    664664
    665665
     666(defun merge-all-constructs(constructs-to-be-merged)
     667  "Merges all constructs contained in the given list."
     668  (declare (list constructs-to-be-merged))
     669  (let ((constructs-to-be-merged (subseq constructs-to-be-merged 1))
     670        (merged-construct (elt constructs-to-be-merged 0)))
     671    (loop for construct-to-be-merged in constructs-to-be-merged
     672       do (setf merged-construct
     673                (merge-constructs merged-construct construct-to-be-merged)))))
     674
     675
    666676;;; generic definitions ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
    667677(defgeneric get-all-characteristics (parent-construct characteristic-symbol)
     
    23792389            (make-characteristic class-symbol (getf args :charvalue) args))
    23802390           ((TopicC-p class-symbol)
    2381             (make-topic args)))))
     2391            (make-topic args))
     2392           ((TopicMapC-p class-symbol)
     2393            (make-tm args))
     2394           ((RoleC-p class-symbol)
     2395            (make-role args))
     2396           ((AssociationC-p class-symbol)
     2397            (make-association args)))))
    23822398    construct))
    23832399
    23842400
    2385 (defun merge-all-constructs(constructs-to-be-merged)
    2386   "Merges all constructs contained in the given list."
    2387   (declare (list constructs-to-be-merged))
    2388   (let ((constructs-to-be-merged (subseq constructs-to-be-merged 1))
    2389         (merged-construct (elt constructs-to-be-merged 0)))
    2390     (loop for construct-to-be-merged in constructs-to-be-merged
    2391        do (setf merged-construct
    2392                 (merge-constructs merged-construct construct-to-be-merged)))))
    2393 
    2394 
    2395 (defun make-tm (&rest args)
    2396   "Returns a topic map object. If the topic map has already existed the
     2401(defun make-association (args)
     2402  "Returns an association object. If the association has already existed the
    23972403   existing one is returned otherwise a new one is created.
    23982404   This function exists only for being used by make-construct!"
    23992405  (let ((item-identifiers (getf (first args) :item-identifiers))
    24002406        (reifier (getf (first args) :reifier))
    2401         (topics (getf (first args) :topics))
    2402         (assocs (getf (first args) :associations))
    2403         (start-revision (getf (first args) :start-revision)))
     2407        (instance-of (getf (first args) :instance-of))
     2408        (start-revision (getf (first args) :start-revision))
     2409        (themes (get (first args) :themes))
     2410        (roles (get (first args) :roles))
     2411        (err "From make-association(): "))
     2412    (unless start-revision (error "~astart-revision must be set" err))
     2413    (unless roles (error "~aroles must be set" err))
     2414    (unless instance-of (error "~ainstance-of must be set" err))
     2415    (let ((association
     2416           (let ((existing-association
     2417                  (remove-if
     2418                   #'null
     2419                   (map 'list #'(lambda(existing-association)
     2420                                  (when (equivalent-construct
     2421                                         existing-association
     2422                                         :start-revision start-revision
     2423                                         :roles roles :themes themes
     2424                                         :instance-of instance-of)
     2425                                    existing-association))
     2426                        (elephant:get-instances-by-class 'AssociationC)))))
     2427             (if existing-association
     2428                 existing-association
     2429                 (make-instance 'AssociationC)))))
     2430      (initialize-typable association instance-of :start-revision
     2431                          start-revision)
     2432      (dolist (role roles)
     2433        (add-role association role :revision start-revision))
     2434      (dolist (theme themes)
     2435        (add-theme association theme :revision start-revision))
     2436      (initialize-reifiable association item-identifiers reifier
     2437                            :start-revision start-revision))))
     2438
     2439
     2440(defun make-role (args)
     2441  "Returns a role object. If the role has already existed the
     2442   existing one is returned otherwise a new one is created.
     2443   This function exists only for being used by make-construct!"
     2444  (let ((item-identifiers (getf args :item-identifiers))
     2445        (reifier (getf args :reifier))
     2446        (parent (getf args :parent))
     2447        (instance-of (getf args :instance-of))
     2448        (player (getf args :player))
     2449        (start-revision (getf args :start-revision))
     2450        (err "From make-role(): "))
     2451    (unless start-revision (error "~astart-revision must be set" err))
     2452    (unless instance-of (error "~ainstance-of must be set" err))
     2453    (unless player (error "~aplayer must be set" err))
     2454    (let ((role
     2455           (let ((existing-role
     2456                  (remove-if
     2457                   #'null
     2458                   (map 'list #'(lambda(existing-role)
     2459                                  (when (equivalent-construct
     2460                                         existing-role
     2461                                         :player player
     2462                                         :instance-of instance-of)
     2463                                    existing-role))
     2464                        (slot-p parent 'roles)))))
     2465             (if existing-role
     2466                 existing-role
     2467                 (make-instance 'RoleC)))))
     2468      (when player
     2469        (add-player role player :revision start-revision))
     2470      (initialize-typable role instance-of :start-revision start-revision)
     2471      (when parent
     2472        (add-parent role parent :revision start-revision))
     2473      (initialize-reifiable role item-identifiers reifier
     2474                            :start-revision start-revision))))
     2475
     2476
     2477(defun make-tm (args)
     2478  "Returns a topic map object. If the topic map has already existed the
     2479   existing one is returned otherwise a new one is created.
     2480   This function exists only for being used by make-construct!"
     2481  (let ((item-identifiers (getf args :item-identifiers))
     2482        (reifier (getf args :reifier))
     2483        (topics (getf args :topics))
     2484        (assocs (getf args :associations))
     2485        (start-revision (getf args :start-revision))
     2486        (err "From make-tm(): "))
     2487    (unless item-identifiers (error "~aitem-identifiers must be set" err))
     2488    (unless start-revision (error "~astart-revision must be set" err))
    24042489    (let ((tm
    24052490           (let ((existing-tms
     
    24212506      (dolist (top-or-assoc (union topics assocs))
    24222507        (add-to-tm tm top-or-assoc))
    2423       (add-to-version-history tm :start-revision start-revision)
    2424       tm)))
     2508      (initialize-reifiable tm item-identifiers reifier
     2509                            :start-revision start-revision))))
    24252510           
    24262511
     
    24292514   returned otherwise a new one is created.
    24302515   This function exists only for being used by make-construct!"
    2431   (let ((start-revision (getf (first args) :start-revision))
    2432         (psis (getf (first args) :psis))
    2433         (locators (getf (first args) :locators))
    2434         (item-identifiers (getf (first args) :item-identifiers))
    2435         (topic-identifiers (getf (first args) :topic-identifiers))
    2436         (names (getf (first args) :names))
    2437         (occurrences (getf (first args) :occurrences)))
     2516  (let ((start-revision (getf args :start-revision))
     2517        (psis (getf args :psis))
     2518        (locators (getf args :locators))
     2519        (item-identifiers (getf args :item-identifiers))
     2520        (topic-identifiers (getf args :topic-identifiers))
     2521        (names (getf args :names))
     2522        (occurrences (getf args :occurrences))
     2523        (err "From make-topic(): "))
     2524    (unless topic-identifiers (error "~atopic-identifiers must be set" err))
     2525    (unless start-revision (error "~astart-revision must be set" err))
    24382526    (let ((topic
    24392527           (let ((existing-topics
     
    24552543                   (t
    24562544                    (make-instance 'TopicC))))))
    2457       (initialize-reifiable topic item-identifiers nil
    2458                             :start-revision start-revision)
    24592545      (let ((merged-topic topic))
     2546        (setf merged-topic
     2547              (initialize-reifiable topic item-identifiers nil
     2548                                    :start-revision start-revision))
    24602549        (dolist (psi psis)
    24612550          (setf merged-topic (add-psi merged-topic psi
     
    24652554                                          :revision start-revision)))
    24662555        (dolist (name names)
    2467           (setf merged-topic (add-name topic name :revision start-revision)))
     2556          (setf merged-topic (add-name merged-topic name
     2557                                       :revision start-revision)))
    24682558        (dolist (occ occurrences)
    24692559          (add-occurrence merged-topic occ :revision start-revision))
    2470         (add-to-version-history merged-topic :start-revision start-revision)
    24712560        merged-topic))))
    24722561
     
    24852574        (variants (getf (first args) :variants))
    24862575        (reifier (getf (first args) :reifier))
    2487         (parent-construct (getf (first args) :parent-construct))
    2488         (item-identifiers (getf (first args) :item-identifiers)))
     2576        (parent (getf (first args) :parent))
     2577        (item-identifiers (getf (first args) :item-identifiers))
     2578        (err "From make-characteristic(): "))
     2579    (unless start-revision (error "~astart-revision must be set" err))
     2580    (unless charvalue (error "~acharvalue must be set" err))
     2581    (when (and (or (OccurrenceC-p class-symbol) (NameC-p class-symbol))
     2582               (not instance-of))
     2583      (error "~ainstance-of must be set" err))
    24892584    (let ((characteristic
    24902585           (let ((existing-characteristic
    2491                   (when parent-construct
     2586                  (when parent
    24922587                    (remove-if
    24932588                     #'null
     
    25002595                                           :instance-of instance-of)
    25012596                                      existing-characteristic))
    2502                           (get-all-characteristics parent-construct
    2503                                                    class-symbol))))))
     2597                          (get-all-characteristics parent class-symbol))))))
    25042598             (if existing-characteristic
    25052599                 existing-characteristic
    25062600                 (make-instance class-symbol :charvalue charvalue
    25072601                                :datatype datatype)))))
    2508       (let ((merged-characteristic characteristic))
    2509         (setf merged-characteristic
    2510               (initialize-reifiable merged-characteristic item-identifiers
    2511                                     reifier :start-revision start-revision))
    2512         (initialize-scopable merged-characteristic themes
    2513                              :start-revision start-revision)
    2514         (initialize-typable merged-characteristic instance-of
    2515                             :start-revision start-revision)
    2516         (initialize-name merged-characteristic variants
    2517                          :start-revision start-revision)
    2518         (when parent-construct
    2519           (add-parent merged-characteristic parent-construct
    2520                       :revision start-revision))
    2521         merged-characteristic))))
     2602      (initialize-scopable characteristic themes :start-revision start-revision)
     2603      (initialize-typable characteristic instance-of
     2604                          :start-revision start-revision)
     2605      (initialize-name characteristic variants :start-revision start-revision)
     2606      (when parent
     2607        (add-parent characteristic parent :revision start-revision))
     2608      (initialize-reifiable characteristic item-identifiers
     2609                            reifier :start-revision start-revision))))
    25222610
    25232611
     
    25292617        (xtm-id (getf (first args) :xtm-id))
    25302618        (start-revision (getf (first args) :start-revision))
    2531         (identified-construct (getf (first args) :identified-construct)))
     2619        (identified-construct (getf (first args) :identified-construct))
     2620        (err "From make-pointer(): "))
     2621    (when (and identified-construct (not start-revision))
     2622      (error "~astart-revision must be set" err))
    25322623    (let ((identifier
    25332624           (let ((existing-pointer
Note: See TracChangeset for help on using the changeset viewer.