-
Notifications
You must be signed in to change notification settings - Fork 16
/
Copy pathpyshacl_bulk_validator.py
45 lines (38 loc) · 1.51 KB
/
pyshacl_bulk_validator.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# This script can apply pySHACL validation to each vocab in /vocabularies
#
# Current configuration excludes the Gregorian Calendar months from Concept validation since it has multiple prefLabels
# in multiple languages our SHACL files can't handle
import os
from os.path import join, dirname
import glob
from rdflib import Graph
import pyshacl
vocabs_dir = join(dirname(os.getcwd()), "vocabularies")
shapes_dir = join(dirname(os.getcwd()), "shapes")
conceptscheme_shape_graph = Graph().parse(join(shapes_dir, "vocabulary-metadata.shape.ttl"), format="turtle")
concept_shape_graph = Graph().parse(join(shapes_dir, "concept.shape.ttl"), format="turtle")
agent_shape_graph = Graph().parse(join(shapes_dir, "agent.shape.ttl"), format="turtle")
for v in sorted(glob.glob(vocabs_dir + "/*.ttl")):
print("validating: {}".format(v))
conforms, results_graph, results_text = pyshacl.validate(
Graph().parse(v, format="turtle"),
shacl_graph=conceptscheme_shape_graph
)
if not conforms:
print(results_text)
exit()
if "gregorian" not in v:
conforms, results_graph, results_text = pyshacl.validate(
Graph().parse(v, format="turtle"),
shacl_graph=concept_shape_graph
)
if not conforms:
print(results_text)
exit()
conforms, results_graph, results_text = pyshacl.validate(
Graph().parse(v, format="turtle"),
shacl_graph=agent_shape_graph
)
if not conforms:
print(results_text)
exit()