RDFLib / pySHACL

A Python validator for SHACL
Apache License 2.0
241 stars 63 forks source link

owl:imports for data graph is hardcoded to false #211

Closed edmondchuc closed 8 months ago

edmondchuc commented 9 months ago

Before I make a PR to change this, I just wanted to ask why owl:imports is not allowed for the data graph.

https://github.com/RDFLib/pySHACL/blob/52e239c41b88497e9c9f5fd8ae0ae567e59885b8/pyshacl/validate.py#L425-L428

ashleysommer commented 8 months ago

Hi @edmondchuc Yes, this is done on purpose. owl:imports is explicitly not supported on the data graph.

This is for a number of reasons: 1) The SHACL spec states that the data graph should be provided to the SHACL validator complete with all the content required for validation, and the SHACL validator may not modify the data graph during the operation of validation. 2) owl:imports is an OWL2 axiom, it is only supported on documents that are rdf:type owl:Ontology. In normal use cases, the SHACL Shapes graph (and the Extra Ontology graph) will likely be in the form of an OWL ontology, but your datagraph is normally not an ontology. 3) In cases where your data graph is an OWL ontology (eg, you are applying SHACL validation to validate ontology documents) then those are cases where you normally do not want the imports to resolve in the data graph, in order to more easily target just your own ontology nodes.

edmondchuc commented 8 months ago

Thanks for the explanation @ashleysommer. That all makes sense.

I was hoping to find a declarative method for stating imports in RDF and thought that SHACL processors might support this functionality. It appears, however, that there’s no way around it - the data graph must be expanded outside of the SHACL processor.