Comments (7)
Hi @mgberg
This looks like a similar or duplicate problem to the one reported here: #29
And since that bug was fixed, this example should work in all versions of PySHACL from v0.11.1 onwards.
Can you tell me please, what version of PySHACL are you using?
from pyshacl.
@mgberg
I've run your example with pyshacl v0.11.3 (and latest v0.11.3.post1) and it works as expected with output:
Constraint Violation in MinCountConstraintComponent (http://www.w3.org/ns/shacl#MinCountConstraintComponent):
Severity: sh:Violation
Source Shape: ex:NameConstraint
Focus Node: ex:Bob
Result Path: ex:name
If you're using a version of PySHACL older than v0.11.1, please upgrade to v0.11.1 or newer (preferrably always use the latest version).
If there is a good reason you're deliberately using an older version, let me know and I might be able to backport the owl:Class
fix to it via a maintenance release.
from pyshacl.
My computer thought v0.10 was the most up-to-date version. I upgraded and it works. Thanks!
from pyshacl.
Hello again. If I run the following code:
shapes = rdf.Graph()
shapes.parse(data="""@prefix owl: <http://www.w3.org/2002/07/owl#> .
@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
@prefix sh: <http://www.w3.org/ns/shacl#> .
@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .
@prefix ex: <http://example.org/ns#> .
ex:Person
rdfs:label "Person" ;
rdf:type owl:Class ;
rdf:type sh:NodeShape ;
rdfs:subClassOf owl:Thing ;
sh:property ex:Person-favoriteFood .
ex:Child
rdfs:label "Child" ;
rdf:type owl:Class ;
rdf:type sh:NodeShape ;
rdfs:subClassOf ex:Person .
ex:Person-favoriteFood
rdf:type sh:PropertyShape ;
sh:path ex:favoriteFood ;
sh:class ex:Food ;
sh:name "Favorite Food" .
""",format="ttl")
data = rdf.Graph()
data.parse(data="""@prefix owl: <http://www.w3.org/2002/07/owl#> .
@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
@prefix sh: <http://www.w3.org/ns/shacl#> .
@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .
@prefix ex: <http://example.org/ns#> .
ex:Sally
rdfs:label "Sally" ;
rdf:type ex:Child ;
ex:favoriteFood ex:Sally .
""",format="ttl")
r = sh.validate(data_graph=data, shacl_graph=shapes, inference="both")
print(r[2])
no validation errors are reported. PySHACL is not inferring that the property shape applied to ex:Person
should also be applied to ex:Child
. If this is loaded in a TopQuadrant product, the error is reported correctly.
I have upgraded PySHACL to version 0.11.4.
Thanks!
from pyshacl.
Hi @mgberg
You're not seeing those RDFS subclasses being applied to the data because the class relationships are declared in the SHACL Shapes file.
When you enable inferencing, the process applies only to the data graph. The class relationships declared in the SHACL file don't affect it.
This is why the "extra ontology graph" feature exists in pySHACL. You can give a third graph to the validator, this other graph can contain your extra ontological class relationships. It is mixed in with the data graph before inferencing occurs, so the RDFS inferencer has all of the required class information needed to expand the data graph.
One easy fix for your code for now is to simply feed your SHACL Shapes graph to the ont_graph argument, like this:
r = sh.validate(data_graph=data, shacl_graph=shapes, ont_graph=shapes, inference="both")
print(r[2])
from pyshacl.
I see, that does work. Thanks!
from pyshacl.
@mgberg
Thanks for letting me know.
Heres an example of splitting them out into a separate graph:
shapes = rdf.Graph()
shapes.parse(data="""@prefix owl: <http://www.w3.org/2002/07/owl#> .
@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
@prefix sh: <http://www.w3.org/ns/shacl#> .
@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .
@prefix ex: <http://example.org/ns#> .
ex:Person
rdfs:label "Person" ;
rdf:type owl:Class ;
rdf:type sh:NodeShape ;
rdfs:subClassOf owl:Thing ;
sh:property ex:Person-favoriteFood .
ex:Child
rdfs:label "Child" ;
rdf:type owl:Class ;
rdf:type sh:NodeShape ;
rdfs:subClassOf ex:Person .
ex:Person-favoriteFood
rdf:type sh:PropertyShape ;
sh:path ex:favoriteFood ;
sh:class ex:Food ;
sh:name "Favorite Food" .
""",format="ttl")
extra = rdf.Graph()
extra.parse(data="""@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.org/ns#> .
ex:Person
rdfs:label "Person" ;
rdf:type owl:Class ;
rdfs:subClassOf owl:Thing .
ex:Child
rdfs:label "Child" ;
rdf:type owl:Class ;
rdfs:subClassOf ex:Person .
""",format="ttl")
data = rdf.Graph()
data.parse(data="""@prefix owl: <http://www.w3.org/2002/07/owl#> .
@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
@prefix sh: <http://www.w3.org/ns/shacl#> .
@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .
@prefix ex: <http://example.org/ns#> .
ex:Sally
rdfs:label "Sally" ;
rdf:type ex:Child ;
ex:favoriteFood ex:Sally .
""",format="ttl")
r = sh.validate(data_graph=data, shacl_graph=shapes, ont_graph=extra, inference="both")
print(r[2])
from pyshacl.
Related Issues (20)
- [Discussion] Unexpected behaviour of OWL-RL reasoner HOT 2
- SPARQL constraints depend on variable names HOT 2
- Release for RDFLib 7.0 HOT 2
- assert(): cli-friendly validation + entailment api for data pipelines HOT 2
- Message template substitutions for parameters of SPARQL-based Constraint Components fail when the value is not a Literal
- CI fails on pyduktape HOT 5
- [Discussion] Pinned vs loose requirements, application vs library use cases HOT 5
- 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
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.