shex
shex copied to clipboard
RDF representation of ShapeMap's
It would be interesting to define an RDF/JSON-LD serialization of shape maps.
As an example, the following shapeMap:
:alice@:PersonShape,
{FOCUS rdf:type schema:Person}@:PersonShape
could be represented in RDF as:
prefix sm: <http://shex.io/ns/shapeMap#>
prefix : <http://example.org/>
prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
prefix schema: <http://schema.org/>
[ a sm:ShapeMap ;
sm:associations (
[ sm:node :alice ;
sm:shape :PersonShape ;
sm:status sm:conformant
]
[ sm:node [
a sm:triplePattern ;
sm:subject sm:Focus ;
sm:predicate rdf:type ;
sm:object schema:Person
] ;
sm:shape :PersonShape
]
) ] .
A use case would be to validate RDF graphs that contain a merge of the shapes, the data and the shapeMap.
Something like this:
prefix sm: <http://shex.io/ns/shapeMap#>
prefix : <http://example.org/>
prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
prefix schema: <http://schema.org/>
PREFIX xsd: <http://www.w3.org/2001/XMLSchema#>
# Map
[ a sm:ShapeMap ;
sm:associations (
[ sm:node [
a sm:triplePattern ;
sm:subject sm:Focus ;
sm:predicate rdf:type ;
sm:object schema:Person
] ;
sm:shape :PersonShape
]
) ] .
# Data
:alice a schema:Person ;
schema:name "Alice" .
# Schema
[ a sx:Schema ;
sx:shapes :PersonShape ].
:PersonShape a a sx:Shape;
sx:expression [ a sx:TripleConstraint ;
sx:predicate schema:name ;
sx:valueExpr [
a sx:NodeConstraint ;
sx:datatype xsd:string
]
]
.
After entertaining ourselves with how to validate the RDF graph at sm:Focus, we settled on adding an sm:focus predicate:
[ a sm:ShapeMap ;
sm:associations (
[
sm:node [
sm:focus rdf:subject ;
rdf:predicate rdf:type ;
sm:object schema:Person
] ;
sm:shape :PersonShape
]
)
] .
This also uses rdf:{subject,predicate,object}.
More examples:
{FOCUS :status _}@START
[]
a sm:ShapeMap ;
sm:associations (
[
sm:node [
a sm:TriplePattern ;
sm:focus rdf:subject ;
rdf:predicate <http://hl7.org/fhir/status> ;
] ;
sm:shape sx:Start
]
) .
This means that sx:Start ought not be a URL for a schema that labels some ShapeDecl as sx:Start a la
<http://bad.example/ns/Start>
sx:start sx:Schema ;
sx:shapes (
sx:Schema sx:Start
) .
sx:Schema a sx:ShapeDecl ; sx:shapeExpr [ ... ] .
sx:Start a sx:ShapeDecl ; sx:shapeExpr [ ... ] .
That's OK, we control that schema and are not so masochistic that we'll add such confusion right away.