]> dreyeck.freedombox.rocks Git - topic-maps.git/blobdiff - src/tmdm/items.lisp
Implement unreified Variants with Scope and canonical merging
[topic-maps.git] / src / tmdm / items.lisp
index f9142d1ff96860385ff4ec9d4bae7cb46a10fdba..c77dba5f0b43331ce8fd9b14a2ea8fa8d6d03abc 100644 (file)
@@ -3,7 +3,7 @@
 ;;; 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.
+;;; (CTM 3.2). Scope is a materialized Topic set; Variants belong to Names.
 (defstruct (topic-map (:constructor make-topic-map ()) (:conc-name %topic-map-)) topics associations)
 (defstruct (topic (:constructor %make-topic (parent)) (:conc-name %topic-))
   (parent nil :read-only t) item-identifiers subject-identifiers subject-locators names occurrences
   (value "" :type string :read-only t)
   (type nil :type topic)
   (parent nil :type topic)
-  scope forward)
+  scope variants 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 forward)
 
 (defstruct (occurrence (:constructor %make-occurrence (value datatype type parent))
                        (:conc-name %occurrence-))
@@ -46,6 +50,20 @@ 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))
 
+(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 are implicitly empty in the supported unreified Variant subset."
+  (canonical-variant item) nil)
+
 (defun canonical-association (association)
   "Resolve a retained Association handle after duplicate association merging."
   (check-type association association)
@@ -103,6 +121,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 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)))))