]>
dreyeck.freedombox.rocks Git - topic-maps.git/blob - scripts/check-reification.py
2 """Independent pinned-source/baseline comparison of observed Reifier references."""
7 import xml
. etree
. ElementTree
as ET
9 ROOT
= pathlib
. Path ( __file__
). resolve (). parent
. parent
10 report
= json
. loads ( pathlib
. Path ( sys
. argv
[ 1 ]). read_text ())
11 assert report
[ 'kind' ] == 'reification-evidence' and report
[ 'failed' ] == 0
12 assert report
[ 'passed' ] == len ( report
[ 'checks' ]) == len ( set ( report
[ 'checks' ]))
13 names
= [ 'tm-reifier' , 'tm-reifier2' , 'tm-reifier3' , 'name-reifier' , 'variant-reifier' ,
14 'occurrence-reifier' , 'occurrence-reifier-nested' , 'occurrence-reifier-nested-nested' ,
15 'association-reifier' , 'role-reifier' , 'role-duplicate-reified-qnames' ]
16 assert [ c
[ 'id' ] for c
in report
[ 'cases' ]] == [ 'ctm/in/' + n
+ '.ctm' for n
in names
]
17 properties
= [ 'itemIdentifiers' , 'subjectIdentifiers' , 'subjectLocators' ]
18 kind
= dict ( topicMap
= 'topic-map' , name
= 'topic-name' , variant
= 'variant' , occurrence
= 'occurrence' ,
19 association
= 'association' , role
= 'association-role' )
20 for case
in report
[ 'cases' ]:
21 assert case
[ 'ctmSource' ] == ( ROOT
/ 'vendor/cxtm' / case
[ 'id' ]). read_bytes (). decode ( 'utf-8' )
22 doc
= case
[ 'documentIRI' ]
23 base
= ET
. parse ( ROOT
/ 'vendor/cxtm/ctm/baseline' / ( pathlib
. Path ( case
[ 'id' ]). name
+ '.cxtm' )). getroot ()
25 return doc
+ s
if s
. startswith ( '#' ) else s
26 expected_keys
= { t
. attrib
[ 'number' ]: tuple ( tuple ( sorted ( absolute ( l
. text
) for l
in t
. findall ( p
+ '/locator' )))
27 for p
in properties
) for t
in base
. findall ( 'topic' )}
28 observed_keys
= { str ( t
[ 'ordinal' ]): tuple ( tuple ( sorted ( t
[ p
])) for p
in properties
) for t
in case
[ 'model' ][ 'topics' ]}
29 assert collections
. Counter ( expected_keys
. values ()) == collections
. Counter ( observed_keys
. values ())
30 expected
= collections
. Counter (( kind
[ i
. tag
], i
. findtext ( 'value' ), expected_keys
[ i
. attrib
[ 'reifier' ]])
31 for i
in base
. iter () if 'reifier' in i
. attrib
)
32 observed
= collections
. Counter (( r
[ 'kind' ], r
[ 'value' ], observed_keys
[ str ( r
[ 'reifierTopic' ])])
33 for r
in case
[ 'reifications' ])
34 assert expected
== observed
, case
[ 'id' ]
35 assert all ( r
[ 'inverseIsItem' ] and r
[ 'itemIsCanonical' ] and r
[ 'reifierIsCanonical' ] for r
in case
[ 'reifications' ])
36 negative
= [( 'reifier-collision' , 'reifier-conflict' ), ( 'tm-reifier-not-ontop' , 'topic-map-reifier-position' )]
37 assert [ c
[ 'id' ] for c
in report
[ 'negativeCases' ]] == [ 'ctm/invalid/' + n
+ '.ctm' for n
, _
in negative
]
38 for case
, ( name
, code
) in zip ( report
[ 'negativeCases' ], negative
):
39 source
= ( ROOT
/ 'vendor/cxtm' / case
[ 'id' ]). read_text ()
40 pos
= source
. rfind ( '~' )
41 assert case
[ 'code' ] == code
and case
[ 'position' ] == pos
42 assert case
[ 'line' ] == source
[: pos
]. count ( ' \n ' ) + 1
43 assert case
[ 'column' ] == pos
- source
. rfind ( ' \n ' , 0 , pos
)
44 print ( 'REIFICATION-INDEPENDENT-PASS: 11 original model observations, canonical Topic identity and bidirectional Reifier references; 2 specific rejection reasons/positions' )