]> dreyeck.freedombox.rocks Git - topic-maps.git/blobdiff - src/tmdm/items.lisp
Qualify pinned CXML encodings with reproducible local patches
[topic-maps.git] / src / tmdm / items.lisp
index f9142d1ff96860385ff4ec9d4bae7cb46a10fdba..f4871a75643f8f245a068a7eeba984c537667293 100644 (file)
@@ -1,30 +1,32 @@
 (in-package #:topic-maps.tmdm)
 
 (in-package #:topic-maps.tmdm)
 
-;;; Only Topic Map, Topic, Name/Occurrence, Association and Role properties used
-;;; by the current subset are materialized.
-;;; Omitted set-valued properties are implicitly empty, single-valued ones null
-;;; (CTM 3.2). Variants remain implicitly empty; Scope is a materialized Topic set.
-(defstruct (topic-map (:constructor make-topic-map ()) (:conc-name %topic-map-)) topics associations)
+;;; All seven information items carry Item Identifier sets (TMDM 5.1-5.8).
+;;; Reifier belongs to non-Topic constructs; Topic Reified is computed.
+(defstruct (topic-map (:constructor make-topic-map ()) (:conc-name %topic-map-)) topics associations item-identifiers reifier)
 (defstruct (topic (:constructor %make-topic (parent)) (:conc-name %topic-))
   (parent nil :read-only t) item-identifiers subject-identifiers subject-locators names occurrences
   ;; Implementation bookkeeping, not a TMDM property or another information item.
   forward)
 
 (defstruct (association (:constructor %make-association (parent type)) (:conc-name %association-))
 (defstruct (topic (:constructor %make-topic (parent)) (:conc-name %topic-))
   (parent nil :read-only t) item-identifiers subject-identifiers subject-locators names occurrences
   ;; Implementation bookkeeping, not a TMDM property or another information item.
   forward)
 
 (defstruct (association (:constructor %make-association (parent type)) (:conc-name %association-))
-  (parent nil :type topic-map :read-only t) (type nil :type topic) roles scope forward)
+  (parent nil :type topic-map :read-only t) (type nil :type topic) roles scope item-identifiers reifier forward)
 (defstruct (association-role (:constructor %make-association-role (parent type player))
                             (:conc-name %association-role-))
 (defstruct (association-role (:constructor %make-association-role (parent type player))
                             (:conc-name %association-role-))
-  (parent nil :type association) (type nil :type topic) (player nil :type topic) forward)
+  (parent nil :type association) (type nil :type topic) (player nil :type topic) item-identifiers reifier forward)
 (defstruct (topic-name (:constructor %make-topic-name (value type parent)) (:conc-name %topic-name-))
   (value "" :type string :read-only t)
   (type nil :type topic)
   (parent nil :type topic)
 (defstruct (topic-name (:constructor %make-topic-name (value type parent)) (:conc-name %topic-name-))
   (value "" :type string :read-only t)
   (type nil :type topic)
   (parent nil :type topic)
-  scope forward)
+  scope variants item-identifiers reifier forward)
+
+(defstruct (variant (:constructor %make-variant (value datatype parent)) (:conc-name %variant-))
+  (value "" :type string :read-only t) (datatype "" :type string :read-only t)
+  (parent nil :type topic-name) scope item-identifiers reifier forward)
 
 (defstruct (occurrence (:constructor %make-occurrence (value datatype type parent))
                        (:conc-name %occurrence-))
   (value "" :type string :read-only t) (datatype "" :type string :read-only t)
 
 (defstruct (occurrence (:constructor %make-occurrence (value datatype type parent))
                        (:conc-name %occurrence-))
   (value "" :type string :read-only t) (datatype "" :type string :read-only t)
-  (type nil :type topic) (parent nil :type topic) item-identifiers scope forward)
+  (type nil :type topic) (parent nil :type topic) item-identifiers scope reifier forward)
 
 (defun canonical-occurrence (occurrence)
   "Resolve a retained Occurrence replaced by TMDM duplicate removal; no compression."
 
 (defun canonical-occurrence (occurrence)
   "Resolve a retained Occurrence replaced by TMDM duplicate removal; no compression."
@@ -46,6 +48,19 @@ EQ on obsolete objects does not change; compare their canonical representatives.
   (loop for current = name then (%topic-name-forward current)
         unless (%topic-name-forward current) return current))
 
   (loop for current = name then (%topic-name-forward current)
         unless (%topic-name-forward current) return current))
 
+(defun canonical-variant (item)
+  "Resolve a retained Variant replaced by duplicate removal, without mutation."
+  (check-type item variant)
+  (loop for current = item then (%variant-forward current)
+        unless (%variant-forward current) return current))
+(defun topic-name-variants (name) (copy-list (%topic-name-variants (canonical-topic-name name))))
+(defun variant-value (item) (%variant-value (canonical-variant item)))
+(defun variant-datatype (item) (%variant-datatype (canonical-variant item)))
+(defun variant-parent (item) (%variant-parent (canonical-variant item)))
+(defun variant-scope (item) (copy-list (%variant-scope (canonical-variant item))))
+(defun variant-item-identifiers (item)
+  (item-identifiers (canonical-variant item)))
+
 (defun canonical-association (association)
   "Resolve a retained Association handle after duplicate association merging."
   (check-type association association)
 (defun canonical-association (association)
   "Resolve a retained Association handle after duplicate association merging."
   (check-type association association)
@@ -62,7 +77,11 @@ EQ on obsolete objects does not change; compare their canonical representatives.
 (defun topic-map-topics (map) (copy-list (%topic-map-topics map)))
 (defun topic-map-associations (map) (copy-list (%topic-map-associations map)))
 (defun topic-parent (topic) (%topic-parent (canonical-topic topic)))
 (defun topic-map-topics (map) (copy-list (%topic-map-topics map)))
 (defun topic-map-associations (map) (copy-list (%topic-map-associations map)))
 (defun topic-parent (topic) (%topic-parent (canonical-topic topic)))
-(defun topic-item-identifiers (topic) (copy-list (%topic-item-identifiers (canonical-topic topic))))
+(defun topic-item-identifiers (topic) (item-identifiers (canonical-topic topic)))
+(defun topic-map-item-identifiers (map) (check-type map topic-map) (item-identifiers map))
+(defun topic-name-item-identifiers (name) (item-identifiers (canonical-topic-name name)))
+(defun association-item-identifiers (item) (item-identifiers (canonical-association item)))
+(defun association-role-item-identifiers (item) (item-identifiers (canonical-association-role item)))
 (defun topic-subject-identifiers (topic) (copy-list (%topic-subject-identifiers (canonical-topic topic))))
 (defun topic-subject-locators (topic) (copy-list (%topic-subject-locators (canonical-topic topic))))
 (defun topic-names (topic) (copy-list (%topic-names (canonical-topic topic))))
 (defun topic-subject-identifiers (topic) (copy-list (%topic-subject-identifiers (canonical-topic topic))))
 (defun topic-subject-locators (topic) (copy-list (%topic-subject-locators (canonical-topic topic))))
 (defun topic-names (topic) (copy-list (%topic-names (canonical-topic topic))))
@@ -71,7 +90,7 @@ EQ on obsolete objects does not change; compare their canonical representatives.
 (defun occurrence-datatype (item) (%occurrence-datatype (canonical-occurrence item)))
 (defun occurrence-parent (item) (%occurrence-parent (canonical-occurrence item)))
 (defun occurrence-type (item) (%occurrence-type (canonical-occurrence item)))
 (defun occurrence-datatype (item) (%occurrence-datatype (canonical-occurrence item)))
 (defun occurrence-parent (item) (%occurrence-parent (canonical-occurrence item)))
 (defun occurrence-type (item) (%occurrence-type (canonical-occurrence item)))
-(defun occurrence-item-identifiers (item) (copy-list (%occurrence-item-identifiers (canonical-occurrence item))))
+(defun occurrence-item-identifiers (item) (item-identifiers (canonical-occurrence item)))
 (defun topic-name-value (name) (%topic-name-value (canonical-topic-name name)))
 (defun topic-name-type (name) (%topic-name-type (canonical-topic-name name)))
 (defun topic-name-scope (name) (copy-list (%topic-name-scope (canonical-topic-name name))))
 (defun topic-name-value (name) (%topic-name-value (canonical-topic-name name)))
 (defun topic-name-type (name) (%topic-name-type (canonical-topic-name name)))
 (defun topic-name-scope (name) (copy-list (%topic-name-scope (canonical-topic-name name))))
@@ -103,6 +122,9 @@ EQ on obsolete objects does not change; compare their canonical representatives.
 (defmethod print-object ((item topic-name) stream)
   (print-unreadable-object (item stream :type t :identity t)
     (format stream "~S" (topic-name-value item))))
 (defmethod print-object ((item topic-name) stream)
   (print-unreadable-object (item stream :type t :identity t)
     (format stream "~S" (topic-name-value item))))
+(defmethod print-object ((item variant) stream)
+  (print-unreadable-object (item stream :type t :identity t)
+    (format stream "~S datatype=~S" (variant-value item) (variant-datatype item))))
 (defmethod print-object ((item association) stream)
   (print-unreadable-object (item stream :type t :identity t)
     (format stream "~D roles" (length (association-roles item)))))
 (defmethod print-object ((item association) stream)
   (print-unreadable-object (item stream :type t :identity t)
     (format stream "~D roles" (length (association-roles item)))))