]> dreyeck.freedombox.rocks Git - topic-maps.git/blob - src/tmdm/core-subjects.lisp
Implement XTM association and role core with original conformance evidence
[topic-maps.git] / src / tmdm / core-subjects.lisp
1 (in-package #:topic-maps.tmdm)
2
3 ;; TMDM 2006, 7.1-7.5. These are locator constants, not a second Topic registry.
4 ;; In particular 7.5's NAME-TYPE is not silently equated to CTM 3.11's
5 ;; TOPIC-NAME locator; the existing CTM default-name mapping is unchanged.
6 (defparameter *core-subject-identifiers*
7 (mapcar (lambda (local) (concatenate 'string "http://psi.topicmaps.org/iso13250/model/" local))
8 '("type-instance" "type" "instance" "supertype-subtype" "supertype" "subtype" "sort" "name-type")))
9
10 (defun core-subject-identifiers ()
11 "Return fresh locator strings for the eight Core Subjects of TMDM 2006, 7."
12 (mapcar #'copy-seq *core-subject-identifiers*))
13 (define-condition core-subject-error (error)
14 ((code :initarg :code :reader core-subject-error-code)
15 (detail :initarg :detail :reader core-subject-error-detail))
16 (:report (lambda (c out) (format out "Core Subject ~A: ~A" (core-subject-error-code c)
17 (core-subject-error-detail c)))))
18 (defun check-core-subject-identifiers (identifiers)
19 (let ((core (remove-duplicates
20 (intersection identifiers *core-subject-identifiers* :test #'string=) :test #'string=)))
21 (when (rest core)
22 (error 'core-subject-error :code :core-subject-conflict
23 :detail (format nil "TMDM 7.1: distinct Core Subjects cannot share a Topic: ~{~A~^, ~}." core))))
24 t)
25 (defun map-has-core-subject-p (map)
26 (some (lambda (topic) (intersection (%topic-subject-identifiers topic) *core-subject-identifiers* :test #'string=))
27 (%topic-map-topics map)))
28 (defun validate-map-core-subjects (map)
29 "Check stored Subject Identifiers without merging or mutating any item."
30 (dolist (topic (%topic-map-topics map)) (check-core-subject-identifiers (%topic-subject-identifiers topic)))
31 t)