This document defines an abstract syntax for the core SHACL (SHApes Constraint Language). It is derived from the SHACL specification[[!shacl]] and is a non-normative version of the content of that specification.

This document is no longer maintained and is out of date.

Introduction

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.

Scope of This Document

This abstract syntax describes the SHACL Core language as specified in sections 2 and 4 of the Shapes Constraint Language document.

Notation

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:

Shape := 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 Targets, the filters are a set of Shapes, and the constraints is a set of Constraints. 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:

shapenoderesultreason
<Shape1><node1>pass
<Shape1><node2>failno ex:state supplied.

These are the namespace prefixes used in the examples:

Schemas and Shapes

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."

Schema := shapes:Set[Shape]
Shape := label:IRI|BNode, targets:Set[Target], filters:Set[Shape], constraints:Set[Test]
Test := Constraint|Algebraic

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:

  1. match any of the targets, and
  2. pass all of the filter Shapes. [deal with this somewhere (Targets in filter Shapes have no effect.)]

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.

Constraints

Constraint := NodeConstraint|PathConstraint|PartitionConstraint

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.

NodeConstraint := 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.

PathConstraint := 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, path, value node). The path is an expression in the SPARQL1.1 Property Path language excluding the forms of negation: NegatedPropertySet. Note that this includes InversePath.

PartitionConstraint := expression:Sexpr, extra:Set[IRI]
Sexpr := Choice|Group|PathConstraint
Choice := exprs:Set[Sexpr]
Group := 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:

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(T, expr, m) indicates that a set of triples T can satisfy these rules:

Partition example 1
<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" .
shapenoderesultreason
<EmployeeShape><employee1>pass
<EmployeeShape><employee2>pass
<EmployeeShape><employee3>failexpected either foaf:name or foaf:givenName and foaf:familyName.
<EmployeeShape><employee4>failexpected only one of foaf:name or foaf:givenName and foaf:familyName.

Parameters

Parameter := UnaryParameter | NaryParameter

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

Unary Parameters evaluate each node in the set of value nodes that were selected by the Constraints.

RDF term type of value node

NodeKind := kind:"IRI"|"blank node"|"literal"

Testing a NodeKind parameter against a value node returns fail if

  • kind = "IRI" and value node is not an IRI
  • kind = "blank node" and value node is not a blank node
  • kind = "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.

Parameters example 1
<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" .
shapenoderesultreason
<IssueShape><issue1>pass
<IssueShape><issue2>pass
<IssueShape><issue3>failex: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.

RDF term equivalence

In := 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.

Parameters example 3
<IssueShape> sh:property [ sh:predicate ex:state; sh:in (ex:Resolved, ex:Rejected) ] .
<issue1> ex:state ex:Resolved .
<issue2> ex:state ex:Unresolved .
shapenoderesultreason
<IssueShape><issue1>pass
<IssueShape><issue2>failex: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.

Class := t:IRI

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).

Datatype

Datatype := 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.

Parameters example 4
<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 .
shapenoderesultreason
<IssueShape><issue1>pass
<IssueShape><issue2>failex:submittedOn expected to be an xsd:date, xsd:dateTime found.

XML Schema string facets

MinLength := 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.

Parameters example 5
<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
shapenoderesultreason
<IssueShape><issue1>pass
<IssueShape><issue2>failex:submittedOn expected to be >= 20 characters,
3 characters found.
MaxLength := 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.

Pattern := 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.

Parameters example 6
<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> .
shapenoderesultreason
<IssueShape1><issue1>pass
<IssueShape1><issue2>pass
<IssueShape1><issue3>failmailto: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.
Stem := 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.

XML Schema numeric facets

MinInclusive := 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.

Parameters example 7
<IssueShape> sh:property [ sh:predicate ex:confirmations; sh:minInclusive 1 ] .
<issue1> ex:confirmations 1 .
<issue2> ex:confirmations 0 .
<issue3> ex:confirmations "ii"^^ex:romanNumeral .
shapenoderesultreason
<IssueShape><issue1>pass
<IssueShape><issue2>fail0 is less than 1.
<IssueShape><issue3>failex:romanNumeral is not a numeric datatype.
MinExclusive := 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.

MaxInclusive := 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.

MaxExclusive := 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 with specified property

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, _).

LessThanOrEquals := compareProp:RDFLiteral PC

Let compareVals be the set of objects in triples matching (focus node, compareProp, compareVal). Testing a LessThanOrEquals parameter against a value node returns fail if evaluating the SPARQL1.1 Operator (value node = 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.

Parameters example 8

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 .
shapenoderesultreason
<IssueShape><issue1>pass
<IssueShape><issue2>pass
<IssueShape><issue3>fail4 greater than 2.
<IssueShape><issue4>fail"Medium" greater than "Low".
<IssueShape><issue5>fail1 not comparable with ex:Low.
LessThan := compareProp:RDFLiteral PC

Let compareVals be the set of objects in triples matching (focus node, compareProp, compareVal). Testing a LessThan parameter against a value node returns fail if evaluating the SPARQL1.1 Operator (value node < 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.

Equals := compareProp:RDFLiteral PC

Let compareVals be the set of objects in triples matching (focus node, compareProp, compareVal). Testing an Equals parameter against a value node returns fail if evaluating the SPARQL1.1 Operator (value node = 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.

Disjoint := compareProp:RDFLiteral

Let comapreVals be the set of objects in triples matching (focus node, compareProp, compareVal). Testing a Disjoint parameter against a value node returns fail if evaluating the SPARQL1.1 Operator (value node != 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.

Nested shape constraints

HasShape := nested:Shape

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.

Parameters example 9
<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> .
shapenoderesultreason
<IssueShape><issue1>pass
<IssueShape><issue2>failexpected dc:creator to be an IRI.
<IssueShape><issue3>failexpected ex:submittedBy to match <UserShape>.

N-ary Parameters

N-ary Parameters evaluate the set of value nodes which were selected by the Constraints.

Uniqueness

UniqueLang := 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.

Parameters example 10
<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 .
shapenoderesultreason
<IssueShape><issue1>pass
<IssueShape><issue2>failmultiple ex:label values with same language tag.
<IssueShape><issue3>pass

RDF term equivalence

HasValue := 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.

Parameters example 2
<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 .
shapenoderesultreason
<ResolvedIssueShape><issue1>pass
<ResolvedIssueShape><issue2>pass
<ResolvedIssueShape><issue3>failex:state expected to be ex:Resolved, ex:Unresolved found.

Cardinality

The MinCount and MaxCount Parameters on a Constraint with property P identify the minimum and maximum number of triples (focus node, P, _) may exist in the instance data. Unless provided, the MinCount is 0 and the MaxCount in infinite.

MinCount := 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.

MaxCount := 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.

Parameters example 11
<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?" .
shapenoderesultreason
<IssueShape><issue1>pass
<IssueShape><issue2>failexpected at most 1 ex:status.
<IssueShape><issue3>failexpected at least 1 ex:status.

QualifiedCardinality

QualifiedMinCount := ref:numeric PC
QualifiedMaxCount := ref:numeric PC
QualifiedValueShape := nested:Shape PC

QualifiedMinCount 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.

Parameters example 12

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> .
shapenoderesultreason
<ApprovedIssueShape><issue1>pass
<ApprovedIssueShape><issue2>failexpected at most 1 ex:approvedBy matching
"^mailto:.*?@engineering.example".
<ApprovedIssueShape><issue3>failexpected 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>.

Logical operators

Algebraic := And|Or|Not

Algebraic operators provide logical combinations of shapes.

And := 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.

Algebraics example 1
<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 .
shapenoderesultreason
<User><user1>pass
<User><user2>fail"1234.0" is an xsd:double.
Or := 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.

Algebraics example 2
<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 .
shapenoderesultreason
<User><user1>pass
<User><user2>pass
<User><user3>pass
<User><user4>failno foaf:name supplied and
"78.0" is an xsd:double.
Not := 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.

Algebraics example 3
<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 .
shapenoderesultreason
<User><user1>failfoaf:name is an RDFLiteral and
"12" is an xsd:integer.
<User><user2>fail"34" is an xsd:integer.
<User><user3>failfoaf:name is an RDFLiteral
<User><user4>pass

Targets

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.

Target := TargetNode|TargetClass|TargetSubjectsOf|TargetObjectsOf

The simplest form of Target directly identifies nodes in the data graph:

TargetNode := 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.

Targets example 1
		<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" .
TargetClass := type:IRI

A TargetClass matches any node in the data graph with the triple (node, rdf:type, type) or any node which is of a type which is a transitive rdfs:subClassOf type.

A TargetClass is connected to a shape by the sh:targetClass property.

Targets example 2

			<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.

TargetSubjectsOf := predicate:IRI

A TargetSubjectsOf matches any subject node in the data graph with a triple (node, predicate, _) where "_" is any node.

A TargetSubjectsOf is connected to a shape by the sh:targetSubjectsOf property.

Targets example 3
		<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.

TargetObjectsOf := predicate:IRI

A TargetObjectsOf matches any object node in the data graph with a triple (_, predicate, node) where "_" is any node.

A TargetObjectsOf is connected to a shape by the sh:targetObjectsOf property.

Targets example 4
		<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.