]>
dreyeck.freedombox.rocks Git - topic-maps.git/blob - scripts/check-merging.py
2 """Compare selected model properties with frozen baselines, never canonical XML.
4 Match topics by identifier sets, not observation order or CXTM numbering.
5 This bounded semantic oracle does not implement ISO 13250-4 canonicalization.
10 import xml
.etree
.ElementTree
as ET
12 root
= pathlib
.Path(__file__
).resolve().parent
.parent
13 report
= json
.loads(pathlib
.Path(sys
.argv
[1]).read_text())
14 assert report
['kind'] == 'semantic-observations-not-cxtm'
15 assert report
['failed'] == 0 and report
['passed'] == len(report
['checks'])
16 assert len(set(report
['checks'])) == len(report
['checks'])
17 expected_ids
= {'ctm/in/'+name
+'.ctm' for name
in [
18 'topic-subject-identifier', 'topic-subject-identifier-wrapped',
19 'topic-subject-identifier-duplicate', 'topic-subject-locator',
20 'topic-subject-locator-wrapped', 'topic-subject-locator-semi',
21 'topic-subject-locator-duplicate', 'topic-item-identifier',
22 'topic-item-identifier-wrapped', 'topic-item-identifier-duplicate', 'name-duplicate']}
23 assert len(report
['cases']) == len(expected_ids
)
24 assert {case
['id'] for case
in report
['cases']} == expected_ids
25 for case
in report
['cases']:
26 baseline
= root
/'vendor/cxtm/ctm/baseline'/(pathlib
.Path(case
['id']).name
+'.cxtm')
27 xml
= ET
.parse(baseline
).getroot()
28 actual
= case
['actualObjects']
29 expected_topics
= xml
.findall('topic')
30 assert xml
.tag
== 'topicMap'
31 assert actual
['topicCount'] == len(expected_topics
)
32 assert actual
['nameCount'] == sum(len(t
.findall('name')) for t
in expected_topics
)
34 def key(topic
, xml_item
=False):
36 for prop
in ['itemIdentifiers', 'subjectIdentifiers', 'subjectLocators']:
37 locators
= ([e
.text
for e
in topic
.findall(prop
+'/locator')]
38 if xml_item
else topic
[prop
])
39 locators
= [case
['documentIRI']+v
if v
.startswith('#') else v
for v
in locators
]
40 assert len(locators
) == len(set(locators
))
41 values
.append(tuple(sorted(locators
)))
44 by_identity
= {key(t
): t
for t
in actual
['topics']}
45 assert len(by_identity
) == actual
['topicCount']
47 for expected
in expected_topics
:
48 observed
= by_identity
[key(expected
, True)]
49 assert observed
['parentIsMap'] is True
50 assert all(c
.tag
in ['itemIdentifiers', 'subjectIdentifiers', 'subjectLocators', 'name'] for c
in expected
)
51 mapping
[int(expected
.attrib
['number'])] = observed
['ordinal']
52 for expected
in expected_topics
:
53 observed
= by_identity
[key(expected
, True)]
54 names
= [(n
['value'], n
['typeTopicOrdinal'], n
['parentTopicOrdinal']) for n
in observed
['names']]
55 expected_names
= [(n
.find('value').text
, mapping
[int(n
.find('type').attrib
['topicref'])],
56 observed
['ordinal']) for n
in expected
.findall('name')]
57 assert sorted(names
) == sorted(expected_names
)
58 print('MERGING-BASELINE-SEMANTIC-EVIDENCE-PASS: 11 frozen baselines; no canonicalization or canonical numbering')