@@ -142,6 +142,37 @@ def main() -> None:
142
142
_logger .debug ("arg_ontology_graph = %r." , arg_ontology_graph )
143
143
ontology_graph .parse (arg_ontology_graph )
144
144
145
+ # Filter the graph pyshacl uses as its ontology mix-in to exclude
146
+ # all SHACL-related triples.
147
+ # This is done because, at the time of pyshacl 0.20.0, the entirety
148
+ # of the ontology graph is mixed into the data graph. UCO 1.0.0
149
+ # includes some mechanisms to cross-check SHACL PropertyShapes
150
+ # versus OWL property definitions. Because of the mix-in, all of
151
+ # the ontology graph (.validate ont_graph kwarg) is reviewed by the
152
+ # SHACL graph (.validate shacl_graph kwarg), so for UCO 1.0.0 that
153
+ # adds around 30 seconds to each case_validate call, redundantly
154
+ # reviewing UCO.
155
+ # The ontology graph (.validate ont_graph kwarg) is currently
156
+ # believed to never need to know about SHACL concepts.
157
+ ontology_graph_without_shacl = rdflib .Graph ()
158
+ SH_prefix = str (rdflib .SH )
159
+ for triple in ontology_graph .triples ((None , None , None )):
160
+ skip_triple = False
161
+ for triple_part in triple :
162
+ if isinstance (triple_part , rdflib .URIRef ):
163
+ if str (triple_part ).startswith (SH_prefix ):
164
+ skip_triple = True
165
+ if skip_triple :
166
+ break
167
+ if skip_triple :
168
+ continue
169
+ ontology_graph_without_shacl .add (triple )
170
+ # _logger.debug("len(ontology_graph) = %d.", len(ontology_graph))
171
+ # _logger.debug("len(ontology_graph_without_shacl) = %d.", len(ontology_graph_without_shacl))
172
+ # At the time of CASE 1.0.0, this was the debug output:
173
+ # DEBUG:__init__.py:len(ontology_graph) = 13499.
174
+ # DEBUG:__init__.py:len(ontology_graph_without_shacl) = 7639.
175
+
145
176
# Determine output format.
146
177
# pySHACL's determination of output formatting is handled solely
147
178
# through the -f flag. Other CASE CLI tools handle format
@@ -158,7 +189,7 @@ def main() -> None:
158
189
validate_result = pyshacl .validate (
159
190
data_graph ,
160
191
shacl_graph = ontology_graph ,
161
- ont_graph = ontology_graph ,
192
+ ont_graph = ontology_graph_without_shacl ,
162
193
inference = args .inference ,
163
194
abort_on_first = args .abort ,
164
195
allow_warnings = True if args .allow_warnings else False ,
0 commit comments