]> dreyeck.freedombox.rocks Git - topic-maps.git/blobdiff - src/tmdm/associations.lisp
Implement Topic-set Scope across TMDM, CTM and CXTM
[topic-maps.git] / src / tmdm / associations.lisp
index 4c48c089b58f3915e6e81575f538ecc43e5a7f47..caaf0215dee2872a6ae702fca98c0880f2645a85 100644 (file)
@@ -16,8 +16,9 @@
 (defun equal-associations-p (a b)
   ;; TMDM 5.7: compare role sets structurally, independent of role ordering.
   ;; Role parents are the associations being compared (the equality cycle).
-  ;; Scope is empty and reifier/II are absent in this subset.
+  ;; Scope sets are significant; reifier/II are absent in this subset.
   (and (eq (%association-type a) (%association-type b))
+       (same-scope-p (%association-scope a) (%association-scope b))
        (= (length (%association-roles a)) (length (%association-roles b)))
        (every (lambda (role) (find role (%association-roles b) :test #'same-role-signature-p))
               (%association-roles a))))
@@ -26,7 +27,8 @@
   ;; TMDM 6.6: C receives A's equal role set. Retarget parent and discarded
   ;; equivalent B-role handles, so clients cannot observe stale live references.
   (let ((c (%make-association map (%association-type a))))
-    (setf (%association-roles c) (copy-list (%association-roles a))
+    (setf (%association-scope c) (copy-list (%association-scope a))
+          (%association-roles c) (copy-list (%association-roles a))
           (%topic-map-associations map) (replace-pair (%topic-map-associations map) a b c)
           (%association-forward a) c (%association-forward b) c)
     (dolist (role (%association-roles c)) (setf (%association-role-parent role) c))
         while pair do (merge-two-associations map (first pair) (second pair)))
   map)
 
-(defun make-association (map type roles)
-  "Create a same-map unscoped Association. ROLES is a nonempty list of (TYPE PLAYER).
+(defun make-association (map type roles &key scope)
+  "Create a same-map Association with a Scope Topic set. ROLES is a nonempty list of (TYPE PLAYER).
 All references are validated before mutation and resolved to live Topics.
 Return its current representative after duplicate normalization."
   (check-type map topic-map)
-  (let ((type (live-topic type)))
+  (let ((type (live-topic type)) (scope (canonical-scope map scope)))
     (unless (eq map (%topic-parent type)) (error "Association type belongs to another map."))
-    (unless (and (listp roles) roles) (error "An Association requires at least one Role."))
+    (unless (and (proper-list-p roles) roles) (error "An Association requires at least one Role."))
     (let ((references
             (mapcar (lambda (pair)
-                      (unless (and (listp pair) (= 2 (length pair)))
+                      (unless (and (proper-list-p pair) (= 2 (length pair)))
                         (error "Each Role requires a type and a player."))
                       (let ((type (live-topic (first pair))) (player (live-topic (second pair))))
                         (unless (and (eq map (%topic-parent type)) (eq map (%topic-parent player)))
                           (error "Role type and player must belong to the Association's map."))
                         (list type player))) roles)))
       (let ((association (%make-association map type)))
-        (setf (%association-roles association)
+        (setf (%association-scope association) scope
+              (%association-roles association)
               (mapcar (lambda (pair) (%make-association-role association (first pair) (second pair))) references)
               (%topic-map-associations map) (append (%topic-map-associations map) (list association)))
         (normalize-associations map)