1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60
|
from pyshacl import validate
import rdflib
SCHEMA_PATH = "http://datashapes.org/schema.ttl"
data = """\
@prefix ex: <http://example.org/> .
@prefix sch: <http://schema.org/> .
@prefix xsd: <http://www.w3.org/2001/XMLSchema#> .
ex:asdgjkj a sch:CommunicateAction ;
sch:about [ a sch:GameServer ;
sch:playersOnline "42"^^xsd:integer ] .
"""
shacl = """\
# baseURI: http://example.org/myschema
# imports: http://datashapes.org/schema
@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 schema: <http://schema.org/> .
@prefix sh: <http://www.w3.org/ns/shacl#> .
@prefix xsd: <http://www.w3.org/2001/XMLSchema#> .
@prefix : <http://example.org/myschema#> .
<http://example.org/myschema>
a owl:Ontology ;
rdfs:comment "Dummy Schema importing from Schema.org shape"@en ;
rdfs:label "Schema.org importer" ;
owl:imports <http://datashapes.org/schema> .
"""
def schema_org():
dataGraph = rdflib.Graph().parse(data=data, format='ttl')
# print(dataGraph.serialize(format='ttl').decode('utf8'))
shaclDS = rdflib.Dataset()
shaclGraph = shaclDS.default_context
shaclDS.graph(shaclGraph)
shaclGraph.parse(data=shacl, format='ttl')
report = validate(
dataGraph,
shacl_graph=shaclDS,
abort_on_first=False,
inference='both',
meta_shacl=False,
debug=False,
advanced=True,
do_owl_imports=True,
)
print(report[2])
if __name__ == "__main__":
schema_org()
|