-
Notifications
You must be signed in to change notification settings - Fork 65
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
sh:targetClass does not use shacl/ont graph hierarchies #148
Comments
This issue also occurs when I put the SHACL graph as an argument to |
Hi @gtfierro The first problem is this:
That is correct. All OWL and RDFS defined relationships/axioms need to be part of the data-graph at runtime. This is part of the SHACL spec document, section 2.1.3.2:
This does not only affect This is the most frequently asked question on the PySHACL issue tracker, see #142 #46 #38 (the second part), the main conversation about this was in #6. The solution is to use the Your second problem is:
This is a duplicate of #78 (and closely related to #20) The SHACL spec specifies that the validator should not modify either the data graph or shapes graph at run time:
PySHACL creates a clone of your source datagraph at runtime, and any operations on the datagraph (eg inferencing/entailment and triple rules) are performed on the cloned graph. That is why the inferred triples do not exist on See the long running issue discussion thread in #60 about the proposed alternative mode to operate PySHACL as a new kind of inferencing engine, that will emit the triple rules back into the input data_graph. In your PR #149, you've implemented an alternative solution to address the first problem, in an effort to solve your second problem. That is why you are getting inconsistent results when using |
Note, there is a little hack/workaround you can use if you really do want to have PySHACL modify your input datagraph rather than creating a clone. That is to use the undocumented
That will put the PySHACL validator into a non-spec-compliant operation mode where it skips the clone step, and does emit any changes directly back into the input graph. This is normally used when your data-graph is not cloneable (eg, you are using a sparql-connector on a remote data graph, or when your data graph cannot fit in memory), but I've seen users use the feature to emulate the behaviour you're expecting in this issue. |
Wow -- thank you for the extremely thoughtful and detailed answer! I see now how my mental model was incorrect for using pySHACL and I've adjusted my code to access the inferred triples. My final solution is a little awkward because I have to subtract out the triples I don't want in my expanded data graph, but it works reliably and also generates the same output as TopBraid Composer. I can leave this open if you would like an open reminder of the small bug that I inadvertently found, or I can close this because my original issue is technically resolved. Let me know! |
No need, a fix for that was already included in the v0.19.1 release. I'm glad to know you've solved your problem with a workaround. |
Say I have a simple SHACL-based ontology as follows:
and a separate data graph:
I would expect that running pyshacl with advanced features will generate the
ex:A ex:hasProperty ex:Inferred
triple on the graph. However, this only happens when I put the ontology/shapes and data in the same graph object.Succeeds:
Fails:
I am not running RDFS or OWL inference in this scenario and per the SHACL specification, I shouldn't have to -- the
sh:targetClass
property should be aware of therdfs:subClassOf
hierarchy. In fact, this seems to work great in the case where the data graph has therdfs:subClassOf
statements. However, the waysh:targetClass
is implemented, it only considers triples inside the data graph argument tovalidate
and not theshacl_graph
oront_graph
arguments.I believe there should be a straightforward fix to this by passing in the shacl and ontology graphs into the
apply_rules
function within pySHACL. I've developed a reproducible test case (above) and will start looking at implementing a fix --- how does the proposed approach sound?The text was updated successfully, but these errors were encountered: