(and (or (char<= #\a (char head 0) #\z) (char<= #\A (char head 0) #\Z))
(every (lambda (c) (or (char<= #\a c #\z) (char<= #\A c #\Z)
(char<= #\0 c #\9) (find c "+-."))) head)))))))
(and (or (char<= #\a (char head 0) #\z) (char<= #\A (char head 0) #\Z))
(every (lambda (c) (or (char<= #\a c #\z) (char<= #\A c #\Z)
(char<= #\0 c #\9) (find c "+-."))) head)))))))
-(defun same-occurrence-properties-p (a value datatype type)
- ;; Parent is the containing topic; scope is empty throughout this subset.
+(defun same-occurrence-properties-p (a value datatype type scope)
+ ;; Parent is the containing topic; Scope is compared as a Topic set.
(defun check-topic-occurrence-identifiers (map kind iri)
(when (member kind '(:item-identifier :subject-identifier))
(dolist (topic (%topic-map-topics map))
(defun check-topic-occurrence-identifiers (map kind iri)
(when (member kind '(:item-identifier :subject-identifier))
(dolist (topic (%topic-map-topics map))
(when (member iri (%occurrence-item-identifiers occurrence) :test #'string=)
(occurrence-problem (if (eq kind :item-identifier) :duplicate-item-identifier :unsupported-reification-identity)
"Topic identity conflicts with an existing Occurrence item identifier."))))))
(when (member iri (%occurrence-item-identifiers occurrence) :test #'string=)
(occurrence-problem (if (eq kind :item-identifier) :duplicate-item-identifier :unsupported-reification-identity)
"Topic identity conflicts with an existing Occurrence item identifier."))))))
-(defun validate-occurrence-identifiers (map topic type value datatype identifiers)
- (unless (and (listp identifiers) (every #'absolute-locator-p identifiers))
+(defun validate-occurrence-identifiers (map topic type value datatype identifiers scope)
+ (unless (and (proper-list-p identifiers) (every #'absolute-locator-p identifiers))
(occurrence-problem :invalid-item-identifiers "Item identifiers must be a list of resolved absolute locators."))
(dolist (id identifiers)
(dolist (owner (%topic-map-topics map))
(occurrence-problem :invalid-item-identifiers "Item identifiers must be a list of resolved absolute locators."))
(dolist (id identifiers)
(dolist (owner (%topic-map-topics map))
(occurrence-problem :unsupported-reification-identity "Topic/Occurrence reification identity is outside this model."))
(dolist (other (%topic-occurrences owner))
(when (and (member id (%occurrence-item-identifiers other) :test #'string=)
(occurrence-problem :unsupported-reification-identity "Topic/Occurrence reification identity is outside this model."))
(dolist (other (%topic-occurrences owner))
(when (and (member id (%occurrence-item-identifiers other) :test #'string=)
(occurrence-problem :duplicate-item-identifier "An Item Identifier is already assigned to a different Occurrence."))))))
(defun normalize-occurrences (map)
(occurrence-problem :duplicate-item-identifier "An Item Identifier is already assigned to a different Occurrence."))))))
(defun normalize-occurrences (map)
(dolist (topic (%topic-map-topics map))
(loop for pair = (equal-pair (%topic-occurrences topic)
(lambda (a b) (same-occurrence-properties-p a (%occurrence-value b)
(dolist (topic (%topic-map-topics map))
(loop for pair = (equal-pair (%topic-occurrences topic)
(lambda (a b) (same-occurrence-properties-p a (%occurrence-value b)
while pair do
(let* ((a (first pair)) (b (second pair))
(c (%make-occurrence (%occurrence-value a) (%occurrence-datatype a) (%occurrence-type a) topic)))
while pair do
(let* ((a (first pair)) (b (second pair))
(c (%make-occurrence (%occurrence-value a) (%occurrence-datatype a) (%occurrence-type a) topic)))
(set-union (%occurrence-item-identifiers a) (%occurrence-item-identifiers b) #'string=)
(%topic-occurrences topic) (replace-pair (%topic-occurrences topic) a b c)
(%occurrence-forward a) c (%occurrence-forward b) c))))
map)
(set-union (%occurrence-item-identifiers a) (%occurrence-item-identifiers b) #'string=)
(%topic-occurrences topic) (replace-pair (%topic-occurrences topic) a b c)
(%occurrence-forward a) c (%occurrence-forward b) c))))
map)
-(defun add-occurrence (topic type value &key (datatype (string-datatype)) item-identifiers)
- "Create an unscoped Occurrence; TYPE must be a same-map Topic. VALUE and DATATYPE
-are strings; DATATYPE is any absolute locator (TMDM 4.4). Supported Integer/Decimal/Date
+(defun add-occurrence (topic type value &key (datatype (string-datatype)) item-identifiers scope)
+ "Create an Occurrence with a Scope Topic set; TYPE must be a same-map Topic. VALUE and DATATYPE
+are strings; DATATYPE is any absolute locator (TMDM 4.4). Supported Integer/Decimal/Date/DateTime
lexical forms are validated; stored strings are never rewritten.
anyURI VALUE must already be absolute, never resolved here.
Validate before mutation, return current representative after duplicate replacement."
lexical forms are validated; stored strings are never rewritten.
anyURI VALUE must already be absolute, never resolved here.
Validate before mutation, return current representative after duplicate replacement."
(occurrence-problem :invalid-decimal-value "Value is not an xsd:decimal lexical form."))
(when (and (string= datatype (date-datatype)) (not (date-lexical-p value)))
(occurrence-problem :invalid-date-value "Value is not an XSD 1.0 date lexical form or valid Gregorian date."))
(occurrence-problem :invalid-decimal-value "Value is not an xsd:decimal lexical form."))
(when (and (string= datatype (date-datatype)) (not (date-lexical-p value)))
(occurrence-problem :invalid-date-value "Value is not an XSD 1.0 date lexical form or valid Gregorian date."))
(when (and (string= datatype (iri-datatype)) (not (absolute-locator-p value)))
(occurrence-problem :relative-uri-value "TMDM IRI-valued Occurrences require an absolute locator."))
(when (and (string= datatype (iri-datatype)) (not (absolute-locator-p value)))
(occurrence-problem :relative-uri-value "TMDM IRI-valued Occurrences require an absolute locator."))
(unless (eq map (%topic-parent type))
(occurrence-problem :foreign-type "Occurrence Parent and Type must belong to the same map."))
(unless (eq map (%topic-parent type))
(occurrence-problem :foreign-type "Occurrence Parent and Type must belong to the same map."))
(%topic-occurrences topic) (append (%topic-occurrences topic) (list item)))
(normalize-occurrences map)
(canonical-occurrence item))))
(%topic-occurrences topic) (append (%topic-occurrences topic) (list item)))
(normalize-occurrences map)
(canonical-occurrence item))))