This document defines the SHACL Shapes Constraint Language, a language for validating RDF graphs against a set of conditions. These conditions are provided as shapes and other constructs expressed in the form of an RDF graph. RDF graphs that are used in this manner are called "shapes graphs" in SHACL and the RDF graphs that are validated against a shapes graph are called "data graphs". As SHACL shape graphs are used to validate that data graphs satisfy a set of conditions they can also be viewed as a description of the data graphs that do satisfy these conditions. Such descriptions may be used for a variety of purposes beside validation, including user interface building, code generation and data integration.
This document covers the the SHACL Core language.
SHACL Full, an extension of SHACL Core that includes SPARQL-based constraints and user defined constraint components is defined in link to document.
The examples in this document use Turtle [[!turtle]]. The reader should be familiar with basic RDF concepts [[!rdf11-concepts]] such as triples and, for the advanced concepts of SHACL, with SPARQL [[!sparql11-overview]].
TODO: needs more work.
This specification describes conformance criteria for:
TODO: link to test cases.
Throughout this document, IRIs are written in Turtle syntax, using the following mapping of prefixes to namespaces:
Prefix | Namespace |
---|---|
rdf: |
http://www.w3.org/1999/02/22-rdf-syntax-ns# |
rdfs: |
http://www.w3.org/2000/01/rdf-schema# |
sh: |
http://www.w3.org/ns/shacl# |
xsd: |
http://www.w3.org/2001/XMLSchema# |
ex: |
http://example.com/ns# |
The remainder of this section is informative.
Note that the URI of the graph defining the SHACL vocabulary itself is equivalent to
the namespace above, i.e. it includes the #
.
References to the SHACL vocabulary, e.g. via owl:imports
should include the #
.
The Turtle serialization of the SHACL vocabulary will be uploaded to web URL of the graph that it represents.
Throughout the document, color-coded boxes containing RDF graphs in Turtle will appear. These fragments of Turtle documents use the prefix bindings given above.
# This box represents an input shapes graph
# Triples that can be omitted are marked as grey e.g.
<s> <p> <o> .
# This box represents an input data graph. # When highlighting is used in the examples: # Elements highlighted in blue are target nodes ex:Bob a ex:Person . # Elements highlighted in red are nodes that fail validation ex:Alice a ex:Person .
# This box represents an output results graph
SHACL Definitions appear in blue boxes:
# This box contains textual definitions.
Terminology that is linked to portions of RDF 1.1 Concepts and Abstract Syntax is used in SHACL as defined there. Terminology that is linked to portions of SPARQL 1.1 Query Language is used in SHACL as defined there. A single linkage is sufficient to provide a definition for all occurences of a particular term in this document.
Definitions are complete within this document, i.e., if there is no rule to make a some situation true in this document then the situation is false.
n
has value v
for property p
in an
G
if there is
an RDF triple in G
with subject n
, predicate p
, and
object v
.
An RDF term n
has value v
for SPARQL property path expression
p
in an
RDF graph G
if there is a solution mapping in the result of the SPARQL query
SELECT ?s ?o WHERE { ?s p' ?o }
on G
that binds ?s
to
n
and ?o
to v
, where
p'
is SPARQL surface syntax for p
.
G
is an IRI or a blank node that is
either rdf:nil
(provided that rdf:nil
has no value for either
rdf:first
or
rdf:rest
in G
), or has exactly one value for rdf:first
in
G
and exactly one
value for rdf:rest
in G
that is also a SHACL list in G
and there is
no non-empty path in G
from the list back to itself where the predicates of
the RDF triples in the path are each rdf:rest
.
The members of any SHACL list except rdf:nil
in an RDF
graph G
consist
of its value for rdf:first
in G
followed by the members in
G
of its value
for rdf:rest
in G
.
The SHACL list rdf:nil
has no members in any RDF graph.
n
is a SHACL instance of an
RDF
term m in an RDF graph G
if
there is a path in G
from n
to m
where the predicate of
the first RDF triple
in the path is rdf:type
and the predicates of any other RDF triples in the
path are rdfs:subClassOf
.
An RDF term n
has an RDF term m
as SHACL types in an RDF graph G
if n
is a
SHACL instance of m
in G
.
RDF terms have zero or more expected types in an RDF graph.
Each expected type for an RDF term in an RDF graph G
is the result of the RDF
term being the object of an RDF triple in G
with a particular predicate as
described in this document.
A blank node is an ill-formed property path in an RDF graph G
if it has
a value for more than one of
rdf:first
,
sh:alternativePath
,
sh:inversePath
,
sh:zeroOrMorePath
,
sh:oneOrMorePath
,
or sh:zeroOrOnePath
in G
.
A blank node is an ill-formed property path in an RDF graph G
if there is
a path in G
from the node back to itself where the sequence of
predicates of the RDF triples in the path matches the regular expression
( ( rdf:rest* rdf:first ) | sh:alternativePath ( rdf:rest* rdf:first ) | sh:inversePath |
sh:zeroOrMorePath | sh:oneOrMorePath | sh:zeroOrOnePath ) +
.
An RDF term is an ill-formed property path in an RDF graph if it does not satisfy exactly one of the conditions in the mapping below.
If an RDF term is not an ill-formed property path in an RDF graph G
then
it is a SHACL property path in G
.
The path mapping in an RDF graph G
of a RDF term p
that is a SHACL
property path in G
, path(p,S)
, is a *SPARQL property path expression*
defined as follows:
p
is an IRI then path(p,S)
is PredicatePath(p)
.
p
is a blank node that is a SHACL list in G
that has at least two
members in G
and none of these members are ill-formed property paths in
G
then path(p,S) is SequencePath(path(v1,S) ... path(vn,S))
where vi are the
members of p
in G
, in order.
p
is a blank node that has exactly one value for sh:alternativePath in
G and that value is a SHACL list in G
that has at least two members in G
and
none of the members in G
are ill-formed property paths in G
then path(p,S)
is AlternativePath(path(v1,S) ... path(vn,S)) where vi are the members of
the list in G
, in order.
p
is a blank node that has exactly one value v
for
sh:inversePath in G
and v
is not an ill-formed property path in G
then path(p,S) is
InversePath(path(v,S)).
p
is a blank node that has exactly one value v
for
sh:zeroOrMorePath
in G
and v
is not an ill-formed property path in G
then path(p,S) is
ZeroOrMorePath(path(v,S)).
p
is a blank node that has exactly one value v
for
sh:oneOrMorePath in
G and v
is not an ill-formed property path in G
then path(p,S) is
OneOrMorePath(path(v,S)).
p
is a blank node that has exactly one value v
for
sh:zeroOrOnePath in
G and v
is not an ill-formed property path in G
then path(p,S) is
ZeroOrOnePath(path(v,S)).
SHACL property paths in same or different RDF graphs are equivalent if their path mappings in their graphs are the same.
The remainder of this section is informative.
The following example illustrates some valid SHACL property paths, together with their SPARQL 1.1 equivalents.
SPARQL Property path: ex:parent SHACL Property path: ex:parent SPARQL Property path: ^ex:parent SHACL Property path: [ sh:inversePath ex:parent ] SPARQL Property path: ex:parent/ex:firstName SHACL Property path: ( ex:parent ex:firstName ) SPARQL Property path: rdf:type/rdfs:subClassOf* SHACL Property path: ( rdf:type [ sh:zeroOrMorePath rdfs:subClassOf ] ) SPARQL Property path: ex:father|ex:mother SHACL Property path: [ sh:alternativePath ( ex:father ex:mother ) ]
SHACL uses the RDF and RDFS vocabularies, but full RDFS inferencing is not required.
However, SHACL processors MUST identify SHACL instances of a class both in the data graph and
the shapes graph without modifying either graph during the validation
process.
Furthermore, SHACL processors MAY operate on RDF graphs that include entailments - either pre-computed
before being submitted to a SHACL processor or performed on the fly as part of SHACL processing.
To support processing of entailments, SHACL includes the property sh:entailment
to indicate what inferencing is required by a given
shapes graph.
SHACL implementations MAY, but are not required to, support entailment regimes.
The following example data graph contains three SHACL instances of the class
ex:Person
.
ex:Alice a ex:Person ; ex:child ex:Calvin ; ex:ssn "987-65-432A" . ex:Bob a ex:Person ; ex:child ex:Calvin ; ex:ssn "123-45-6789" ; ex:ssn "124-35-6789" . ex:Calvin a ex:Person ; ex:school ex:TrinityAnglicanSchool .
The following conditions are shown in the example:
ex:Person
can have at most one value for the property
ex:ssn
,
and this value is a literal with the datatype xsd:string
that matches
a specified regular expression.
ex:Person
can have unlimited values for the property
ex:child
,
and these values are IRIs and SHACL instances of ex:Person
.
ex:child
in the inverse direction.
A SHACL instance of ex:Person
can have at most 2 parents, i.e. can be the
object of at most two triples
where the predicate is ex:child
.
ex:Person
cannot have values for any other property apart
from
ex:ssn
, ex:child
and rdf:type
.
The aforementioned conditions can be represented as constraints in the following shapes graph:
ex:PersonShape
a sh:Shape ;
sh:targetClass ex:Person ; # Applies to all persons
sh:shape [
sh:path ex:ssn ; # This constraint is about the values of the ex:ssn property
sh:maxCount 1 ;
sh:datatype xsd:string ;
sh:pattern "^\\d{3}-\\d{2}-\\d{4}$" ;
] ;
sh:shape [
sh:path ex:child ;
sh:class ex:Person ;
sh:nodeKind sh:IRI ;
] ;
sh:shape [
rdfs:comment "A person's parents are represented via ex:child used in the inverse direction." ;
sh:path [ sh:inversePath ex:child ] ;
sh:name "parent" ;
sh:maxCount 2 ;
] ;
sh:closed true ;
sh:ignoredProperties ( rdf:type
) .
We can use the shape declaration above to illustrate some of the key terminology used by SHACL.
The focus nodes for the shape ex:PersonShape
are all SHACL instances of
the class ex:Person
.
These focus nodes are the targets of the shape and are specified using the property
sh:targetClass
.
The shape has three shapes with the property sh:shape
,
one of which uses a path expression.
The shape itself is also a constraint on the focus nodes using the parameters
sh:closed
and sh:ignoredProperties
.
Some of the property constraints specify parameters from multiple constraint components in
order to
restrict multiple aspects of the property values.
For example, in the shape for ex:ssn
, parameters from three constraint
components are used.
The parameters of these constraint components are sh:datatype
,
sh:pattern
and sh:maxCount
.
For each focus node< the property values of ex:ssn
will be validated against all
three components.
The constraint on the inverse property values of sh:child
uses only one constraint
component identified by the sh:maxCount
parameter.
Note that this constraint uses the non-validating property sh:name
to suggest a human-readable name for the property when used in the inverse direction.
SHACL validation based on the provided data graph and shapes graph would produce the following validation report. See the section Validation Report for details on the format.
[] a sh:ValidationReport ; sh:conforms "false"^^xsd:boolean ; sh:result [ a sh:ValidationResult ; sh:resultSeverity sh:Violation ; sh:focusNode ex:Alice ; sh:resultPath ex:ssn ; sh:value "987-65-432A" ; sh:sourceConstraintComponent sh:RegexConstraintComponent ; sh:sourceShape ex:PersonShape ; ] , [ a sh:ValidationResult ; sh:resultSeverity sh:Violation ; sh:focusNode ex:Bob ; sh:resultPath ex:ssn ; sh:sourceConstraintComponent sh:MaxCountConstraintComponent ; sh:sourceShape ex:PersonShape ; ] , [ a sh:ValidationResult ; sh:resultSeverity sh:Violation ; sh:focusNode ex:Calvin ; sh:resultPath ex:school ; sh:value ex:TrinityAnglicanSchool ; sh:sourceConstraintComponent sh:ClosedConstraintComponent ; sh:sourceShape ex:PersonShape ; ] .
The validation results are enclosed in a validation report.
The first validation result is produced because ex:Alice
has a value for
ex:ssn
that does not match the regular expression specified by the property sh:regex
.
The second validation result is produced because ex:Bob
has more than the permitted
number of values
for the property ex:ssn
as specified by the sh:maxCount
of 1.
The third validation result is produced because the shape ex:PersonShape
has the
the property sh:closed
set to true
but ex:Calvin
uses the property ex:school
which is neither one of the predicates
from any of the
property constraints of the shape, nor one of the properties listed using
sh:ignoredProperties
.
A results graph is an RDF graph G
where every node in G
that has
SHACL type sh:ValidationResult
in G
meets the following conditions
rdf:type
in G
G
G
G
and this value
if present is a SHACL property path in G
G
G
G
G
is a language-tagged
literal and each has a different language tag.
G
has SHACL type
sh:ValidationResult.
p
in G
where p
is a list-taking parameter is a
SHACL list in G
.
A validation result from RDF term f, optional RDF term v, data graph
D, constraint c
with type C, and shape s
in shapes graph S
is a node in a results graph G
that meets the following conditions:
sh:ValidationResult
as a value for rdf:type
in G
sh:focusNode
in G
is f
sh:valueNode
in G
is v
if v
is
present, otherwise it has no value for sh:valueNode
in G
G
is a SHACL property path in G
that
is equivalent to the value of s
for sh:path
in S
if there is one,
otherwise it has no value for sh:resultPath in G
G
is s
G
is C
G
is the severity of s
in S
G
are the validation messages of s
in S
p
in G
with p
a non-list-taking
parameter of C
and X = { x | <p,x> is a parameter value of c }
are the elements of X
p
in G
with p
a list-taking parameter of C
and X = { x | <p,x> is a parameter value of c }
contain for each member
of X a SHACL list in G
whose elements in G
are the elements of X in S
A results structure is a results graph R and a set of nodes from R each of which have SHACL type sh:ValidationResult in R. The set of nodes is called the top-level validation results of the results structure.
A results structure contains a top-level validation result from
f,v,D,c,s,S
if its graph contains a node that is a validation result from
f,v,D,c,s,S
and that node is an element of its top-level validation results.
A validation report V
for a results structure R
is any results graph
containing at least the triples of R
plus a new blank node n
with
sh:ValidationReport
as a value for rdf:type
in V
;
"false"^^xsd:boolean
as sole value for sh:conforms
in V
if R
has any top-level validation results in R
, and "true"^^xsd:boolean
otherwise;
and whose set of values for sh:result
in V
is the set of top-level validation results
in R
.
The combination of a multiset of results structures is the union of the graphs of the results structures and the union of their sets of top-level validation results, provided that this is a results structure.
The remainder of this section is informative.
Combination does not use merging so that, for example, validation results and SHACL property paths do not have to be replicated. Care does need to be taken when different results structures share blank nodes so that invalid validation results or SHACL property paths do not result.
Validation reports are only required to contain
top-level validation results from results graphs, i.e., the results for
validating elements of the complete targets of shapes against the shape.
Implementations are encouraged to provide interfaces that also retain other
validation results and to use the property sh:detail
to link from a
validation result for a shape to validation results from subsidiary
conformance checking such as is required for constraints of type
sh:ShapeConstraintComponent
.
The shapes of an RDF graph G
are those nodes in G
with
SHACL or expected
type sh:Shape
in G
.
A shapes graph is an RDF graph G
containing no ill-formed
shapes in G
.
Ill-formed shapes are described in the rest of this document.
If s
is a shape in an RDF graph G
with more than one value for sh:severity
in G
or a a value that is not sh:Info, sh:Warning, or sh:Violation then s
is
an ill-formed shape in G
.
The severity of a SHACL shape in a shapes graph S
is its value for
sh:severity in S
, if any, otherwise sh:Violation
.
If s
is a shape in an RDF graph G
with a value for sh:message that is
that is neither a literal of datatype xsd:string
nor a language-tagged literal
is an ill-formed shape in G
.
The validation messages of a SHACL shape in a shapes graph S
are its values for
sh:message in S
, if any, otherwise they are defined by the SHACL Processor.
If s
is a shape in an RDF graph G
with a value for sh:deactivated that is not
"true"^^xsd:boolean
is an ill-formed shape in G
A shape code>s is a shape in an RDF graph G
with "true"^^xsd:boolean
as a value for sh:deactivated is a deactivated shape.
A deactivated shape conforms to all RDF terms.
A constraint component is one of the IRIs so-described in the rest of this document. Each constraint component has one or more **mandatory parameters**, each of which is a property. Each constraint component has zero or more **optional parameters**, each of which is a property. The parameters of a constraint component are its mandatory parameters plus its optional parameters. Some parameters of a constraint component are list-taking parameters. A parameter that forces expected type sh:Shape on objects of triples with with it as predicate or members of such objects is a shape-inducing parameter.
For a constraint component c
with mandatory parameters p1, ..., pn a shape s
in a shapes graph S
has a constraint of type c
with mandatory
parameter values <p1,v1>, ..., <pn,vn>
in S
when s
has vi as a value for
pi in S
. If s
in S
has a constraint of type c
in S
then
the optional
parameter values of the constraint in S
are all the <oi,vi>
where oi is an
optional parameter of c
and s
has vi as a value for oi in S
.
The parameter values of a constraint are its manadatory parameter values and
its optional parameter values.
A shape s1
in an RDF graph G
refers to shape s2 in G
if it
has s2
as value for some non-list-taking, shape-inducing parameter of some
constraint component or s2 as a member of the value for some list-taking,
shape-inducing parameter of some constraint component.
A shape in an RDF graph G
is a recursive shape in G
if it is related to
itself
by the transitive closure of the refers relationship in G
. An RDF graph G
that contains a recursive shape in G
is recursive.
The complete targets from a data graph D
for a shape s
in a shapes
graph
S is the union of the targets from D
for s
in S
as defined in the
reminder f
this
section.
If s
is a shape in an RDF graph G
with a value for sh:targetNode in
G
that
is not an IRI or literal then s
is an ill-formed shape in G
.
If s
is a shape in a shapes graph S
and s
has value t for
sh:targetNode in S
then { t } is a target from any data graph for s
in S
.
The remainder of this section is informative.
With the example data below, only ex:Alice
is the target of the provided shape:
ex:PersonShape a sh:Shape ; sh:targetNode ex:Alice .
ex:Alice a ex:Person .
ex:Bob a ex:Person .
If s
is a shape in an RDF graph G
with a value for sh:targetClass in
G
that
is not an IRI then s
is an ill-formed shape in G
.
If s
is a shape in a shapes graph S
and s
has value c
for
sh:targetClass in
S
then the set of SHACL instances of c
in a data graph D
is a **target**
from D
for s
in S
.
The remainder of this section is informative.
ex:PersonShape a sh:Shape ; sh:targetClass ex:Person .
ex:Alice a ex:Person . ex:Bob a ex:Person . ex:NewYork a ex:Place .
In this example, only ex:Alice
and ex:Bob
are target nodes.
Note that, according to the SHACL instance definition, all the
rdfs:subClassOf
declarations needed to walk the class hierarchy need to exist in
the data graph.
However, the ex:Person a rdfs:Class
triple is not required to exist in either
graphs.
In the following example, the only target node is ex:Who
.
ex:Doctor rdfs:subClassOf ex:Person .
ex:Who a ex:Doctor .
ex:House a ex:Nephrologist .
If s
is a shape in an RDF graph G
and s
is also a SHACL instance
of
rdfs:Class in G
and s
is not an IRI then s
is an ill-formed
shape in G
.
If s
is a shape in a shapes graph S
and s
is also a SHACL
instance of
rdfs:Class in S
then the set of SHACL instances of s
in a data graph
D
is a
**target** from D
for s
in S
.
The remainder of this section is informative.
ex:Person a rdfs:Class, sh:Shape .
ex:Alice a ex:Person .
ex:NewYork a ex:Place .
In this example, only ex:Alice
is a target node, because it is a SHACL instance of
ex:Person
which is both a class and a shape in the shapes graph.
A shape in an RDF graph G
with a value for sh:targetSubjectsOf in G
that is
not an IRI is an **ill-formed** shape in G
.
If s
is a shape in a shapes graph S
and s
has value
p
for sh:targetSubjectsOf
in S
then the set of nodes in a data graph D
that are subjects of RDF
triples in D
with predicate p
is a **target** from D
for
s
in S
.
The remainder of this section is informative.
ex:TargetSubjectsOfExampleShape a sh:Shape ; sh:targetSubjectsOf ex:knows .
ex:Alice ex:knows ex:Bob .
ex:Bob ex:livesIn ex:NewYork .
In the example above, only ex:Alice
is validated against the given shape,
because it is the subject of a triple that has ex:knows
as its
predicate.
A shape in an RDF graph G
with a value for sh:targetObjectsOf in G
that is
not an IRI is an ill-formed shape in G
.
If s
is a shape in a shapes graph S
and s
has value
p
for sh:targetObjectsOf
in S
then the set of nodes in a data graph D
that are objects of RDF triples
in D
with predicate p
is a **target** from D
for s
in S
.
The remainder of this section is informative.
ex:TargetObjectsOfExampleShape a sh:Shape ; sh:targetObjectsOf ex:knows .
ex:Alice ex:knows ex:Bob .
ex:Bob ex:livesIn ex:NewYork .
In the example above, only ex:Bob
is validated against the given shape,
because it is the object of a triple that has ex:knows
as its
predicate.
A shape in an RDF graph G
with a value for sh:path
in G
that is an
ill-formed property path in G
is an ill-formed shape in G
. A shape
in
an RDF graph G
with more than one value for sh:path
in G
is an ill-formed
shape in G
.
Given f
an RDF term, D
a data graph, and s
a shape in S
a shapes graph
the value nodes of f
with D
for s
in
S
is the set
containing
the values of f
for path(p,S) in D
if s
has p
as value
for sh:path
in S, or just f
if s
has no value for sh:path
in S
.
This section covers shape annotation properties that are ignored by SHACL processors. The use of these properties is entirely optional and not subject to formal interpretation contracts. They MAY be used for purposes such as form building or predictable printing of RDF files.
Shapes may have one or more values for sh:name
to provide human-readable labels for the
Shape.
Similarly, shapes may have one or more values for sh:description
to
provide a description of the shape.
Both sh:name
and sh:description
may have multiple values, but should
only have one value per language tag.
Shapes may have one value for the property sh:order
to indicate the relative order
of the shape for purposes such as form building.
The values of sh:order
are decimals.
If present, the recommended use of sh:order
is to sort shapes in an ascending order, for
example so that
properties with smaller order are placed above (or to the left) of properties with larger order.
rename to shapeGroup?
Shapes may link to an SHACL instance of the class sh:PropertyGroup
using the
property sh:group
to indicate that
the shape belongs to a group of related shapes.
Each group may have additional triples that serve application purposes, such as an
rdfs:label
for form building.
Groups may also have an sh:order
property to indicate the relative ordering of groups
within the same form.
Shapes may have a single value for sh:defaultValue
.
The default value does not have fixed semantics in SHACL, but MAY be used by user interface tools to
pre-populate input widgets.
The value type of the sh:defaultValue
should align with the specified
sh:datatype
or sh:class
of the same constraint.
The remainder of this section is informative.
The following example illustrates the use of these various features together.
ex:PersonFormShape a sh:Shape ; sh:shape [ sh:path ex:firstName ; sh:name "first name" ; sh:description "The person's given name(s)" ; sh:order 0 ; sh:group ex:NameGroup ; ] ; sh:shape [ sh:path ex:lastName ; sh:name "last name" ; sh:description "The person's last name" ; sh:order 1 ; sh:group ex:NameGroup ; ] ; sh:shape [ sh:path ex:streetAddress ; sh:name "street address" ; sh:description "The street address including number" ; sh:order 11 ; sh:group ex:AddressGroup ; ] ; sh:shape [ sh:path ex:locality ; sh:name "locality" ; sh:description "The suburb, city or town of the address" ; sh:order 12 ; sh:group ex:AddressGroup ; ] ; sh:shape [ sh:path ex:postalCode ; sh:name "postal code" ; sh:name "zip code"@en-US ; sh:description "The postal code of the locality" ; sh:order 13 ; sh:group ex:AddressGroup ; ] . ex:NameGroup a sh:PropertyGroup ; sh:order 0 ; rdfs:label "Name" . ex:AddressGroup a sh:PropertyGroup ; sh:order 1 ; rdfs:label "Address" .
A form building application MAY use the information above to display information as follows:
first name: | John |
last name: | Doe |
street address: | 123 Silverado Ave |
locality: | Cupertino |
zip code: | 54321 |
Validation is the main relationship defined in SHACL, usually producing a validation report containing the results of the validation. There are generally many different possible validation reports for a particular validation. Conformance checking is a simplified version of validation, usually producing a boolean result.
Validation and conformance checking can result in a failure. For example, a particular SHACL processor might allow recursive shapes but report a failure if it detects a loop. Failure can also be reported due to resource exhaustion. Failures are signalled through implementation-specific channels.
Given G
a data graph and S
a shapes graph, a results graph for the
validation of G
against S
is a combination of some multiset
{{ R1, ..., Rn}}
where { s1, ..., sn }
is the set of shapes in S
and Ri
is a results graph
for the validation of G
against si in S
. A validation report for the
validation of G
against S
is a validation report for some results graph for
the validation of G
against S
.
A data graph D
conforms to a shapes graph S
if and only there is a results graph for the validation of D
against
S
that contains no top-level validation results.
Given G
a data graph and s
a shape in S
a shapes graph, a **results
graph**
for the validation of G
against s
in S
is a combination of some
multiset {{
R1, ..., Rn }} where { t1, ..., tn } is the complete targets from G
for s
in
S and Ri is a results graph for the validation of ti using G
against s
in
S
.
A data graph D
**conforms** to a shape s
in a shapes graph S
if and
only
there is a results graph for the validation of D
against s
in S
that
contains no top-level validation results.
Given f
an RDF term, D
a data graph, and s
a shape in a shapes graph
S
a
**results graph** for the validation of f
using G
against s
in S
is a
combination of some multiset {{ R1, ..., Rn }} where { c1, ..., cn } is the
constraints of s
in S
, Ri is an element of results(f,V,D,ci,s,S), and
V
is
the value nodes of f
with D
for s
in S
. An RDF term and
a data graph
D
**conforms** to a shape s
in a shapes graph S
if and only if there is a
results graph for the validation of the RDF term using D
against s
in
S
that
contains no top-level validation results.
Note that although there can be multiple possible results graphs for a particular validation, if any results graph for the validation has no top-level validation results they will all have no top-level validation results.
This section defines the SHACL constraint components along with their parameters and how they participate in validation. The choice of constraint components that were included into the SHACL was made based on the requirements collected by the [[shacl-ucr]] document.
Given an RDF term f, a set of RDF terms V
, a data graph D, a constraint c,
and a shape s
in a shapes graph S
the possible **results of validating** f
and v
with D
against c
in S
, results(f,V,D,c,s,S)
, is a set
of results
structures as defined in this section.
sh:ClassConstraintComponent
is a constraint component with mandatory
parameter sh:class
.
A shape in an RDF graph with a value for sh:class
in G
that is not
an IRI is an ill-formed shape in G
.
Each results structure in
where results(f,V,D,c,s,S)
c
has type
sh:ClassConstraintComponent
and parameter values <sh:class,c>
contains a different top-level validation result from f,v,D,c,s,S
for each v
in V
that is not a SHACL instance of c
in D
and no other top-level validation results.
The remainder of this section is informative.
ex:ClassExampleShape
a sh:Shape ;
sh:targetNode ex:Bob, ex:Alice, ex:Carol ;
sh:shape [
sh:path ex:knows ;
sh:class ex:Person ;
] .
ex:Alice a ex:Person .
ex:Bob ex:knows ex:Alice .
ex:Carol ex:knows ex:Bob .
sh:DatatypeConstraintComponent is a constraint component with mandatory parameter sh:datatype.
A shape in an RDF graph G
with a value for sh:datatype in G
that is not an IRI is an ill-formed shape in G
.
Each results structure in results(f,V,D,c,s,S)
where c
is a constraint that
has kind sh:DatatypeConstraintComponent and that has mandatory parame-
ter values <sh:datatype, x>
contains a different top-level validation result from
f,v,D,c,s,S
for each v
in V
that is not a literal with datatype x, and no other
top-level validation results.
The remainder of this section is informative.
ex:DatatypeExampleShape
a sh:Shape ;
sh:targetNode ex:Alice, ex:Bob, ex:Carol ;
sh:shape [
sh:path ex:age ;
sh:datatype xsd:integer ;
] .
ex:Alice ex:age "23"^^xsd:integer . ex:Bob ex:age "twenty two" . ex:Carol ex:age "23"^^xsd:int .
sh:NodeKindConstraintComponent is a constraint component with manda-
tory parameter sh:nodeKind. A shape in an RDF graph G
with a value for
sh:nodeKind in G
that is not one of sh:BlankNode, sh:IRI, or sh:Literal is
an ill-formed shape in G
.
Each results structure in results(f,V,D,c,s,S)
where c
is a constraint that
has kind sh:NodeKindConstraintComponent and that has mandatory parame-
ter values <sh:nodeKind, x>
contains a different top-level validation result from
f,v,D,c,s,S
for each v
in V
that is not a blank node if x is sh:BlankNode, not
an IRI if x is sh:IRI, or not a literal if x is sh:Literal, and no other top-level
validation results.
The remainder of this section is informative.
ex:NodeKindExampleShape
a sh:Shape ;
sh:targetNode ex:Bob, ex:Alice ;
sh:shape [
sh:path ex:knows ;
sh:nodeKind ex:IRI ;
] .
ex:Bob ex:knows ex:Alice .
ex:Alice ex:knows "Bob" .
sh:MinCountConstraintComponent is a constraint component with mandatory parameter sh:minCount
A shape in an RDF graph G
with a value for sh:minCount in G
that is not a
literal with datatype xsd:integer is an ill-formed shape in G
.
Each results structure in results(f,V,D,c,s,S)
where c
has type
sh:MinCountConstraintComponent and parameter values <sh:minCount,i>
contains
a single top-level validation result from f,D,c,s,S and no other top-level
validation results if the cardinality of V
is less than the *literal value*
of i, and no top-level validation results otherwise.
The remainder of this section is informative.
ex:MinCountExampleShape
a sh:Shape ;
sh:targetNode ex:Alice, ex:Bob ;
sh:shape [
sh:path ex:name ;
sh:minCount 1 ;
] .
ex:Alice ex:name "Alice" .
ex:Bob ex:givenName "Bob"@en .
sh:MaxCountConstraintComponent is a constraint component with manda-
tory parameter sh:maxCount. A shape in an RDF graph G
with a value for
sh:maxCount in G
that is not a literal with datatype xsd:integer is an ill-
formed shape in G
.
Each results structure in results(f,V,D,c,s,S)
where c
is a constraint that
has kind sh:MaxCountConstraintComponent and that has mandatory param-
eter values <sh:maxCount, i>
contains a single top-level validation result from
f,D,c,s,S and no other top-level validation results if the cardinality of v is greater
than the literal value of i, and no top-level validation results otherwise.
The remainder of this section is informative.
ex:MaxCountExampleShape
a sh:Shape ;
sh:targetNode ex:Bob ;
sh:shape [
sh:path ex:birthDate ;
sh:maxCount 1 ;
] .
ex:Bob ex:birthDate "May 5th 1990" .
sh:MinExclusiveConstraintComponent is a constraint component with mandatory parameter sh:minExclusive
A shape in an RDF graph G
with a value for sh:minExclusive in G
that is not
suitable for use in the SPARQL operator <
is an ill-formed shape in G
.
Each results structure in results(f,V,D,c,s,S)
where c
has type
sh:MinExclusiveConstraintComponent and parameter values <sh:minExclusive,i>
contains a different top-level validation result from f,v,D,c,s,S
for each v
in V
for which m < v
returns false or produces an error
in SPARQL and no other top-level validation results.
sh:MinInclusiveConstraintComponent is a constraint component with mandatory parameter sh:minInclusive.
A shape in an RDF graph G
with a value
for sh:minInclusive in G
that is not suitable for use in the SPARQL operator <=
is an ill-formed shape in G
.
Each results structure in results(f,V,D,c,s,S)
where c
is a constraint that
has kind sh:MinInclusiveConstraintComponent and that has mandatory parameter values
<sh:minInclusive, i> contains different top-level validation result from
f,v,D,c,s,S
for each v
in V
for which i <= v
returns false or produces
an error in SPARQL, and no other top-level validation results.
sh:MaxExclusiveConstraintComponent is a constraint component with mandatory
parameter sh:maxExclusive. A shape in an RDF graph G
with a value
for sh:maxExclusive in G
that is not suitable for use in the SPARQL operator
>
is an ill-formed shape in G
.
Each results structure in results(f,V,D,c,s,S)
where c
is a constraint that
has kind sh:MaxExclusiveConstraintComponent and that has mandatory pa-
rameter values <sh:maxExclusive, i>
contains a different top-level validation
result from f,v,D,c,s,S
for each v
in V
for which i > v
returns false or produces an
error in SPARQL, and no other top-level validation results.
sh:MaxInclusiveConstraintComponent is a constraint component with mandatory
parameter sh:maxInclusive. A shape in an RDF graph G
with a value
for sh:maxInclusive in G
that is not suitable for use in the SPARQL operator
>=
is an ill-formed shape in G
.
Each results structure in results(f,V,D,c,s,S)
where c
is a constraint that
has kind sh:MaxInclusiveConstraintComponent and that has mandatory pa-
rameter values <sh:maxInclusive, i>
contains a different top-level validation
result from f,v,D,c,s,S
for each v
in V
for which i >= v
returns false or produces
an error in SPARQL, and no other top-level validation results.
sh:MinLengthConstraintComponent is a constraint component with man-
datory parameter sh:minLength. A shape in an RDF graph G
with a value
for sh:minLength in G
that is not a literal with datatype xsd:integer is an
ill-formed shape in G
.
Each results structure in results(f,V,D,c,s,S)
where c
is a constraint that
has kind sh:MinLengthConstraintComponent and that has mandatory parameter
values <sh:minLength, i>
contains a different top-level validation result from
f,v,D,c,s,S
for each v
in V
that is a blank node or where the length of its string
representation (as defined by the SPARQL str function) is less than the literal
value of i, and no other top-level validation results.
sh:MaxLengthConstraintComponent is a constraint component with mandatory
parameter sh:maxLength. A shape in an RDF graph G
with a value
for sh:maxLength in G
that is not a literal with datatype xsd:integer is an
ill-formed shape in G
.
Each results structure in results(f,V,D,c,s,S)
where c
is a constraint that
has kind sh:MaxLengthConstraintComponent and that has mandatory parameter
values <sh:maxLength, i>
contains a different top-level validation result from
f,v,D,c,s,S
for each v
in V
that is a blank node or where the length of its string
representation (as defined by the SPARQL str function) is greater than the
literal value of i, and no other top-level validation results.
The remainder of this section is informative.
ex:PasswordExampleShape
a sh:Shape ;
sh:targetNode ex:Bob, ex:Alice ;
sh:shape [
sh:path ex:password ;
sh:minLength 8 ;
sh:maxLength 10 ;
] .
ex:Bob ex:password "123456789" .
ex:Alice ex:password "1234567890ABC" .
sh:LanguageInConstraintComponent is a constraint component with mandatory
list-taking parameter sh:languageIn. A shape in an RDF graph G
with
a value for sh:languageIn that is not a literal with datatype xsd:string is an
ill-formed shape in G
.
Each results structure in results(f,V,D,c,s,S)
where c
is a constraint that
has kind sh:LanguageInConstraintComponent and that has mandatory parameter
values <sh:languageIn, l>
contains a different top-level validation result
from f,v,D,c,s,S
for each v
in V
that is not a language-tagged string whose
language tag matches the literal value of one of elements of l as defined by the
SPARQL langMatches function, and no other top-level validation results.
The remainder of this section is informative.
The following example shape states that all values of ex:prefLabel
can be either in English or Māori.
ex:NewZealandLanguagesShape
a sh:Shape ;
sh:targetNode ex:Mountain, ex:Berg ;
sh:shape [
sh:path ex:prefLabel ;
sh:languageIn ( "en" "mi" ) ;
] .
From the example instances, ex:Berg
will lead to constraint violations for all
of its labels.
ex:Mountain
ex:prefLabel "Mountain"@en ;
ex:prefLabel "Hill"@en-NZ ;
ex:prefLabel "Maunga"@mi .
ex:Berg
ex:prefLabel "Berg" ;
ex:prefLabel "Berg"@de ;
ex:prefLabel ex:BergLabel .
sh:PatternConstraintComponent is a constraint component with mandatory parameter sh:pattern and optional parameter sh:flags
A shape in an RDF graph G
with a value for sh:pattern or sh:flags in G
that
is not a literal with datatype xsd:string is an ill-formed shape in G
.
A shape in an RDF graph G
with more than one value for sh:pattern or
sh:flags in G
is an ill-formed shape in G
.
Each results structure in results(f,V,D,c,s,S)
where c
has type
sh:PatternConstraintComponent and mandatory parameter values <sh:pattern,r>
contains a different top-level validation result from f,v,D,c,s,S
for each v
in V
that is either a blank node or where the string representation (as
defined by the SPARQL str function) does not match the given regular
expression (as defined by the SPARQL REGEX function)
and no other top-level validation results.
If the constraint has optional parameter values <sh:flags,flags>
then flags is used as the third argument of the SPARQL REGEX function,
otherwise the third argument is the empty string.
The remainder of this section is informative.
ex:PatternExampleShape
a sh:Shape ;
sh:targetNode ex:Bob, ex:Alice, ex:Carol ;
sh:shape [
sh:path ex:bCode ;
sh:pattern "^B" ; # starts with 'B'
sh:flags "i" ; # Ignore case
] .
ex:Bob ex:bCode "b101" .
ex:Alice ex:bCode "B102" .
ex:Carol ex:bCode "C103" .
sh:UniqueLangConstraintComponent is a constraint component with mandatory parameter sh:uniqueLang
A shape in an RDF graph G
with a value for sh:uniqueLang in G
that is not
"true"^^xsd:boolean is an ill-formed shape in G
.
Each results structure in results(f,V,D,c,s,S)
where c
has type
sh:UniqueLangConstraintComponent and parameter values <sh:uniqueLang,t>
contains a different top-level validation result from f,v,D,c,s,S
for each v
in V
that is is a language-tagged literal with the same language
tag as some other element of V
and no other top-level validation results.
The remainder of this section is informative.
ex:UniqueLangExampleShape
a sh:Shape ;
sh:targetNode ex:Alice, ex:Bob ;
sh:shape [
sh:path ex:label ;
sh:uniqueLang true ;
] .
ex:Alice
ex:label "Alice" ;
ex:label "Alice"@en ;
ex:label "Alice"@fr .
ex:Bob
ex:label "Bob"@en ;
ex:label "Bobby"@en .
sh:EqualsConstraintComponent is a constraint component with mandatory
parameter sh:equals
A shape in an RDF graph G
with a value for sh:equals in G
that is not an IRI
is an ill-formed shape in G
.
Each results structure in results(f,V,D,c,s,S)
where c
has type
sh:EqualsConstraintComponent and parameter values <sh:equals,p>
contains a different top-level validation result from f,v,D,c,s,S
for each v
in V
that is not a value of f
for p
in D
and for each value of f
for p
in D
that is not in V
and no other top-level validation results.
The remainder of this section is informative.
ex:EqualExampleShape
a sh:Shape ;
sh:targetNode ex:Bob ;
sh:shape [
sh:path ex:firstName ;
sh:equals ex:givenName ;
] .
ex:Bob ex:firstName "Bob" ; ex:givenName "Bob" .
sh:DisjointConstraintComponent is a constraint component with mandatory parameter sh:disjoint
A shape in an RDF graph G
with a value for sh:disjoint in G
that is not an
IRI is an ill-formed shape in G
.
Each results structure in results(f,V,D,c,s,S)
where c
has type
sh:DisjointConstraintComponent and parameter values <sh:disjoint,p>
contains a different top-level validation result from f,v,D,c,s,S
for each v
in V
that is also a value of f
for p
in
D
and no other top-level validation results.
The remainder of this section is informative.
The following example illustrates the use of sh:disjoint
in a shape to specify
that certain nodes cannot share any values for ex:prefLabel
and ex:altLabel
.
ex:DisjointExampleShape
a sh:Shape ;
sh:targetNode ex:USA, ex:Germany ;
sh:shape [
sh:path ex:prefLabel ;
sh:disjoint ex:altLabel ;
] .
ex:USA
ex:prefLabel "USA" ;
ex:altLabel "United States" .
ex:Germany
ex:prefLabel "Germany" ;
ex:altLabel "Germany" .
sh:LessThanConstraintComponent is a constraint component with mandatory
parameter sh:lessThan. A shape in an RDF graph G
with a value for
sh:lessThan in G
that is not an IRI is an ill-formed shape in G
.
Each results structure in results(f,V,D,c,s,S)
where c
is a constraint that
has kind sh:LessThanConstraintComponent and that has mandatory parameter
values <sh:lessThan, p>
contains a different top-level validation result from
f,v,D,c,s,S
for each v
in V
that does not compare as less than each value of f
for p in G
using SPARQL operator <
, and no other top-level validation results.
Note: A comparison that produces an error counts as not comparing as less than.
The remainder of this section is informative.
The following example illustrates the use of sh:lessThan
in a shape to specify
that all values of ex:startDate
are "before" the values of ex:endDate
.
ex:LessThanExampleShape a sh:Shape ; sh:shape [ sh:path ex:startDate ; sh:lessThan ex:endDate ; ] .
sh:LessThanOrEqualsConstraintComponent is a constraint component with
mandatory parameter sh:lessThanOrEquals. A shape in an RDF graph G
with
a value for sh:lessThanOrEquals in G
that is not an IRI is an ill-formed shape
in G
.
Each results structure in results(f,V,D,c,s,S)
where c
is a constraint that
has kind sh:LessThanOrEqualsConstraintComponent and that has mandatory
parameter values <sh:lessThanOrEquals, p>
contains a different top-level val-
idation result from f,v,D,c,s,S
for each v
in V
that does not compare as less
than or equal each value of f for p in G
using SPARQL operator <=
, and no
other top-level validation results.
Note: A comparison that produces an error counts as not comparing as less than or equals.
sh:ShapeConstraintComponent is a constraint component with mandatory parameter sh:shape
A shape in an RDF graph G
with a value for sh:shape in G
that is not an IRI
or blank node is an ill-formed shape in G
.
If s
is the object of an RDF triple in an RDF graph G
with
predicate sh:shape then s
has **expected type** sh:shape in G
.
Each results structure in results(f,V,D,c,s,S)
where s
is not recursive and c
has type sh:ShapeConstraintComponent and parameter values <sh:shape,x>
contains a different top-level validation result from f,v,D,c,s,S
for each v
in V
where v
and D
do not conform to x in S
and no other
top-level
validation results.
The remainder of this section is informative.
In the following example, all values of the property ex:someProperty
will validate with no
results for the shape
specified by a blank node that ensures that the property ex:nestedProperty
has at least one
value.
ex:ShapeExampleShape a sh:Shape ; sh:shape [ sh:path ex:someProperty ; sh:shape [ a sh:Shape ; # Optional sh:shape [ sh:path ex:nestedProperty ; sh:minCount 1 ; ] ] ] .
ex:ShapeExampleValidResource ex:someProperty [ ex:nestedProperty 42 ; ] .
sh:NotConstraintComponent is a constraint component with mandatory
parameter sh:not. A shape in an RDF graph G
with a value for sh:not in G
that is not an IRI or blank node is an ill-formed shape in G
. If s is the object of
an RDF triple in an RDF graph G
with predicate sh:not then s has expected
type sh:shape in G
.
Each results structure in results(f,V,D,c,s,S)
where s is not recursive and c
is a constraint that has kind sh:NotConstraintComponent and that has mandatory
parameter values <sh:not, x>
contains a different top-level validation result
from f,v,D,c,s,S
for each v
in V
where v and D do conform to x in S, and no
other top-level validation results.
The remainder of this section is informative.
The following example illustrates the use of sh:not
in a shape to specify the condition
that certain nodes cannot have any value of ex:property
.
ex:NotExampleShape
a sh:Shape ;
sh:targetNode ex:InvalidInstance1 ;
sh:not [
a sh:Shape ;
sh:shape [
sh:path ex:property ;
sh:minCount 1 ;
] ;
] .
ex:InvalidInstance1 ex:property "Some value" .
sh:AndConstraintComponent is a constraint component with mandatory list-taking parameter sh:and
A shape in an RDF graph G
with a value for sh:and in G
that is not a SHACL
list in G
whose members in G
are all IRIs or blank nodes in G
is an
ill-formed shape in G
.
If s
is a member of a SHACL list in an RDF graph G
that is the object of an
RDF triple in G
with predicate sh:and then s
has **expected type** sh:shape
in G
.
Each results structure in results(f,V,D,c,s,S)
where s
is not recursive and c
has type sh:AndConstraintComponent and parameter values <sh:and,l>
contains
a different top-level validation result from f,v,D,c,s,S
for each v
in
V
where v
and D
do not conform to each element of l in S
and no other
top-level validation results.
The remainder of this section is informative.
The following example illustrates the use of sh:and
in a shape to specify the condition
that certain nodes have exactly one value of ex:property
.
This is achieved via the conjunction of a separate named shape (ex:SuperShape
) which specifies
the minimum count, and a blank node shape that additionally specifies the maximum count.
As shown here, sh:and
can be used to implement a specialization mechanism between shapes.
ex:SuperShape
a sh:Shape ;
sh:shape [
sh:path ex:property ;
sh:minCount 1 ;
] .
ex:ExampleAndShape
a sh:Shape ;
sh:targetNode ex:ValidInstance, ex:InvalidInstance ;
sh:and (
ex:SuperShape
[
a sh:Shape ;
sh:shape [
sh:path ex:property ;
sh:maxCount 1 ;
]
]
) .
ex:ValidInstance
ex:property "One" .
# Invalid: more than one property
ex:InvalidInstance
ex:property "One" ;
ex:property "Two" .
sh:OrConstraintComponent is a constraint component with mandatory
list-taking parameter sh:or. A shape in an RDF graph G
with a value for sh:or in
G that is not an ASHACL list in G
whose members in G
are all IRIs or blank
nodes in G
is an ill-formed shape in G
. If s is a member of an ASHACL list in
an RDF graph G
that is the object of an RDF triple in G
with predicate sh:or
then s has expected type sh:shape in G
.
Each results structure in results(f,V,D,c,s,S)
where s is not recursive and
c is a constraint that has kind sh:OrConstraintComponent and that has mandatory
parameter values <sh:or, l>
contains a different top-level validation result
from f,v,D,c,s,S
for each v
in V
where v and D do not conform to any element
of l in S, and no other top-level validation results.
The remainder of this section is informative.
The following example illustrates the use of sh:or
in a shape to specify the condition
that certain nodes have at least one value of ex:firstName
or at least one value of ex:givenName
.
ex:OrConstraintExampleShape
a sh:Shape ;
sh:targetNode ex:Bob ;
sh:or (
[
sh:property [
sh:predicate ex:firstName ;
sh:minCount 1 ;
]
]
[
sh:property [
sh:predicate ex:givenName ;
sh:minCount 1 ;
]
]
) .
ex:Bob ex:firstName "Robert" .
The next example shows how sh:or
can be used in a shape to state that the values of
the given property ex:address
may be either literals with datatype xsd:string
or SHACL instances of the class ex:Address
.
ex:PersonAddressShape
a sh:Shape ;
sh:targetClass ex:Person ;
sh:property [
sh:predicate ex:address ;
sh:or (
[
sh:datatype xsd:string ;
]
[
sh:class ex:Address ;
]
)
] .
ex:Bob ex:address "123 Prinzengasse, Vaduz, Liechtenstein" .
sh:QualifiedValueShapeConstraintComponent is a constraint component with mandatory parameter sh:qualifiedValueShape and optional parameters sh:qualifiedMinCount and sh:qualifiedMaxCount
A shape in an RDF graph G
with a value for sh:qualifiedValueShape in G
that
is not an IRI or blank node is an ill-formed shape in G
.
A shape in an RDF graph G
with a value for sh:qualifiedMinCount or
sh:qualifiedMaxCount in G
that is not a literal with dataype xsd:integer is
an ill-formed shape in G
.
A shape in an RDF graph G
with more than one value for
sh:qualifiedValueShape, sh:qualifiedMinCount, or sh:qualifiedMaxCount in G
is an ill-formed shape in G
.
A shape in an RDF graph G
that has a value for sh:qualifiedValueShape in G
but no value for sh:qualifiedMinCount in G
and no value for
sh:qualifiedMaxCount in G
is an ill-formed shape in G
.
If s
is the object of an RDF triple in an RDF graph G
with predicate
sh:qualifiedValueShape then s
has **expected type** sh:shape in G
.
Each results structure in results(f,V,D,c,s,S)
where s
is not recursive and c
has type sh:QualifiedValueShapeConstraintComponent and mandatory parameter
values <sh:qualifiedValueShape,x>
contains a single top-level validation result from f,D,c,s,S
and no other top-level validation results
if the number of elements v
of V
where where v
and D
conform
to
x in S
is less than the value of min if <sh:qualifiedMinCount,min>
is in the
optional parameters of the constraint or is greater than the value of max if
<sh:qualifiedMaxCount,max>
is in the optional parameters of the constraint,
and no top-level validation results otherwise.
The remainder of this section is informative.
In the following example shape can be used to specify the condition that the property ex:parent
has exactly two values,
and at least one of them is female.
ex:QualifiedValueShapeExampleShape
a sh:Shape ;
sh:targetNode ex:QualifiedValueShapeExampleValidResource ;
sh:shape [
sh:path ex:parent ;
sh:minCount 2 ;
sh:maxCount 2 ;
sh:qualifiedValueShape [
a sh:Shape ; # Optional
sh:shape [
sh:path ex:gender ;
sh:hasValue ex:female ;
]
] ;
sh:qualifiedMinCount 1 ;
] .
ex:QualifiedValueShapeExampleValidResource ex:parent ex:John ; ex:parent ex:Jane . ex:John ex:gender ex:male . ex:Jane ex:gender ex:female .
sh:ClosedConstraintComponent is a constraint component with mandatory parameter sh:closed and optional list-taking parameter sh:ignoredProperties
A shape in an RDF graph G
with a value for sh:closed in G
that is not
"true"^^xsd:boolean is an ill-formed shape in G
.
A shape in an RDF graph G
with a value for sh:ignoredProperties in G
that is
not a SHACL list in G
whose members in G
are all IRIs is an **ill-formed
shape** in G
.
A shape in an RDF graph G
with more than one value for sh:closed or
sh:ignoredProperties in G
is an ill-formed shape in G
.
Each results structure in results(f,V,D,c,s,S)
where c
has type
sh:ClosedConstraintComponent and mandatory parameter values <sh:closed,t>
contains a different top-level validation result from f,v,D,c,s,S
for each RDF triple in D
with subject f
whose predicate is
not a value of some value of s
for sh:shape in D
for sh:path
in
D
and not a member of i in D
if the constraint has
optional parameter values <sh:ignoredProperties,i>
and no other top-level validation results.
The remainder of this section is informative.
The following example illustrates the use of sh:closed
in a shape to specify the condition
that certain nodes only have values for ex:exampleProperty1
and
ex:exampleProperty2
.
The "ignored" property rdf:type
would also be allowed.
ex:ClosedShapeExampleShape
a sh:Shape ;
sh:targetNode ex:Alice, ex:Bob ;
sh:closed true ;
sh:ignoredProperties (rdf:type) ;
sh:shape [
sh:path ex:firstName ;
] ;
sh:shape [
sh:path ex:lastName ;
] .
ex:Alice
ex:firstName "Alice" .
ex:Bob
ex:firstName "Bob" ;
ex:middleInitial "J" .
sh:HasValueConstraintComponent is a constraint component with mandatory parameter sh:hasValue.
Each results structure in results(f,V,D,c,s,S)
where c
has type
sh:HasValueConstraintComponent and mandatory parameter values
<sh:hasValue,x> contains a single top-level validation result from f,D,c,s,S
and no other top-level validation results if x is not in V
, and no top-level
validation results otherwise.
The remainder of this section is informative.
ex:StanfordGraduate
a sh:Shape ;
sh:targetNode ex:Alice ;
sh:shape [
sh:path ex:alumniOf ;
sh:hasValue ex:Stanford ;
] .
ex:Alice ex:alumniOf ex:Harvard ; ex:alumniOf ex:Stanford .
sh:InConstraintComponent is a constraint component with mandatory list-taking parameter sh:in.
A shape in an RDF graph G
with a value for sh:in in G
that is not a SHACL
list in G
whose members in G
are all IRIs or blank nodes in G
is an
ill-formed shape in G
.
Each results structure in results(f,V,D,c,s,S)
where c
has type
sh:InConstraintComponent and parameter values <sh:in,x>
contains
a different top-level validation result from f,v,D,c,s,S
for each v
in
V
where v
is not a member of x in S
and no other top-level validation results.
The remainder of this section is informative.
ex:InExampleShape
a sh:Shape ;
sh:targetNode ex:RainbowPony ;
sh:shape [
sh:path ex:color ;
sh:in ( ex:Pink ex:Purple ) ;
] .
ex:RainbowPony ex:color ex:Pink .
A SHACL processor MUST provide an interface that takes two RDF graphs - a data graph and a potential shapes graph.
A SHACL processor SHOULD provide an interface similar to above except that any return value is a boolean indicating whether the data graph conforms to the potential shapes graph.
A SHACL processor MAY provide interfaces where the shapes graph is constructed by accessing locations that are values of RDF triples with predicate sh:shapesGraph in the data graph. A SHACL processor MAY provide interfaces that construct the potential shapes graph by taking a partial shapes graph and merging in other graphs accessible at locations that are values of RDF triples with predicate owl:imports in the potential shapes graph being consructed.
If a SHACL processor accesses persistent representations of RDF graphs to validate a data graph against a potential shapes graph it MUST not change any of these representations. A SHACL processor MAY store any representation of a validation report that it constructs so long as the processor does not not violate the previous requirement.
By default, SHACL does not assume any entailment regime [[!sparql11-entailment]] to be
activated on the data graph.
However, the property sh:entailment
can be used in the shapes graph to instruct a SHACL
processor to ensure that a given entailment is activated on the data graph.
The values of sh:entailment
are IRIs, with common use cases covered by
[[!sparql11-entailment]].
SHACL processors are not required to support any entailment regimes. If an entailment regime is provided in the shapes graph which is not supported by the SHACL processor, the validation MUST produce a failure.
Many people contributed to this specification, including members of the RDF Data Shapes Working Group. We especially thank the following:
Arnaud Le Hors (chair), Jim Amsden, Iovka Boneva, Karen Coyle, Richard Cyganiak, Michel Dumontier, Holger Knublauch, Dimitris Kontokostas, Jose Labra, Peter Patel-Schneider (who contributed parts of this specification even outside the WG), Eric Prud'hommeaux, Arthur Ryman (who also served as a co-editor until Feb 2016), Harold Solbrig, Simon Steyskal, Ted Thibodeau