]>
dreyeck.freedombox.rocks Git - topic-maps.git/blob - scripts/check-core-relationships.py
2 """Evaluate the stored CXTM baselines of the original isa/ako inputs and compare with the Lisp readers.
4 This is an independent evaluation of serialized data: it counts, in each unchanged baseline, the
5 associations that have the structure of TMDM 7.2 or 7.3. It is not a proof of conformance to the
6 standard; the normative expectations are argued clause by clause in tests/core-relationships.lisp.
11 import xml
.etree
.ElementTree
as ET
13 ROOT
= pathlib
.Path(__file__
).resolve().parent
.parent
14 PREFIX
= 'http://psi.topicmaps.org/iso13250/model/'
15 RULES
= {'type_instance': ('type-instance', 'type', 'instance'),
16 'supertype_subtype': ('supertype-subtype', 'supertype', 'subtype')}
19 def count(baseline
, rule
):
20 relationship
, first
, second
= (PREFIX
+ local
for local
in RULES
[rule
])
21 identifiers
= {topic
.attrib
['number']: {locator
.text
for locator
in topic
.findall('subjectIdentifiers/locator')}
22 for topic
in baseline
.findall('topic')}
24 for association
in baseline
.findall('association'):
25 roles
= [identifiers
[role
.find('type').attrib
['topicref']] for role
in association
.findall('role')]
26 if (relationship
in identifiers
[association
.find('type').attrib
['topicref']] and len(roles
) == 2
27 and any(first
in a
and second
in b
for a
, b
in (roles
, roles
[::-1]))):
32 report
= json
.loads(pathlib
.Path(sys
.argv
[1]).read_text())
33 assert len(report
['cases']) == 11 and len({case
['id'] for case
in report
['cases']}) == 11
34 for case
in report
['cases']:
35 assert case
['id'].startswith('ctm/in/') and case
['id'].endswith('.ctm'), case
['id']
36 name
= pathlib
.Path(case
['id']).name
37 baseline
= ET
.parse(ROOT
/ 'vendor/cxtm/ctm/baseline' / (name
+ '.cxtm')).getroot()
39 assert count(baseline
, rule
) == case
[rule
], (case
['id'], rule
, count(baseline
, rule
), case
[rule
])
40 print('CORE-RELATIONSHIPS-SERIALIZED-DATA-PASS: 11 original CXTM baselines hold the association counts '
41 'the TMDM 7.2/7.3 readers report; an evaluation of serialized data, not a conformance proof')