This document is no longer maintained and is out of date.
SHACL (Shapes Constraint Language) is a language for describing and constraining the contents of RDF graphs[[!rdf11-concepts]]. SHACL constraints are grouped into "shapes", which may also be referenced by constraints in other shapes. These constraints describe the triples[[!rdf11-concepts]] connecting certain nodes in the graph.
The abstract syntax consists of statements defining data structures and named members of those data structures.
Each member has either a single type or two or more types that are a union (choice) of types.
Each type is either a reference to another statement, an RDF type, or a SPARQL literal term (e.g. numeric
)[[!sparql11-query]], or the template type Set
, which signifies a logical set of a type.
Sets are unordered and duplicate members have no significance; the set (1, 1, 2, 3, 5)
is the same as the set (5, 1, 3, 2)
.
In this notation:
label
:IRI|BNode, targets
:Set[Target], filters
:Set[Shape], constraints
:Set[Constraint]
This signifies that a Shape
has four components called label
, targets
, filters
, constraints
.
The label
is either a IRI
or BNode
,
the targets
are a set of Target
s,
the filters
are a set of Shape
s,
and the constraints
is a set of Constraint
s.
IRI
and BNode
are defined in RDF 1.1 Semantics[[!rdf11-mt]].
Target
, Shape
and Constraint
are defined terms within this document.
The term definitions given in this document rely on matching triple patterns in the form (subject, predicate, object)
where each position may be supplied by a constant, a previously defined term, or the underscore "_
", which represents a previously undefined element or wildcard.
This corresponds to a SPARQL Triple Pattern where each "_" is replaced by a unique blank node.
Matching such a triple pattern against a graph is defined by SPARQL Basic Graph Pattern Matching (BFP) with a BGP containing only that triple pattern.
Sections defining the RDF representation of SHACL will have a .rdf class.
Validation is a function which takes schema shape and an RDF node and returns a pass or fail.
In examples, the results of validation are represented in a table associating node/shape pairs with a pass or fail and a reason for failure:
shape | node | result | reason |
---|---|---|---|
<Shape1> | <node1> | pass | |
<Shape1> | <node2> | fail | no ex:state supplied. |
These are the namespace prefixes used in the examples:
The SHACL environment uses two inputs: a SHACL shape graph, and a data graph. A SHACL shape graph consists of schemas and shapes. A Schema is a set of one or more Shapes. A Shape is a set of Targets, Filters, and Constraints. Each Shape has a label that is an IRI or BNode. Targets define the nodes in the data graph that are selected for comparison. Filters provide further refinement of the targets if needed. The targeted nodes in the data graph are called "focus nodes."
shapes
:Set[Shape]label
:IRI|BNode, targets
:Set[Target], filters
:Set[Shape], constraints
:Set[Test]
Shapes are represented in RDF as a subject node that is the shape's label
with a set of properties identifying the types of any targets
, filters
and constraints
.
For example, a specific form of Constraint, a PathConstraint that requires that conforming nodes have a foaf:name
property with a value that is an RDF literal would be:
[ sh:predicate foaf:name; sh:nodeKind sh:Literal ] .
A Shape with the label
IRI <http://a.example/Person> and only that constraint
would have a sh:property
arc connecting the shape label
to the above constraint
:
<Person> sh:property [ sh:predicate foaf:name; sh:nodeKind sh:Literal ] .
Here, sh:property
identifies a PathConstraint constraint
; other properties identify other forms of targets
, filters
and constraints
.
These properties will be enumerated in the definitions below.
The SHACL instance graph identifies the nodes in the data graph selected through targets
and filters
and that will be compared against the defined constraints.
The data graph nodes that are identified by the targets
and filters
are call "focus nodes". Focus nodes are all nodes in the graph that:
SHACL can be used for documenting data structures or the input and output of processes, driving user interface generation or navigation because these processes all require testing some nodes in a graph against shapes. The process is called "validation" and the result is called a "validation result". The validation result is fail if validating any Test against each "focus node" returned fail, otherwise the result is pass.
Both PathConstraints and NodeConstraints include a set of Parameters. Constraints select a set of "value nodes" and then test the conformance of the value nodes against each Parameter.
It's possible that renaming Constraints to Selectors and Parameters to Constraints would clarify this specification. Please send feedback to public-rdf-shapes.
Parameters are either unary or n-ary. Validation of a unary Parameter can be performed on each value node individually. The result of validating a set of value nodes against a set of unary parameters is fail if any individual value node failed any Parameter, otherwise pass. The result of validating a set of value nodes against a set of n-ary parameters is fail if the set of value nodes failed any Parameter, otherwise it is pass. Both NodeConstraint and PathConstraint fail if any Parameter in parms fails.
Note that the Paramenter arguments include "numeric" which is the set of SPARQL numeric types enumerated in SPARQL Operand Data Types SPARQL Operand Data Types.
parms
:Set[Parameter]
Testing a NodeConstraint against a focus node returns all of the errors from testing each Parameter (Node Constraint Parameter) against the value node where the value node is the focus node.
path
:SPARQLPropertyPath, parms
:Set[Parameter]
A SPARQLPropertyPath is a property path as defined in [[!sparql11-query]].
Testing a PathConstraint against a focus node returns all of the errors from testing each Parameter against each value node in the SPARQL1.1 Property Path Pattern (focus node,
.
The path
, value node)path
is an expression in the SPARQL1.1 Property Path language excluding the forms of negation: NegatedPropertySet
.
Note that this includes InversePath
.
expression
:Sexpr, extra
:Set[IRI]exprs
:Set[Sexpr]exprs
:Set[Sexpr]
Validation of a PartitionConstraint depends on evaluation of matches
defined below.
Let neigh (the "neighborhood") be the union of every triple (focus node, _, _)
and (_, _, focus node)
.
Testing a PartitionConstraint returns pass if and only if:
neigh
can be partitioned into two sets matches(matched , expression, m )
.
If expression is absent, remainder = neigh
.outs = remainder ∩ arcsOut(G , n )
.matchables = Ø (the empty set)
.matchables ∪ unmatchables = outs
.
matches: asserts that a triple expression is matched by a set of triples that come from the neighbourhood of a node in an RDF graph.
The expression matches(
indicates that a set of triples
matches(
.
matches(
.
<EmployeeShape> sh:partition [ sh:or ( [ sh:property [ sh:predicate foaf:name ; sh:minCount 1 ; sh:maxCount 1 ] ] [ sh:and ( [ sh:property [ sh:predicate foaf:givenName ; sh:minCount 1 ; sh:maxCount 1 ] ] [ sh:property [ sh:predicate foaf:familyName ; sh:minCount 1 ; sh:maxCount 1 ] ] ) ] ] .
<employee1> foaf:name "Bob Smith" . <employee2> foaf:givenName "Bob" ; foaf:familyName "Smith" . <employee3> ex:otherProp "some value" . <employee4> foaf:name "Bob Smith" ; foaf:familyName "Smith" .
shape | node | result | reason |
---|---|---|---|
<EmployeeShape> | <employee1> | pass | |
<EmployeeShape> | <employee2> | pass | |
<EmployeeShape> | <employee3> | fail | expected either foaf:name or foaf:givenName and foaf:familyName . |
<EmployeeShape> | <employee4> | fail | expected only one of foaf:name or foaf:givenName and foaf:familyName . |
The specific ways a value or value set can be constrained are called Parameters
.
They are grouped below into unary and n-ary parameters depending on whether they evaluate a value node or a set of value nodes.
Parameters take one or more arguments.
Note that RDF graphs do not include triples with a literal subject so tests of literal values can only succeed if applied to PathConstraint with a final path component with is not inverse. Other Parameters are only defined for PathConstraint. The symbol PC indicates Parameters that should only be used in a PathConstraint.
Unary Parameters evaluate each node in the set of value nodes that were selected by the Constraints.
kind
:"IRI"|"blank node"|"literal"
Testing a NodeKind parameter against a value node returns fail if
kind
= "IRI" and value node is not an IRIkind
= "blank node" and value node is not a blank nodekind
= "literal" and value node is not an RDFLiteral
A NodeKind parameter is connected to a constraint by the sh:nodeKind
predicate; the node kinds are represented by the constants sh:IRI
, sh:BlankNode
and sh:Literal
respectively.
The following combinations represent disjunctions of the above node kinds: sh:BlankNodeOrIRI
, sh:IRIOrLiteral
, sh:BlankNodeOrLiteral
, sh:IRIOrLiteral
, sh:BlankNodeOrIRI
, sh:BlankNodeOrLiteral
.
<IssueShape> sh:property [ sh:predicate ex:state; sh:nodeKind sh:IRI ] .
<issue1> ex:state ex:HunkyDory . <issue2> ex:staet ex:GoodEnough . # Note mispelling of "state" <issue3> ex:state "just fine" .
shape | node | result | reason |
---|---|---|---|
<IssueShape> | <issue1> | pass | |
<IssueShape> | <issue2> | pass | |
<IssueShape> | <issue3> | fail | ex:state expected to be an IRI, literal found. |
Note that <issue2> passes even though it has no sh:state
property.
To require a property, one must use cardinality parameters as described below in Cardinality.
vals
:Set[RDF term]
Testing a In parameter against a value node returns fail if the value node is not in the set vals
.
An In parameter in RDF is represented as an RDF collection connected to a constraint by the sh:in
predicate.
<IssueShape> sh:property [ sh:predicate ex:state; sh:in (ex:Resolved, ex:Rejected) ] .
<issue1> ex:state ex:Resolved .
<issue2> ex:state ex:Unresolved .
shape | node | result | reason |
---|---|---|---|
<IssueShape> | <issue1> | pass | |
<IssueShape> | <issue2> | fail | ex:state expected to be ex:Resolved or ex:Rejected , ex:Unresolved found. |
The n-ary variant HasValue passes if any value matches the supplied argument.
Testing a Class parameter against a value node returns fail if there is no triple (focus node, rdf:type, X)
where X is the subject of any triple matched by the SPARQL1.1 path expression (X, rdf:subClassOf*,
.
t
)
dt
:IRI
Testing a Datatype parameter against a value node returns fail if the value node is not an RDFLiteral or of the datatype of the value node is not the same RDF term as dt
.
A Datatype parameter is connected to a constraint by the sh:datatype
predicate.
<IssueShape> sh:property [ sh:predicate ex:submittedOn; sh:datatype xsd:dateTime ] .
<issue1> ex:submittedOn "2016-07-08"^^xsd:date .
<issue2> ex:submittedOn "2016-07-08T01:23:45Z"^^xsd:dateTime .
shape | node | result | reason |
---|---|---|---|
<IssueShape> | <issue1> | pass | |
<IssueShape> | <issue2> | fail | ex:submittedOn expected to be an xsd:date , xsd:dateTime found. |
ref
:numeric
Testing a MinLength paramenter against a value node returns fail if the lexical form of the value node is shorter than ref
.
A MinLength parameter is connected to a constraint by the sh:minLength
predicate.
<IssueShape> sh:property [ sh:predicate ex:submittedBy; sh:minLength 20 ] .
<issue1> ex:submittedBy <http://a.example/bob> . # 20 characters <issue2> ex:submittedBy "Bob" . # 3 characters
shape | node | result | reason |
---|---|---|---|
<IssueShape> | <issue1> | pass | |
<IssueShape> | <issue2> | fail | ex:submittedOn expected to be >= 20 characters,3 characters found. |
ref
:numeric
Testing a MaxLength paramenter against a value node returns fail if the lexical form of the value node is longer than ref
.
A MaxLength parameter is connected to a constraint by the sh:maxLength
predicate.
pat
:RDFLiteral, flagstr
:RDFLiteral
A Pattern parameter is evaluated against the SPARQL regex function with the lexical form of the value node as the text
parameter, pat
as the pattern
parameter and flagstr
as the flags
parameter.
The test returns fail is the result is false or produces an XPath type error.
A Pattern parameter is connected to a constraint by the sh:pattern
predicate.
An optional sh:flags
property can supply the flags
parameter.
It is an error for a constraint to have more than one sh:flags
property or a single sh:flags
property and more than one sh:pattern
property.
<IssueShape1> sh:property [ sh:predicate ex:submittedBy; sh:pattern "^HtTp://" ; sh:flags "i" ] . <IssueShape2> sh:property [ sh:predicate ex:submittedBy; sh:pattern " +" ; sh:flags "@" ] .
<issue1> ex:submittedBy <http://a.example/bob> . # matches <IssueShape1>'s case-insensitive pattern <issue2> ex:submittedBy "http://hahaha!" . # also matches <IssueShape1>'s pattern <issue3> ex:submittedBy <mailto:bob@example.com> .
shape | node | result | reason |
---|---|---|---|
<IssueShape1> | <issue1> | pass | |
<IssueShape1> | <issue2> | pass | |
<IssueShape1> | <issue3> | fail | mailto:bob@example.com does not match the pattern /^HtTp:\/\//i |
<IssueShape2> | <issue1> | fail | @ is not a valid flag string. |
<IssueShape2> | <issue2> | fail | @ is not a valid flag string. |
str
:RDFLiteral
Testing a Stem parameter against a value node returns fail if the value node is not an IRI or the lexical form of the value node does not start with str
.
ref
:RDFLiteral PC
Testing a MinInclusive parameter against a value node returns fail if the evaluation of (value node >= ref
) in SPARQL1.1 Operator Mapping returns false or results in a type error.
A MinInclusive parameter is connected to a constraint by the sh:minInclusive
predicate.
<IssueShape> sh:property [ sh:predicate ex:confirmations; sh:minInclusive 1 ] .
<issue1> ex:confirmations 1 .
<issue2> ex:confirmations 0 .
<issue3> ex:confirmations "ii"^^ex:romanNumeral .
shape | node | result | reason |
---|---|---|---|
<IssueShape> | <issue1> | pass | |
<IssueShape> | <issue2> | fail | 0 is less than 1 . |
<IssueShape> | <issue3> | fail | ex:romanNumeral is not a numeric datatype. |
ref
:RDFLiteral PC
Testing a MinExclusive parameter against a value node returns fail if the evaluation of (value node > ref
) in SPARQL1.1 Operator Mapping returns false or results in a type error.
A MinExclusive parameter is connected to a constraint by the sh:minExclusive
predicate.
ref
:RDFLiteral PC
Testing a MaxInclusive parameter against a value node returns fail if the evaluation of (value node <= ref
) in SPARQL1.1 Operator Mapping returns false or results in a type error.
A MaxInclusive parameter is connected to a constraint by the sh:maxInclusive
predicate.
ref
:RDFLiteral
Testing a MaxExclusive parameter against a value node returns fail if the evaluation of (value node < ref
) in SPARQL1.1 Operator Mapping returns false or results in a type error.
A MaxExclusive parameter is connected to a constraint by the sh:maxExclusive
predicate.
Comparison parameters compare the value node against each value reachable by a specified property compareProp
.
Note that these are limited to arcs out of the focus node, that is, those triples matching (focus node,
.
compareProp
, _)
compareProp
:RDFLiteral PC
Let compareVals
be the set of objects in triples matching (focus node,
.
Testing a LessThanOrEquals parameter against a value node returns fail if evaluating the SPARQL1.1 Operator (value node = compareProp
, compareVal
)compareVal
) for any compareVal
in compareVals
returns false or results in a type error.
A LessThanOrEqual's compareProp
parameter is connected to a constraint by the sh:lessThanOrEquals
predicate.
Different departments can assign different criticalities (how important is it) and priorities (how soon should it get fixed) to issues and no priority may be lower than a criticality:
# In this example, a lower number means higher priority or criticality. <IssueShape> sh:property [ sh:predicate ex:priority; sh:lessThanEquals ex:criticality ] .
<issue1> ex:criticality 3; ex:priority 2 . <issue2> ex:priority 1, 4 . # No criticality against which to compare <issue3> ex:criticality 2, 5; ex:priority 1, 4 . <issue4> ex:criticality ex:Low; ex:priority ex:Medium . <issue5> ex:criticality ex:Low; ex:priority 1 .
shape | node | result | reason |
---|---|---|---|
<IssueShape> | <issue1> | pass | |
<IssueShape> | <issue2> | pass | |
<IssueShape> | <issue3> | fail | 4 greater than 2 . |
<IssueShape> | <issue4> | fail | "Medium" greater than "Low" . |
<IssueShape> | <issue5> | fail | 1 not comparable with ex:Low . |
compareProp
:RDFLiteral PC
Let compareVals
be the set of objects in triples matching (focus node,
.
Testing a LessThan parameter against a value node returns fail if evaluating the SPARQL1.1 Operator (value node < compareProp
, compareVal
)compareVal
) for any compareVal
in comapreVals
returns false or results in a type error.
A LessThan's compareProp
parameter is connected to a constraint by the sh:lessThan
predicate.
compareProp
:RDFLiteral PC
Let compareVals
be the set of objects in triples matching (focus node,
.
Testing an Equals parameter against a value node returns fail if evaluating the SPARQL1.1 Operator (value node = compareProp
, compareVal
)compareVal
) for any compareVal
in compareVals
returns false or results in a type error.
A Equal's compareProp
parameter is connected to a constraint by the sh:equals
predicate.
compareProp
:RDFLiteral
Let comapreVals
be the set of objects in triples matching (focus node,
.
Testing a Disjoint parameter against a value node returns fail if evaluating the SPARQL1.1 Operator (value node != compareProp
, compareVal
)compareVal
) for any compareVal
in compareVals
returns false or results in a type error.
A Disjoint's compareProp
parameter is connected to a constraint by the sh:disjoint
predicate.
Testing a HasShape parameter against a value node returns any errors returned when validating the value node as nested (c.f. definition of Shape above).
A Disjoint's nested
parameter is connected to a constraint by the sh:shape
predicate.
<IssueShape> sh:property [ sh:predicate ex:submittedBy; sh:shape <UserShape> ] . <UserShape> sh:property [ sh:predicate dc:creator; sh:nodeKind sh:IRI ] .
<issue1> ex:submittedBy [ dc:creator <mailto:alice@example.com> ] . <issue2> ex:submittedBy [ dc:creator "amy" ] . <issue3> ex:submittedBy <mailto:andrea@example.com> .
shape | node | result | reason |
---|---|---|---|
<IssueShape> | <issue1> | pass | |
<IssueShape> | <issue2> | fail | expected dc:creator to be an IRI. |
<IssueShape> | <issue3> | fail | expected ex:submittedBy to match <UserShape> . |
N-ary Parameters evaluate the set of value nodes which were selected by the Constraints.
b
:boolean PC
Testing a UniqueLang parameter against a set of value nodes returns fail if b
is true
and two or more of the value nodes are RDFLiterals with the same language tag.
<IssueShape> sh:property [ sh:predicate ex:label; sh:uniqueLang true ] ; sh:property [ sh:predicate ex:description; sh:uniqueLang false ] ; sh:property [ sh:predicate ex:notes; sh:nodeKind sh:Literal ] .
<issue1> ex:description "no Save As support"@en, "pas de Sauvegarder Sous"@fr ;
ex:description "there's no way to save a document under another filename"@en ;
ex:notes "Should ADB take care of this?"@en .
<issue2> ex:label "grammar conflict"@en, "conflit analyse"@en ;
ex:description "shift/reduce confict"@en, "reduce/reuse/recycle conflict"@en ;
ex:notes "tried left factor"@en, "tried substitution"@en .
<issue3>
ex:description "vague reports of random crashes"@en .
shape | node | result | reason |
---|---|---|---|
<IssueShape> | <issue1> | pass | |
<IssueShape> | <issue2> | fail | multiple ex:label values with same language tag. |
<IssueShape> | <issue3> | pass |
val
:RDF term
Testing a HasValue parameter against a value node returns fail if the set of value nodes is non-empty and no element of value nodes is the same term as val
.
A HasValue parameter is connected to a constraint by the sh:hasValue
predicate.
<ResolvedIssueShape> sh:property [ sh:predicate ex:state; sh:hasValue ex:Resolved ] .
<issue1> ex:state ex:Resolved .
<issue2> ex:state ex:Resolved, ex:Referred .
<issue3> ex:state ex:Unresolved, ex:Referred .
shape | node | result | reason |
---|---|---|---|
<ResolvedIssueShape> | <issue1> | pass | |
<ResolvedIssueShape> | <issue2> | pass | |
<ResolvedIssueShape> | <issue3> | fail | ex:state expected to be ex:Resolved , ex:Unresolved found. |
The MinCount and MaxCount Parameters on a Constraint with property P identify the minimum and maximum number of triples (focus node,
may exist in the instance data.
Unless provided, the MinCount is 0 and the MaxCount in infinite.
P
, _)
ref
:numeric PC
Testing a MinCount parameter against a set of value nodes returns fail if the number of value nodes is less than ref
.
ref
:numeric PC
Testing a MaxCount parameter against a set of value nodes returns fail if the number of value nodes is greater than ref
.
<IssueShape> sh:property [ sh:predicate ex:status; sh:minCount 1; sh:maxCount 1 ] ; sh:property [ sh:predicate ex:notes; sh:nodeKind sh:Literal ] .
<issue1> ex:status ex:Confirmed . <issue2> ex:status ex:Confirmed, ex:Assigned . <issue3> ex:notes "shouldn't QC have caught this?" .
shape | node | result | reason |
---|---|---|---|
<IssueShape> | <issue1> | pass | |
<IssueShape> | <issue2> | fail | expected at most 1 ex:status . |
<IssueShape> | <issue3> | fail | expected at least 1 ex:status . |
ref
:numeric PCref
:numeric PCQualifiedMinCount and QualifiedMaxCount restrict the set of value nodes to those that pass the Shape QualifiedValueShape. Once the value set is restricted, their evaluation is the same as the evaluation of MinCount and MaxCount respecctively.
Every approved issue must be signed by one person from
engineering and at least one from quality assurance:
<ApprovedIssueShape> sh:sh:property [ sh:predicate ex:approvedBy; sh:qualifiedShape [ sh:pattern "^mailto:.*?@engineering.example" ] ; sh:qualifiedMinCount 1; sh:qualifiedMaxCount 1 ] , sh:sh:property [ sh:predicate ex:approvedBy; sh:qualifiedShape [ sh:pattern "^mailto:.*?@qa.example" ] ; sh:qualifiedMinCount 1 ] .
<issue1> ex:approvedBy <mailto:alice@engineering.example>, <mailto:pat@admin.example>, <mailto:bob@qa.example>, <mailto:eve@qa.example> . <issue2> ex:approvedBy <mailto:amy@engineering.example>, <mailto:brett@engeering.example>, <mailto:cynthia@qa.example> . <issue3> ex:approvedBy <mailto:angel@engineering.example> .
shape | node | result | reason |
---|---|---|---|
<ApprovedIssueShape> | <issue1> | pass | |
<ApprovedIssueShape> | <issue2> | fail | expected at most 1 ex:approvedBy matching"^mailto:.*?@engineering.example" . |
<ApprovedIssueShape> | <issue3> | fail | expected at least 1 ex:approvedBy matching"^mailto:.*?@qa.example" . |
Additional ex:approvedBy
matching neither "^mailto:.*?@engineering.example" nor "^mailto:.*?@qa.example" are not constrainted, c.f. <mailto:amy@engineering.example>
on <Issue1>
.
Algebraic operators provide logical combinations of shapes.
shapes
:Set[Shape]
Testing an And parameter against a value node returns pass if validating each member of the set shapes
against the value node returns pass, otherwise fail.
An And parameter is an RDF Collection of shapes
connected to a constraint by the sh:and
predicate.
<Person> sh:property [ sh:predicate foaf:name; sh:nodeKind sh:Literal ] .
<Customer> sh:property [ sh:predicate corp:custId; sh:datatype xsd:integer ] .
<User> sh:constraint [ sh:and (<Person> <Customer>) ] .
<user1> foaf:name "Alice"; corp:custId 1234 .
<user2> foaf:name "Bob"; corp:custId 1234.0 .
shape | node | result | reason |
---|---|---|---|
<User> | <user1> | pass | |
<User> | <user2> | fail | "1234.0" is an xsd:double. |
shapes
:Set[Shape]
Testing an Or parameter against a value node returns fail if validating each member of the set shapes
against the value node returns fail, otherwise pass.
An Or parameter is an RDF Collection of shapes
connected to a constraint by the sh:or
predicate.
<Person> sh:property [ sh:predicate foaf:name; sh:nodeKind sh:Literal; sh:minCount 1 ] .
<Customer> sh:property [ sh:predicate corp:custId; sh:datatype xsd:integer ] .
<User> sh:constraint [ sh:or (<Person> <Customer>) ] .
<user1> foaf:name "Alice"; corp:custId 12 . <user2> foaf:givenName "Bob"; corp:custId 34 . <user2> foaf:name "Eve"; corp:custId 56.0 . <user2> foaf:name [ rdfs:value "Bob" ]; corp:customerId 78.0 .
shape | node | result | reason |
---|---|---|---|
<User> | <user1> | pass | |
<User> | <user2> | pass | |
<User> | <user3> | pass | |
<User> | <user4> | fail | no foaf:name supplied and "78.0" is an xsd:double. |
shape
:Shape
Testing a Not parameter against a value node returns pass if validating shape
against the value node returns fail, otherwise fail.
A Not parameter is a single shape
connected to a constraint by the sh:not
predicate.
In this example, the not inverts the truth values of the or example above.
<Person> sh:property [ sh:predicate foaf:name; sh:nodeKind sh:Literal ] .
<Customer> sh:property [ sh:predicate corp:custId; sh:datatype xsd:integer ] .
<User> sh:constraint [ sh:not [ sh:or (<Person> <Customer>) ] ] .
<user1> foaf:name "Alice"; corp:custId 12 . <user2> foaf:givenName "Bob"; corp:custId 34 . <user3> foaf:name "Eve"; corp:custId 56.0 . <user4> foaf:name [ rdfs:value "Bob" ]; corp:customerId 78.0 .
shape | node | result | reason |
---|---|---|---|
<User> | <user1> | fail | foaf:name is an RDFLiteral and "12" is an xsd:integer. |
<User> | <user2> | fail | "34" is an xsd:integer. |
<User> | <user3> | fail | foaf:name is an RDFLiteral |
<User> | <user4> | pass |
A SHACL target designates which nodes in the data graph will be validated against the defined constraints. A Target is defined either by matching a node label (TargetNode) in the data graph, a type statement using rdf:type (TargetClass) or a subject IRI (TargetSubjectsOf) or an object IRI (TargetObjectsOf.
The simplest form of Target directly identifies nodes in the data graph:
node
:IRI|literal|BNode
BNodes as TargetNodes depends on being able to name a blank node in an RDF graph. SPARQL1.1 had this as a proposed feature but did not implement it (see some of the SPARQL discussion).
A TargetNode matches node
if node
appears as a node (any subject or object in a triple) in the data graph.
A TargetNode is connected to a shape by the sh:targetNode
property.
<PersonShape> sh:targetNode <http://a.example/Bob>, <http://a.example/Sue> . <NameShape> sh:targetNode "Alice", "Bob" .
In a graph with multiple nodes:
<http://a.example/Alice> foaf:name "Alice" ; foaf:knows <http://a.example/Bob> . <http://a.example/Bob> foaf:name "Bob" . <http://a.example/Sue> foaf:name "Sue" .<PersonShape> selects:
<http://a.example/Alice> foaf:name "Alice" ; foaf:knows <http://a.example/Bob> . <http://a.example/Bob> foaf:name "Bob" . <http://a.example/Sue> foaf:name "Sue" .<NameShape> selects:
<http://a.example/Alice> foaf:name "Alice" ; foaf:knows <http://a.example/Bob> . <http://a.example/Bob> foaf:name "Bob" . <http://a.example/Sue> foaf:name "Sue" .
type
:IRI
A TargetClass matches any node in the data graph with the triple
(node, rdf:type,
or any node which is of a type which is a transitive type
)rdfs:subClassOf
type
.
A TargetClass is connected to a shape by the sh:targetClass
property.
<TeacherShape> sh:targetClass ex:teacher .In a graph with nodes of types
ex:student
, ex:teacher
and ex:class
:
<http://a.example/Alice> a ex:student .
<http://a.example/Bob> a ex:professor . ex:professor rdfs:subClassOf ex:teacher .
<http://a.example/Art> a ex:class .
sh:targetClass
selects <http://a.example/Bob> for validation.
predicate
:IRI
A TargetSubjectsOf matches any subject node in the data graph with a triple
(node,
where "_" is any node.
predicate
, _)
A TargetSubjectsOf is connected to a shape by the sh:targetSubjectsOf
property.
<IssueShape> sh:targetSubjectsOf ex:status .
In a graph with some triples with ex:ex:submittedOn
predicates:
<http://a.example/Issue1> ex:submittedOn "2015-07-08" . <http://a.example/Issue2> ex:submittedOn "2015-07-09"; ex:status ex:assigned . <http://a.example/Issue3> ex:submittedOn "2015-07-10"; ex:status ex:resolved .
sh:targetSubjectOf
selects <http://a.example/Issue2> and <http://a.example/Issue3> for valdiation.
predicate
:IRI
A TargetObjectsOf matches any object node in the data graph with a triple
(_,
where "_" is any node.
predicate
, node)
A TargetObjectsOf is connected to a shape by the sh:targetObjectsOf
property.
<IssueShape> sh:targetObjectsOf ex:waitingOn .
In a graph with some triples with ex:submittedOn
predicates:
<http://a.example/Workflow1> ex:relatedTo <http://a.example/Issue1> . <http://a.example/Workflow2> ex:waitingOn <http://a.example/Issue2> . <http://a.example/Workflow3> ex:waitingOn <http://a.example/Issue3> .
sh:targetObjectsOf
selects <http://a.example/Workflow2> and <http://a.example/Workflow3> for valdiation.