]> dreyeck.freedombox.rocks Git - topic-maps.git/blob - scripts/check-core-relationships.py
feat(tmdm): readers for the TMDM 7.2/7.3 relationships; tests for both default name...
[topic-maps.git] / scripts / check-core-relationships.py
1 #!/usr/bin/env python3
2 """Evaluate the stored CXTM baselines of the original isa/ako inputs and compare with the Lisp readers.
3
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.
7 """
8 import json
9 import pathlib
10 import sys
11 import xml.etree.ElementTree as ET
12
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')}
17
18
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')}
23 found = 0
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]))):
28 found += 1
29 return found
30
31
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()
38 for rule in RULES:
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')