Skip to content

Commit

Permalink
resolves #71 identify missing/mistakes in terms
Browse files Browse the repository at this point in the history
- There are two additional SHACL shapes that check the objects of
  relations skos:broader and skos:narrower have a skos:prefLabel
- This is a simple test that is based on the assumptions that all
  concepts in DPV are related using SKOS broader/narrower and have a
  prefLabel. The corresponding RDFS and OWL serialisations are derived
  from these, so detecting their correctness should also validate other
  serialisations.
- For cases where there is a typo or mistake, the corresponding IRI will
  be different i.e. a new concept that won't have a prefLabel, and hence
  will be identifed using these tests.
- The verification script has been modified to check ALL files
  (explicitly declared) instead of individual files so as to enable
  SHACL to also identify concepts across main spec and extensions
  without declaring them as errors.
  • Loading branch information
coolharsh55 committed Nov 24, 2022
1 parent ccdb0a1 commit c63ecfe
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 25 deletions.
22 changes: 21 additions & 1 deletion documentation-generator/shacl_shapes/shapes.ttl
Original file line number Diff line number Diff line change
Expand Up @@ -51,4 +51,24 @@ ex:TermShape
sh:message "Terms must have exactly 1 status indicating acceptance, proposed, etc."@en ;
] ;

rdfs:label "constraints for dpv terms"@en .
rdfs:label "constraints for dpv terms"@en .

ex:ValidTermsShape-skos-broader
a sh:NodeShape ;
sh:targetObjectsOf skos:broader ;
sh:property [
sh:path skos:prefLabel ;
sh:minCount 1;
sh:message "Invalid term declared as parent using skos:broader"@en ;
] ;
rdfs:label "Identify typos/mistakes by checking linked broader concept is declared"@en .

ex:ValidTermsShape-skos-narrower
a sh:NodeShape ;
sh:targetObjectsOf skos:narrower ;
sh:property [
sh:path skos:prefLabel ;
sh:minCount 1;
sh:message "Invalid term declared as parent using skos:narrower"@en ;
] ;
rdfs:label "Identify typos/mistakes by checking linked narrower concept is declared"@en .
46 changes: 22 additions & 24 deletions documentation-generator/verify_002.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,16 @@
# (parent of folder containing this file)
# (because its less typing of cd & cd ..)
DATA_PATHS = [
'../dpv',
'../dpv/dpv.ttl',
# '../dpv/modules',
'../dpv-gdpr',
'../dpv-gdpr/dpv-gdpr.ttl',
# '../dpv-gdpr/modules',
'../dpv-pd',
'../dpv-legal',
'../dpv-pd/dpv-pd.ttl',
# '../dpv-legal',
# '../dpv-legal/modules',
'../dpv-tech',
'../rights/eu',
'../risk',
'../dpv-tech/dpv-tech.ttl',
'../rights/eu/rights-eu.ttl',
'../risk/risk.ttl',
# '../risk/modules',
]

Expand All @@ -39,9 +39,9 @@
'shapeparam': '-shapesfile',
# set this variable to the file containing constraints
'shapesfile': '{param}',
'dataparam': '-datafile',
# 'dataparam': '-datafile',
# set this variable to the file to be validated
'datafile': '{param}',
# 'datafile': '{param}',
}

#############################################################
Expand Down Expand Up @@ -75,26 +75,24 @@ def get_shacl_results(output):
import subprocess


def test_shacl(folder, shape):
print(folder)
_, _, files = next(walk(folder))
for file in files:
def test_shacl(paths, shape):
print(f'validating with constraints in {shape}')
SHACL_VALIDATION_COMMAND['shapesfile'] = shape
command = list(SHACL_VALIDATION_COMMAND.values())
for file in paths:
if not file.endswith('.ttl'):
# skip non-turtle files
continue
print(f'validating {file} with constraints in {shape}')
file = path.join(folder, file)
SHACL_VALIDATION_COMMAND['shapesfile'] = shape
SHACL_VALIDATION_COMMAND['datafile'] = file
# print(f'command: {" ".join(SHACL_VALIDATION_COMMAND.values())}')
output = subprocess.run(SHACL_VALIDATION_COMMAND.values(), stdout=subprocess.PIPE)
output = output.stdout.decode('utf-8')
get_shacl_results(output)
command.append('-datafile')
command.append(file)
print(f'command: {command}')
output = subprocess.run(command, stdout=subprocess.PIPE)
output = output.stdout.decode('utf-8')
get_shacl_results(output)


#############################################################

for folder in DATA_PATHS:
for shape in SHAPES:
test_shacl(folder, shape)
for shape in SHAPES:
test_shacl(DATA_PATHS, shape)

0 comments on commit c63ecfe

Please sign in to comment.