Created
April 7, 2022 22:18
-
-
Save ashleysommer/a8d34c8693b659eabae82564b6c379d7 to your computer and use it in GitHub Desktop.
test_141_simple_fix
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# -*- coding: utf-8 -*- | |
""" | |
https://github.com/RDFLib/pySHACL/issues/141 | |
""" | |
import rdflib | |
from pyshacl import validate | |
shacl_file = r"""@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> . | |
@prefix ex: <http://example.org/ontology/> . | |
@prefix owl: <http://www.w3.org/2002/07/owl#> . | |
@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> . | |
@prefix sh: <http://www.w3.org/ns/shacl#> . | |
ex:Dog | |
a owl:Class , sh:NodeShape ; | |
sh:property [ | |
a sh:PropertyShape ; | |
sh:minCount 1 ; | |
sh:nodeKind sh:BlankNodeOrIRI ; | |
sh:path ex:hasIdentifier | |
] ; | |
sh:targetClass ex:Dog ; | |
. | |
ex:Cat | |
a owl:Class , sh:NodeShape ; | |
sh:property [ | |
a sh:PropertyShape ; | |
sh:minCount 1 ; | |
sh:nodeKind sh:BlankNodeOrIRI ; | |
sh:path ex:hasCharacteristic | |
] ; | |
sh:targetClass ex:Cat ; | |
. | |
""" | |
data_file = """@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> . | |
@prefix owl: <http://www.w3.org/2002/07/owl#> . | |
@prefix ex: <http://example.org/ontology/> . | |
@prefix kb: <http://example.org/kb/> . | |
@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> . | |
ex:hasIdentifier a owl:ObjectProperty ; | |
. | |
ex:hasCharacteristic a owl:ObjectProperty ; | |
. | |
ex:hasName a owl:ObjectProperty ; | |
rdfs:subPropertyOf ex:hasIdentifier , ex:hasCharacteristic ; | |
. | |
ex:hasLabel a owl:ObjectProperty ; | |
rdfs:subPropertyOf ex:hasIdentifier ; | |
. | |
kb:dog_with_identifier | |
a ex:Dog ; | |
rdfs:comment "PASS" ; | |
ex:hasIdentifier kb:dogidentifier1 ; | |
. | |
kb:dog_with_name | |
a ex:Dog ; | |
rdfs:comment "PASS" ; | |
ex:hasName [ rdf:value "Rover" ] ; | |
. | |
kb:dog_with_characteristic | |
a ex:Dog ; | |
rdfs:comment "XFAIL" ; | |
ex:hasCharacteristic [ rdf:value "Brown" ] ; | |
. | |
kb:cat_with_identifier | |
a ex:Cat ; | |
rdfs:comment "XFAIL" ; | |
ex:hasIdentifier kb:catidentifier1 ; | |
. | |
kb:cat_with_name | |
a ex:Cat ; | |
rdfs:comment "PASS" ; | |
ex:hasName [ rdf:value "Mittens" ] ; | |
. | |
kb:cat_with_characteristic | |
a ex:Cat ; | |
rdfs:comment "PASS" ; | |
ex:hasCharacteristic [ rdf:value "Green" ] ; | |
. | |
kb:dog_with_label | |
a ex:Dog ; | |
rdfs:comment "PASS" ; | |
ex:hasLabel [ rdf:value "Dopey" ] ; | |
. | |
""" | |
def test_141() -> None: | |
data = rdflib.Graph() | |
data.parse(data=data_file, format="turtle") | |
shapes = rdflib.Graph() | |
shapes.parse(data=shacl_file, format="turtle") | |
res = validate( | |
data, | |
shacl_graph=shapes, | |
data_graph_format='turtle', | |
shacl_graph_format='turtle', | |
debug=True, | |
inference="rdfs", | |
) | |
conforms, graph, string = res | |
if __name__ == "__main__": | |
test_141() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment