-
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
Graph with subclass relationship and sh:class constraint not considered conform #142
Comments
Hi @morth PySHACL only evaluates the contents of the data graph at runtime. The Your rdfs and owl definitions in the SHACL Shapes file do not affect the data in the datagraph.
These do not need to be in the SHACL Shapes file, but they do need to be known to the datagraph at runtime. If it is not possible to have the owl and rdfs ontological definitions in the datagraph (eg, if the data in the datagraph is pulled from a separate closed system), then you can use PySHACLs 3-file method. Where you have the Shacl Shape file, and Extra ontology file, and the data graph. For example, this works: import rdflib
from pyshacl import validate
shacl_file = """\
@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 sh: <http://www.w3.org/ns/shacl#> .
@prefix ex: <http://example.com/ns#> .
ex:PersonShape
a sh:NodeShape ;
sh:targetClass ex:Person ;
sh:property [
sh:path ex:hasPet ;
sh:class ex:Animal ;
sh:minCount 1 ;
sh:maxCount 1 ;
] ;
.
"""
ont_file = """\
@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/ns#> .
ex:Person a owl:Class .
ex:Animal a owl:Class .
ex:Dog a owl:Class ; rdfs:subClassOf ex:Animal .
"""
data_file = """\
@prefix ex: <http://example.com/ns#> .
ex:Brutus a ex:Dog .
ex:Jane a ex:Person ; ex:hasPet ex:Brutus .
"""
data = rdflib.Graph()
data.parse(data=data_file, format="turtle")
shapes = rdflib.Graph()
shapes.parse(data=shacl_file, format="turtle")
ont = rdflib.Graph()
ont.parse(data=ont_file, format="turtle")
res = validate(data, shacl_graph=shapes, ont_graph=ont)
conforms, graph, string = res |
Hey Ashley, that makes sense, thank you very much for the clarification. I actually read about Thanks again! |
Given the following shapes graph:
And the following data graph:
The following code prints a report that says
Conforms: False
because of a violation of thesh:class
constraint:Is this expected behaviour?
As I understand the SHACL spec, this example should be valid, because:
ex:Animal
is a SHACL superclass ofex:Dog
becauseex:Dog rdfs:subClassOf ex:Animal
ex:Animal
is in the set of SHACL types ofex:Brutus
, because the latter hasrdf:type ex:Dog
and (1)ex:Brutus
is a SHACL instance ofex:Animal
, because one of its SHACL types isex:Animal
sh:class
constraint should be fulfilledIs this a bug in pySHACL or am I missing something here?
I'm using pySHACL 0.19.0 and Python 3.9.
The text was updated successfully, but these errors were encountered: