Comments (5)
@ajhewett Thanks for taking the time to raise this issue.
The problem you are describing is one of pre-inferencing.
A couple of questions:
- How are you invoking pySHACL, via the command line or using the library in a larger project?
- Are you specifiying and pre-inferencing options, like "rdfs", "owlrl', or "both"?
The ParentShape
constraint is not applied to the instance of Child
, because the target graph does not know that Child inherits the rules of Parent, even though the RDFS subClassOf
predicate is used in the Shape file.
In order for the ParentShape
rule to apply to Child
, there must exist a triple (in Data Graph) of (child_instance_id, rdf:type, ex:Parent)
. This is normally injected into the Data Graph by running the RDFS influencing step before validation.
In this case however, this would not work, because the RDFS Classes are declared in the SHACL Shapes File. RDFS pre-inferencing step is only applied to the Data Graph (the target graph), no RDFS declarations from the SHACL Shapes file are pulled into the Data Graph during the pre-inferencing step.
You would need to put this triple into the target graph:
(ex:Child, rdfs:subClassOf. ex:Parent)
Then run ensure you run the RDFS pre-inferencing step before validating, in order to get the result you are expecting.
Note, this same behaviour exists on the official SHACL Playground webapp here:
http://shacl.org/playground/
It uses an entirely different SHACL implementation, and gives the same result you are seeing here.
from pyshacl.
@ajhewett
The latest release of pySHACL (v0.9.9) has a new feature that will potentially solve the problem we were seeing above.
There is a new option to pass into the validator another external file containing extra ontological information, that is needed by the data graph in order for inferencing to proceed correctly.
In the example above, we would have an ontology.ttl file with
@prefix owl: <http://www.w3.org/2002/07/owl#> .
@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .
@prefix ex: <http://example.com/ex#> .
ex:Parent a rdfs:Class ;
rdfs:isDefinedBy ex: ;
rdfs:comment "The parent class"@en ;
rdfs:subClassOf owl:Thing .
ex:Child a rdfs:Class ;
rdfs:isDefinedBy ex: ;
rdfs:comment "The child class"@en ;
rdfs:subClassOf ex:Parent .
Then pass that file into the validator with ont_graph="ontology.ttl"
along with the shacl file and the target data file. Now the data file does not need to be modified before running the validator on it, and it can be simply a bare data snippet that is an instance of those classes defined in the ontology.
from pyshacl.
@ashleysommer many thanks for your prompt response. Very helpful and informative. 👍
To answer your questions:
- I am using the python library within a larger project.
- I specify the "rdfs" inferencing option and also tried the others.
My pyshacl library call looks like:
r = pyshacl.validate(target_graph=dataGraph.default_context, shacl_graph=shaclGraph, inference='rdfs', abort_on_error=False, meta_shacl=True, debug=False)
I did not realize that inferencing is only applied to the target graph with the implication that RDFS Classes declared in the SHACL Shapes graph are not automatically used.
Your suggestion to add a (ex:Child, rdfs:subClassOf. ex:Parent)
triple to the target graph does indeed give the expected result. However, my use-case is validating json-ld data returned in a http response so I would prefer to avoid modifying the response if possible.
After some further experimentation I have been able to achieve a similar effect by enhancing the ParentShape
to also target the Child
class in addition to the Parent
class. This is easier since I control the SHACL Shapes file.
I will close this issue since it is clearly not a pyshacl problem.
from pyshacl.
@ajhewett
I've been thinking about your use-case, and it does absolutely make sense for some applications of SHACL to have the RDFS Class relationships defined in the same file as the SHACL Shapes, and for the Data File to be bare instances of those classes.
I will think about how we could make that work, potentially by copying any rdfs:Class
declarations from the SHACL graph into the Data graph before inferencing.
What I do know is that we can't run RDFS inferencing over the SHACL Shapes graph itself because a lot of the extra triples the inferencing engine adds to the SHACL Shapes and rules break the expected behaviour of those rules.
This new feature would need to be enabled via a flag, because it is probably not something users would expect to happen by default.
from pyshacl.
@ashleysommer Thanks, I will take a look.
from pyshacl.
Related Issues (20)
- SPARQL ASK rule incorrectly passing HOT 7
- Can the prettytable dependency be upgraded to major version 3? HOT 1
- Generating SHACL-SPARQL shapes in RDFLib HOT 2
- Shacl does not seem to work on rdflib.Dataset() HOT 1
- Unable to see the validation result in pyshacl HOT 2
- How to ensure subject is not a sh:BlankNode when validating a owl:Class in an ontology? HOT 4
- owl:imports for data graph is hardcoded to false HOT 2
- pySHACL uses deprecated API `pkg_resources` HOT 4
- Trouble with qualified value shape HOT 6
- Failed to catch violations with properties that are not defined HOT 8
- Is a shape (whether node or property) restricted to one instance of sh:not? HOT 5
- Multiple sh:nots causing strange validation results HOT 2
- Multiple sh:xones on one sh:NodeShape grouping member shapes causing unexpected validation results
- `sh:entailment` and `pyshacl --advanced` HOT 1
- `sh:severity` on shapes linked by `sh:node` HOT 2
- `_evaluation_path` length is not configurable HOT 3
- [Discussion] Higher performance "remote" validation
- Difference between PySHACL and TopBraid SHACL API HOT 1
- Message: Node ex:**** does not contain a value in the set: ['Literal("true" = True, datatype=xsd:boolean)'] HOT 7
- pySHACL 0.26.0 is not yet on PyPI HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from pyshacl.