Changeset 231 for branches/new-datamodel
- Timestamp:
- 03/18/10 11:40:32 (15 years ago)
- Location:
- branches/new-datamodel/src
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
TabularUnified branches/new-datamodel/src/model/datamodel.lisp ¶
r228 r231 93 93 :string-integer-p 94 94 :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 95 115 96 116 ;;globals … … 99 119 100 120 (in-package :datamodel) 121 122 123 124 125 ;;TODO: check merge-constructs in add-topic-identifier, add-item-identifier, 126 ;; add-psi, add-locator 101 127 102 128 … … 109 135 ;;TODO: use some exceptions --> more than one type, 110 136 ;; identifier, not-mergable merges, missing-init-args... 111 ;;TODO: implement make-construct -> symbol112 ;; replace the latest make-construct-method113 137 ;;TODO: implement merge-construct -> ReifiableConstructC -> ... 114 138 ;; the method should merge two constructs that are inherited from … … 584 608 585 609 586 (defun make-construct (class-symbol &key start-revision &allow-other-keys)587 "Creates a new topic map construct if necessary or588 retrieves an equivalent one if available and updates the revision589 history accordingly. Returns the object in question. Methods use590 specific keyword arguments for their purpose."591 (or class-symbol start-revision)592 ;TODO: implement593 )594 595 596 597 610 (defun delete-1-n-association(instance slot-symbol) 598 611 (when (slot-p instance slot-symbol) … … 692 705 693 706 ;;; 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 694 717 (defmethod delete-construct :before ((construct VersionedConstructC)) 695 718 (dolist (version-info (versions construct)) … … 787 810 788 811 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 789 822 ;;; 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 790 835 (defmethod equivalent-construct ((construct PointerC) 791 836 &key start-revision (uri "")) … … 818 863 819 864 ;;; 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 820 872 (defmethod equivalent-construct ((construct TopicIdentificationC) 821 873 &key start-revision (uri "") (xtm-id "")) … … 829 881 830 882 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 831 914 ;;; PointerAssociationC 832 915 (defmethod delete-construct :before ((construct PointerAssociationC)) … … 905 988 906 989 ;;; 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 907 996 (defmethod equivalent-construct ((construct TopicC) 908 997 &key (start-revision 0) (psis nil) … … 1363 1452 1364 1453 ;;; 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 1365 1464 (defmethod equivalent-construct ((construct CharacteristicC) 1366 1465 &key (start-revision 0) (reifier nil) … … 1455 1554 1456 1555 ;;; 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 1457 1562 (defmethod equivalent-construct ((construct OccurrenceC) 1458 1563 &key (start-revision 0) (reifier nil) … … 1473 1578 1474 1579 ;;; 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 1475 1586 (defmethod equivalent-construct ((construct VariantC) 1476 1587 &key (start-revision 0) (reifier nil) … … 1490 1601 1491 1602 ;;; 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 1492 1609 (defmethod equivalent-construct ((construct NameC) 1493 1610 &key (start-revision 0) (reifier nil) … … 1562 1679 1563 1680 ;;; 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 1564 1687 (defmethod equivalent-construct ((construct AssociationC) 1565 1688 &key (start-revision 0) (reifier nil) … … 1646 1769 1647 1770 ;;; 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 1648 1777 (defmethod equivalent-construct ((construct RoleC) 1649 1778 &key (start-revision 0) (reifier nil) … … 1783 1912 1784 1913 ;;; 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 1785 1926 (defgeneric equivalent-reifiable-construct (construct reifier item-identifiers 1786 1927 &key start-revision) … … 1925 2066 1926 2067 ;;; 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 1927 2078 (defgeneric equivalent-typable-construct (construct instance-of 1928 2079 &key start-revision) … … 1936 2087 1937 2088 ;;; 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 1938 2098 (defgeneric equivalent-scopable-construct (construct themes &key start-revision) 1939 2099 (:documentation "Returns t if the passed constructs are TMDM equal, i.e. … … 2066 2226 2067 2227 ;;; 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 2068 2234 (defmethod equivalent-construct ((construct TopicMapC) 2069 2235 &key (start-revision 0) (reifier nil) … … 2114 2280 2115 2281 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 2119 2359 2120 2360 -
TabularUnified branches/new-datamodel/src/unit_tests/datamodel_test.lisp ¶
r228 r231 58 58 :test-equivalent-AssociationC 59 59 :test-equivalent-TopicC 60 :test-equivalent-TopicMapC)) 60 :test-equivalent-TopicMapC 61 :test-class-p)) 61 62 62 63 … … 1644 1645 1645 1646 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 1646 1702 (defun run-datamodel-tests() 1647 1703 "Runs all tests of this test-suite." … … 1684 1740 (it.bese.fiveam:run! 'test-equivalent-TopicC) 1685 1741 (it.bese.fiveam:run! 'test-equivalent-TopicMapC) 1742 (it.bese.fiveam:run! 'test-class-p) 1686 1743 )
Note: See TracChangeset
for help on using the changeset viewer.