Changeset 231 for branches/new-datamodel


Ignore:
Timestamp:
03/18/10 11:40:32 (15 years ago)
Author:
lgiessmann
Message:

new-datamodel: added the helper function "make-pointer" for "make-construct"; added the generics <class>-p to all class-symbols and a unit-test fort these methods.

Location:
branches/new-datamodel/src
Files:
2 edited

Legend:

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

    r228 r231  
    9393           :string-integer-p
    9494           :with-revision
     95           :PointerC-p
     96           :IdentifierC-p
     97           :SubjectLocatorC-p
     98           :PersistentIdC-p
     99           :ItemIdentifierC-p
     100           :TopicIdentificationC-p
     101           :CharacteristicC-p
     102           :OccurrenceC-p
     103           :NameC-p
     104           :VariantC-p
     105           :ScopableC-p
     106           :TypableC-p
     107           :TopicC-p
     108           :AssociationC-p
     109           :RoleC-p
     110           :TopicMapC-p
     111           :ReifiableConstructC-p
     112           :TopicMapConstructC-p
     113           :VersionedConstructC-p
     114           :make-construct
    95115
    96116           ;;globals
     
    99119
    100120(in-package :datamodel)
     121
     122
     123
     124
     125;;TODO: check merge-constructs in add-topic-identifier, add-item-identifier,
     126;;      add-psi, add-locator
    101127
    102128
     
    109135;;TODO: use some exceptions --> more than one type,
    110136;;      identifier, not-mergable merges, missing-init-args...
    111 ;;TODO: implement make-construct -> symbol
    112 ;;      replace the latest make-construct-method
    113137;;TODO: implement merge-construct -> ReifiableConstructC -> ...
    114138;;      the method should merge two constructs that are inherited from
     
    584608
    585609
    586 (defun make-construct (class-symbol &key start-revision &allow-other-keys)
    587   "Creates a new topic map construct if necessary or
    588    retrieves an equivalent one if available and updates the revision
    589    history accordingly. Returns the object in question. Methods use
    590    specific keyword arguments for their purpose."
    591   (or class-symbol start-revision)
    592   ;TODO: implement
    593   )
    594 
    595 
    596 
    597610(defun delete-1-n-association(instance slot-symbol)
    598611  (when (slot-p instance slot-symbol)
     
    692705
    693706;;; VersionedConstructC
     707(defgeneric VersionedConstructC-p (class-symbol)
     708  (:documentation "Returns t if the passed class is equal to VersionedConstructC
     709                   or one of its subtypes.")
     710  (:method ((class-symbol symbol))
     711    (or (eql class-symbol 'VersionedconstructC)
     712        (TopicC-p class-symbol)
     713        (TopicMapC-p class-symbol)
     714        (AssociationC-p class-symbol))))
     715
     716
    694717(defmethod delete-construct :before ((construct VersionedConstructC))
    695718  (dolist (version-info (versions construct))
     
    787810 
    788811
     812;;; TopicMapconstructC
     813(defgeneric TopicMapConstructC-p (class-symbol)
     814  (:documentation "Returns t if the passed class is equal to TopicMapConstructC
     815                   or one of its subtypes.")
     816  (:method ((class-symbol symbol))
     817    (or (eql class-symbol 'TopicMapConstructC)
     818        (ReifiableConstructC-p class-symbol)
     819        (PointerC-p class-symbol))))
     820
     821
    789822;;; PointerC
     823(defgeneric PointerC-p (class-symbol)
     824  (:documentation "Returns t if the passed symbol corresponds to the class
     825                   PointerC or one of its subclasses.")
     826  (:method ((class-symbol symbol))
     827    (or (eql class-symbol 'PointerC)
     828        (IdentifierC-p class-symbol)
     829        (TopicIdentificationC-p class-symbol)
     830        (PersistentIdC-p class-symbol)
     831        (ItemIdentifierC-p class-symbol)
     832        (SubjectLocatorC-p class-symbol))))
     833
     834
    790835(defmethod equivalent-construct ((construct PointerC)
    791836                                 &key start-revision (uri ""))
     
    818863
    819864;;; TopicIdentificationC
     865(defgeneric TopicIdentificationC-p (class-symbol)
     866  (:documentation "Returns t if the passed class symbol is equal
     867                   to TopicIdentificationC.")
     868  (:method ((class-symbol symbol))
     869    (eql class-symbol 'TopicIdentificationC)))
     870
     871
    820872(defmethod equivalent-construct ((construct TopicIdentificationC)
    821873                                 &key start-revision (uri "") (xtm-id ""))
     
    829881
    830882
     883;;; IdentifierC
     884(defgeneric IdentifierC-p (class-symbol)
     885  (:documentation "Returns t if the passed symbol is equal to IdentifierC
     886                   or one of its sybtypes.")
     887  (:method ((class-symbol symbol))
     888    (or (eql class-symbol 'IdentifierC)
     889        (PersistentIdC-p class-symbol)
     890        (SubjectLocatorC-p class-symbol)
     891        (ItemIdentifierC-p class-symbol))))
     892
     893
     894;;; PersistentIdC
     895(defgeneric PersistentIdC-p (class-symbol)
     896  (:documentation "Returns t if the passed symbol is equal to PersistentIdC.")
     897  (:method ((class-symbol symbol))
     898    (eql class-symbol 'PersistentIdC)))
     899
     900
     901;;; ItemIdentifierC
     902(defgeneric ItemIdentifierC-p (class-symbol)
     903  (:documentation "Returns t if the passed symbol is equal to ItemIdentifierC.")
     904  (:method ((class-symbol symbol))
     905    (eql class-symbol 'ItemIdentifierC)))
     906
     907;;; SubjectLocatorC
     908(defgeneric SubjectLocatorC-p (class-symbol)
     909  (:documentation "Returns t if the passed symbol is equal to SubjectLocatorC.")
     910  (:method ((class-symbol symbol))
     911    (eql class-symbol 'SubjectLocatorC)))
     912
     913
    831914;;; PointerAssociationC
    832915(defmethod delete-construct :before ((construct PointerAssociationC))
     
    905988
    906989;;; TopicC
     990(defgeneric TopicC-p (class-symbol)
     991  (:documentation "Returns t if the passed symbol is equal to TopicC.")
     992  (:method ((class-symbol symbol))
     993    (eql class-symbol 'TopicC)))
     994
     995
    907996(defmethod equivalent-construct ((construct TopicC)
    908997                                 &key (start-revision 0) (psis nil)
     
    13631452
    13641453;;; CharacteristicC
     1454(defgeneric CharacteristicC-p (class-symbol)
     1455  (:documentation "Returns t if the passed symbol is equal to CharacteristicC
     1456                   or one of its subtypes.")
     1457  (:method ((class-symbol symbol))
     1458    (or (eql class-symbol 'CharacteristicC)
     1459        (OccurrenceC-p class-symbol)
     1460        (NameC-p class-symbol)
     1461        (VariantC-p class-symbol))))
     1462
     1463
    13651464(defmethod equivalent-construct ((construct CharacteristicC)
    13661465                                 &key (start-revision 0) (reifier nil)
     
    14551554
    14561555;;; OccurrenceC
     1556(defgeneric OccurrenceC-p (class-symbol)
     1557  (:documentation "Returns t if the passed symbol is equal to OccurrenceC.")
     1558  (:method ((class-symbol symbol))
     1559    (eql class-symbol 'OccurrenceC)))
     1560
     1561
    14571562(defmethod equivalent-construct ((construct OccurrenceC)
    14581563                                 &key (start-revision 0) (reifier nil)
     
    14731578
    14741579;;; VariantC
     1580(defgeneric VariantC-p (class-symbol)
     1581  (:documentation "Returns t if the passed symbol is equal to VariantC.")
     1582  (:method ((class-symbol symbol))
     1583    (eql class-symbol 'VariantC)))
     1584
     1585
    14751586(defmethod equivalent-construct ((construct VariantC)
    14761587                                 &key (start-revision 0) (reifier nil)
     
    14901601
    14911602;;; NameC
     1603(defgeneric NameC-p (class-symbol)
     1604  (:documentation "Returns t if the passed symbol is equal to Name.")
     1605  (:method ((class-symbol symbol))
     1606    (eql class-symbol 'NameC)))
     1607
     1608
    14921609(defmethod equivalent-construct ((construct NameC)
    14931610                                 &key (start-revision 0) (reifier nil)
     
    15621679
    15631680;;; AssociationC
     1681(defgeneric AssociationC-p (class-symbol)
     1682  (:documentation "Returns t if the passed symbol is equal to AssociationC.")
     1683  (:method ((class-symbol symbol))
     1684    (eql class-symbol 'AssociationC)))
     1685
     1686
    15641687(defmethod equivalent-construct ((construct AssociationC)
    15651688                                 &key (start-revision 0) (reifier nil)
     
    16461769
    16471770;;; RoleC
     1771(defgeneric RoleC-p (class-symbol)
     1772  (:documentation "Returns t if the passed symbol is equal to RoleC.")
     1773  (:method ((class-symbol symbol))
     1774    (eql class-symbol 'RoleC)))
     1775
     1776
    16481777(defmethod equivalent-construct ((construct RoleC)
    16491778                                &key (start-revision 0) (reifier nil)
     
    17831912
    17841913;;; ReifiableConstructC
     1914(defgeneric ReifiableConstructC-p (class-symbol)
     1915  (:documentation "Returns t if the passed symbol is equal to ReifiableConstructC
     1916                   or one of its subtypes.")
     1917  (:method ((class-symbol symbol))
     1918    (or (eql class-symbol 'ReifiableconstructC)
     1919        (TopicMapC-p class-symbol)
     1920        (TopicC-p class-symbol)
     1921        (AssociationC-p class-symbol)
     1922        (RoleC-p class-symbol)
     1923        (CharacteristicC-p class-symbol))))
     1924
     1925
    17851926(defgeneric equivalent-reifiable-construct (construct reifier item-identifiers
    17861927                                                      &key start-revision)
     
    19252066
    19262067;;; TypableC
     2068(defgeneric TypableC-p (class-symbol)
     2069  (:documentation "Returns t if the passed class is equal to TypableC or
     2070                   one of its subtypes.")
     2071  (:method ((class-symbol symbol))
     2072    (or (eql class-symbol 'TypableC)
     2073        (AssociationC-p class-symbol)
     2074        (RoleC-p class-symbol)
     2075        (CharacteristicC-p class-symbol))))
     2076
     2077
    19272078(defgeneric equivalent-typable-construct (construct instance-of
    19282079                                                     &key start-revision)
     
    19362087
    19372088;;; ScopableC
     2089(defgeneric ScopableC-p (class-symbol)
     2090  (:documentation "Returns t if the passed class is equal to ScopableC or
     2091                   one of its subtypes.")
     2092  (:method ((class-symbol symbol))
     2093    (or (eql class-symbol 'ScopableC)
     2094        (AssociationC-p class-symbol)
     2095        (CharacteristicC-p class-symbol))))
     2096
     2097
    19382098(defgeneric equivalent-scopable-construct (construct themes &key start-revision)
    19392099  (:documentation "Returns t if the passed constructs are TMDM equal, i.e.
     
    20662226
    20672227;;; TopicMapC
     2228(defgeneric TopicMapC-p (class-symbol)
     2229  (:documentation "Returns t if the passed symbol is equal to TopicMapC.")
     2230  (:method ((class-symbol symbol))
     2231    (eql class-symbol 'TopicMapC)))
     2232
     2233
    20682234(defmethod equivalent-construct ((construct TopicMapC)
    20692235                                 &key (start-revision 0) (reifier nil)
     
    21142280
    21152281
    2116 
    2117 
    2118 
     2282;;; make-construct ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
     2283(defun make-construct (class-symbol &rest args)
     2284  "Creates a new topic map construct if necessary or
     2285   retrieves an equivalent one if available and updates the revision
     2286   history accordingly. Returns the object in question. Methods use
     2287   specific keyword arguments for their purpose."
     2288  (declare (symbol class-symbol))
     2289  (let ((start-revision (getf args :start-revision))
     2290        (uri (getf args :uri))
     2291        (xtm-id (getf args :xtm-id))
     2292        (identified-construct (getf args :identified-construct)))
     2293    (let ((construct
     2294           (cond
     2295             ((PointerC-p class-symbol)
     2296              (make-pointer class-symbol uri :start-revision start-revision
     2297                            :xtm-id xtm-id
     2298                            :identified-construct identified-construct)))))
     2299
     2300      construct)))
     2301
     2302
     2303
     2304(defun make-pointer (class-symbol uri
     2305                     &key (start-revision *TM-REVISION*) (xtm-id nil)
     2306                     (identified-construct nil))
     2307  "Returns a pointer object with the specified parameters."
     2308  (declare (symbol class-symbol) (string uri) (integer start-revision)
     2309           (type (or null string) xtm-id)
     2310           (type (or null ReifiableconstructC)))
     2311  (let ((identifier
     2312         (let ((existing-pointer
     2313                (remove-if
     2314                 #'null
     2315                 (map 'list
     2316                      #'(lambda(existing-pointer)
     2317                          (when (equivalent-construct existing-pointer :uri uri
     2318                                                      :xtm-id xtm-id)
     2319                            existing-pointer))
     2320                      (elephant:get-instances-by-value class-symbol 'd::uri uri)))))
     2321           (if existing-pointer existing-pointer
     2322               (make-instance class-symbol :uri uri :xtm-id xtm-id)))))
     2323    (when identified-construct
     2324      (cond ((TopicIdentificationC-p class-symbol)
     2325             (add-topic-identifier identified-construct identifier
     2326                                   :revision start-revision))
     2327            ((PersistentIdC-p class-symbol)
     2328             (add-psi identified-construct identifier :revision start-revision))
     2329            ((ItemIdentifierC-p class-symbol)
     2330             (add-item-identifier identified-construct identifier
     2331                                  :revision start-revision))
     2332            ((SubjectLocatorC-p class-symbol)
     2333             (add-locator identified-construct identifier
     2334                          :revision start-revision))))
     2335    identifier))
     2336                     
     2337           
     2338                     
     2339
     2340
     2341
     2342
     2343
     2344
     2345
     2346
     2347
     2348
     2349
     2350
     2351
     2352
     2353
     2354
     2355
     2356
     2357
     2358       
    21192359
    21202360
  • TabularUnified branches/new-datamodel/src/unit_tests/datamodel_test.lisp

    r228 r231  
    5858           :test-equivalent-AssociationC
    5959           :test-equivalent-TopicC
    60            :test-equivalent-TopicMapC))
     60           :test-equivalent-TopicMapC
     61           :test-class-p))
    6162
    6263
     
    16441645
    16451646
     1647(test test-class-p ()
     1648  "Tests the functions <class>-p."
     1649  (let ((identifier (list 'd::IdentifierC 'd::ItemIdentifierC 'd:PersistentIdC
     1650                          'd:SubjectLocatorC))
     1651        (topic-identifier (list 'd::TopicIdentificationC))
     1652        (characteristic (list 'd::CharacteristicC 'd:OccurrenceC 'd:NameC
     1653                              'd:VariantC))
     1654        (topic (list 'd:TopicC))
     1655        (assoc (list 'd:AssociationC))
     1656        (role (list 'd:AssociationC))
     1657        (tm (list 'd:TopicMapC)))
     1658    (let ((pointer (append identifier topic-identifier))
     1659          (reifiable (append topic assoc role tm characteristic))
     1660          (typable (append characteristic assoc role))
     1661          (scopable (append characteristic assoc)))
     1662  (dolist (class pointer)
     1663    (is-true (d:PointerC-p class)))
     1664  (dolist (class identifier)
     1665    (is-true (d:IdentifierC-p class)))
     1666  (dolist (class topic-identifier)
     1667    (is-true (d:TopicIdentificationC-p class)))
     1668  (is-true (d:PersistentIdC-p 'd:PersistentIdC))
     1669  (is-true (d:SubjectLocatorC-p 'd:SubjectLocatorC))
     1670  (is-true (d:ItemIdentifierC-p 'd:ItemIdentifierC))
     1671  (dolist (class characteristic)
     1672    (is-true (d:CharacteristicC-p class)))
     1673  (is-true (d:OccurrenceC-p 'd:OccurrenceC))
     1674  (is-true (d:VariantC-p 'd:VariantC))
     1675  (is-true (d:NameC-p 'd:NameC))
     1676  (is-true (d:RoleC-p 'd:RoleC))
     1677  (is-true (d:AssociationC-p 'd:AssociationC))
     1678  (is-true (d:TopicC-p 'd:TopicC))
     1679  (is-true (d:TopicMapC-p 'd:TopicMapC))
     1680  (dolist (class reifiable)
     1681    (is-true (d:ReifiableconstructC-p class)))
     1682  (dolist (class scopable)
     1683    (is-true (d:ScopableC-p class)))
     1684  (dolist (class typable)
     1685    (is-true (d:TypableC-p class)))
     1686  (dolist (class (append reifiable pointer))
     1687    (is-true (d:TopicMapConstructC-p class)))
     1688  (dolist (class (append topic tm assoc))
     1689    (is-true (d:VersionedConstructC-p class)))
     1690  (dolist (class identifier)
     1691    (is-false (d:TopicIdentificationC-p class)))
     1692  (dolist (class topic-identifier)
     1693    (is-false (d:IdentifierC-p class)))
     1694  (dolist (class characteristic)
     1695    (is-false (d:PointerC-p class))))))
     1696
     1697
     1698
     1699
     1700
     1701
    16461702(defun run-datamodel-tests()
    16471703  "Runs all tests of this test-suite."
     
    16841740  (it.bese.fiveam:run! 'test-equivalent-TopicC)
    16851741  (it.bese.fiveam:run! 'test-equivalent-TopicMapC)
     1742  (it.bese.fiveam:run! 'test-class-p)
    16861743  )
Note: See TracChangeset for help on using the changeset viewer.