]> dreyeck.freedombox.rocks Git - topic-maps.git/blob - scripts/check-map-import.py
Document qualified disposition of remaining XTM corpus cases
[topic-maps.git] / scripts / check-map-import.py
1 #!/usr/bin/env python3
2 """Independently check the exported import-model evidence, without promoting contracts."""
3 import json
4 import pathlib
5 import sys
6 import xml.etree.ElementTree as ET
7
8 report = json.loads(pathlib.Path(sys.argv[1]).read_text())
9 assert report['kind'] == 'map-content-import-model-evidence'
10 assert report['failed'] == 0 and report['passed'] == len(report['checks']) == len(set(report['checks']))
11 assert len(report['witnesses']) == 2
12 assert len(report['rejections']) == 50
13 for case in report['rejections']:
14 assert case['bothGraphsUnchanged'] and case['bothCXTMUnchanged']
15 assert case['code'] in {'DUPLICATE-ITEM-IDENTIFIER', 'CORE-SUBJECT-CONFLICT',
16 'REIFIER-CONFLICT', 'VARIANT-SCOPE-COLLAPSE', 'SAME-MAP'}
17 for witness in report['witnesses']:
18 assert witness['sourceUnchanged']
19 xml = ET.fromstring(witness['targetCXTM'])
20 topics = xml.findall('topic')
21 assert len(topics) == 12
22 assert len(xml.findall('association')) == 1
23 assert len(xml.findall('.//name')) == len(xml.findall('.//variant')) == len(xml.findall('.//occurrence')) == 1
24 assert len(xml.findall('.//role')) == 2
25 # Every canonical Topic/Role reference must identify an actual output item.
26 ids = {t.attrib['number'] for t in topics}
27 role_ids = {f"association.{a.attrib['number']}.role.{r.attrib['number']}"
28 for a in xml.findall('association') for r in a.findall('role')}
29 for element in xml.findall('.//rolePlayed'):
30 assert element.attrib['ref'] in role_ids
31 for element in xml.iter():
32 if 'topicref' in element.attrib:
33 assert element.attrib['topicref'] in ids
34 if 'reifier' in element.attrib:
35 assert element.attrib['reifier'] in ids
36 root_ids = [i.text for i in xml.findall('itemIdentifiers/locator')]
37 assert root_ids == (['urn:target-map'] if witness['label'] == 'full-six-kind-transfer' else ['urn:t:map'])
38 assert 'urn:source:map' not in root_ids and 'urn:s:map' not in root_ids
39 assert xml.find('.//occurrence/value').text == '7'
40 if 'sourceCXTM' in witness:
41 source = ET.fromstring(witness['sourceCXTM'])
42 assert len(source.findall('topic')) == 11
43 assert source.find('itemIdentifiers/locator').text == 'urn:source:map'
44 print('MAP-IMPORT-REPORT-PASS: model/metadata/reference evidence only; imported contracts unchanged')