RDFLib / pySHACL

A Python validator for SHACL
Apache License 2.0
251 stars 64 forks source link

`sh:entailment` and `pyshacl --advanced` #221

Open ajnelson-nist opened 9 months ago

ajnelson-nist commented 9 months ago

I see from today's features status that sh:entailment is not currently implemented in pySHACL.

I've also seen the --advanced flag and some discussion on other issues (e.g. #60 ) around SHACL-AF.

From Section 8.3 of the SHACL-AF document, there is language around what looks like "halting fast" if the triple $ontology sh:entailment sh:Rules . appears in the input shapes and the engine ~"doesn't support the sh:Rules entailment regime."

What should happen if I have this graph, sh-example.ttl ...

@prefix owl: <http://www.w3.org/2002/07/owl#> .
@prefix sh: <http://www.w3.org/ns/shacl#> .

<http://example.org/shapes>
a owl:Ontology ;
sh:entailment sh:Rules .

... and I use it in these two commands?

pyshacl --advanced --shacl sh-example.ttl sh-example.ttl
pyshacl            --shacl sh-example.ttl sh-example.ttl

Put another way - should the second command fail because only --advanced would "enable" sh:Rules?

Relatedly, because I'm curious about what else implementing sh:entailment might mean: is there a relationship between sh:entailment IRIs and some of pyshacl's inference modes? It looks like there are IRIs from SPARQL that predate SHACL, but SHACL doesn't make impositions within the SHACL specification on what IRIs must be supported. (SPARQL entailment regimes are referenced, but don't seem to be required.) So, if pySHACL said it supported RDFS inferencing, and treated a shapes graph containing $ontology sh:entailment <http://www.w3.org/ns/entailment/RDFS> . with the same runtime effect as pyshacl --inference rdfs, would that be a pySHACL extension behavior over the SHACL specification?

ashleysommer commented 8 months ago

This behaviour in PySHACL is left over from before SHACL-AF spec was published. The first few versions of PySHACL (with built-in inferencing options) were released more than a year before SHACL-AF was released, so sh:entailment and sh:Rules didn't exist.

The current situation is a result of a mismatch between the PySHACL's built-in system for inferencing, and SHACL-AF's specified method for entailment.

The ideal solution would be to implement support for sh:entailment, use that as the default method for enabling RDFS/OWL inferencing, and remove the cli option. That however would be a breaking change. I do plan a similar breaking change in the near future that switches --advanced on by default, so I suppose it makes sense to make this sh:entailment change at the same time.