+(defun relationship-keyword-p (token)
+ (and (eq :identifier (token-kind token)) (member (token-value token) '("isa" "ako") :test #'string=)))
+
+(defun read-type-relationship (parser map topic)
+ "CTM 3.9: expand one isa/ako statement using ordinary same-map Associations."
+ (let* ((keyword (consume parser)) (isa (string= (token-value keyword) "isa")) (next (look parser)))
+ (unless (and (topic-reference-start-p next)
+ (not (and (eq :identifier (token-kind next))
+ (member (token-value next) '("isa" "ako" "def" "end") :test #'string=))))
+ (problem 'ctm-rejection :expected-relationship-topic (token-position next)
+ "Expected one Topic reference after isa or ako."))
+ (let ((target (topic-reference parser map)))
+ (when (punctuation-p parser #\,)
+ (problem 'ctm-rejection :unexpected-relationship-list (token-position (look parser))
+ "isa/ako takes one Topic reference; repeat the keyword in a separate tail element."))
+ (handler-case
+ (flet ((core (local)
+ ;; Resolve locators every time; do not cache replaceable Topic objects.
+ (topic-maps.tmdm:intern-topic map :subject-identifier
+ (concatenate 'string "http://psi.topicmaps.org/iso13250/model/" local))))
+ (let* ((type (core (if isa "type-instance" "supertype-subtype")))
+ (left (core (if isa "instance" "subtype"))) (right (core (if isa "type" "supertype"))))
+ (topic-maps.tmdm:make-association map type (list (list left topic) (list right target)))
+ (topic-maps.tmdm:canonical-topic topic)))
+ (topic-maps.tmdm:core-subject-error (c)
+ (problem 'ctm-rejection (topic-maps.tmdm:core-subject-error-code c)
+ (token-position keyword) (princ-to-string c)))))))
+