Copyright © 2026 World Wide Web Consortium. W3C® liability, trademark and permissive document license rules apply.
This document defines the Inference Rules support of SHACL, the Shapes Constraint Language. While the Core part of SHACL focuses on the basic syntax of shapes and constraint validation of data graphs, the SHACL Inference Rules cover features that can be used to infer new triples from existing triples in the data graph.
This section describes the status of this document at the time of its publication. A list of current W3C publications and the latest revision of this technical report can be found in the W3C standards and drafts index.
This document was published by the Data Shapes Working Group as a Working Draft using the Recommendation track.
Publication as a Working Draft does not imply endorsement by W3C and its Members.
This is a draft document and may be updated, replaced, or obsoleted by other documents at any time. It is inappropriate to cite this document as other than a work in progress.
This document was produced by a group operating under the W3C Patent Policy. W3C maintains a public list of any patent disclosures made in connection with the deliverables of the group; that page also includes instructions for disclosing a patent. An individual who has actual knowledge of a patent that the individual believes contains Essential Claim(s) must disclose the information in accordance with section 6 of the W3C Patent Policy.
This document is governed by the 18 August 2025 W3C Process Document.
This specification is part of the SHACL 1.2 family of specifications. See the SHACL 1.2 Overview for a more detailed introduction to them.
The specifications are as follows:
Working Drafts:
Editor's Drafts:
Implementers can partially check their level of conformance with the above specifications by testing themselves with the test cases each presents, linked to in their metadata. Note, however, that passing all the tests in a test suite does not imply complete conformance to the specifications, it only implies that the implementation conforms to the aspects tested by the test suite.
This document specifies the Inference Rules support of the Shapes Constraint Language (SHACL).
Throughout this document, the following terminology is used.
The SHACL inference rules defined in this document are sometimes simply called SHACL rules or even rules. SHACL SPARQL rules are sometimes simply called SPARQL rules.
Inference rules should not be confused with constraints. Constraints define conditions that a data graph should conform to, while rules define how additional (implicit) statements can be derived/inferred from the statements that are explicitly asserted in a data graph.
Terminology that is linked to portions of RDF 1.2 Concepts and Abstract Syntax is used in SHACL Inference Rules as defined there. Terminology that is linked to portions of other SHACL 1.2 documents is used in SHACL Inference Rules as defined there. A single linkage is sufficient to provide a definition for all occurrences of a particular term in this document.
Definitions are complete within this document, i.e., if there is no rule to make some situation true in this document then the situation is false.
The syntax of SHACL is RDF. The examples in this document use Turtle [rdf12-turtle]. Other RDF serializations such as RDF/XML may be used in practice. The reader should be familiar with basic RDF concepts [rdf12-concepts] such as triples and with SPARQL [sparql12-query].
Within this document, the following namespace prefix bindings are used:
| Prefix | Namespace |
|---|---|
owl: |
http://www.w3.org/2002/07/owl# |
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# |
shnex: |
http://www.w3.org/ns/shacl-node-expr# |
sparql: |
http://www.w3.org/ns/sparql# |
xsd: |
http://www.w3.org/2001/XMLSchema# |
ex: |
http://example.com/ns# |
Within this document, the following JSON-LD context is used:
{
"@context": {
"owl": "http://www.w3.org/2002/07/owl#",
"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#",
"shnex": "http://www.w3.org/ns/shacl-node-expr#",
"sparql": "http://www.w3.org/ns/sparql#",
"xsd": "http://www.w3.org/2001/XMLSchema#",
"ex": "http://example.com/ns#"
}
}
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 #.
Throughout the document, color-coded boxes containing RDF graphs in Turtle will appear. These fragments of Turtle documents use the prefix bindings given above.
Grey boxes such as this include syntax rules that apply to the shapes graph.
SPARQL variables using the $ marker represent external bindings that are pre-bound in the SPARQL query before execution.
true denotes the RDF term "true"^^xsd:boolean.
false denotes the RDF term "false"^^xsd:boolean.
As well as sections marked as non-normative, all authoring guidelines, diagrams, examples, and notes in this specification are non-normative. Everything else in this specification is normative.
The key words MAY, MUST, MUST NOT, and SHOULD in this document are to be interpreted as described in BCP 14 [RFC2119] [RFC8174] when, and only when, they appear in all capitals, as shown here.
This document defines the SHACL Inference Rules framework that extends SHACL Core. This specification describes conformance criteria for:
Also see the discussion of well-formedness in the Conformance section of SHACL Core.
SHACL defines an RDF vocabulary to describe shapes - collections of constraints that apply to a set of nodes. Shapes can be associated with nodes using a flexible target mechanism, e.g. for all instances of a class. One focus area of SHACL is data validation. However, the same principles of describing data patterns in shapes can also be exploited for other purposes. SHACL rules build on SHACL to form a light-weight RDF vocabulary for the exchange of rules that can be used to derive inferred RDF triples from existing asserted triples.
The SHACL rules feature defined in this document includes a general framework using properties
such as sh:rule and sh:condition, plus an extension mechanism for specific rule types.
This document defines two such rule types: SHACL SPARQL rules and triple rules.
This document also defines a declarative mechanism for SPARQL rule templates.
This section is non-normative.
The following example illustrates a simple use case of a SPARQL rule that applies to all instances of
the class ex:Rectangle and computes the values of the ex:area property by multiplying
the rectangle's width and height:
An engine that is capable of executing such rules uses the target statements associated
with the shapes in the shapes graph to determine which rules need to be executed on which target nodes.
For those target nodes that conform to all condition shapes, it executes the provided
CONSTRUCT queries to produce the inferred triples.
During the execution of the query, the variable this has the current focus node as pre-bound variable.
For the following data graph, the triples below would be produced.
This section is non-normative.
In addition to SPARQL-based inference rules, this document introduces triple rules. These rules rely on node expressions instead of SPARQL queries to compute the inferred triples. Here is the same scenario as the previous example, using a triple rule.
The SHACL instances of sh:Rule, including its subclasses sh:SPARQLRule and sh:TripleRule,
are called SHACL rules.
SHACL has a flexible, extensible design in which multiple types of rules can be supported,
but this document only defines two of them (SPARQL rules and triple rules)
and a mechanism to declare SPARQL rule templates.
Each SHACL rule has at least one rdf:type
which is an IRI.
A rule type is identified by an IRI.
Each rule type defines execution instructions that can be implemented by rule engines through the function
execute(rule, focusNodes) -> inferredTriples where
rule is the rule to execute, focusNodes is a set of nodes provided by a rule engine,
and inferredTriples is the graph of (output) triples that are not in the base graph.
The function is invoked as part of the execution of a rule set, which supplies the
evaluation graph that the execution instructions read from.
Rule R has rule type T if R is a SHACL instance of T.
Rules can have multiple types, e.g., to provide instructions that work either in SPARQL or JavaScript,
depending on the capabilities of the engine.
The creator of rules with multiple types needs to make sure that such rules have consistent semantics.
The property sh:rule can be used to link a shape (subject)
with a shape rule (object).
The subjects of sh:rule triples are IRIs.
The objects of sh:rule triples are rules.
SHACL rules can be divided into two categories:
sh:rule triple.
When a shape rule is executed, its focus nodes are the target nodes of the shape
which is the subject of the sh:rule triple.
sh:rule predicate, and is therefore executed without any focus nodes.
A shape rule is evaluated individually for each of its focus nodes.
For example, a SPARQL rule that is a shape rule is evaluated with the variable
$this pre-bound to each focus node, while a global SPARQL rule has no such pre-binding.
In this sense, a shape rule is "local" to each of its focus nodes.
However, the triples inferred by a shape rule are not local: both shape rules and global rules
read from the same evaluation graph and contribute to the same inference graph,
so the triples inferred by any rule are visible to subsequently executed rules and to the subsequent
validation of all shapes.
An example of a shape rule was shown above in Example 1.
The following example illustrates a global rule.
A shape rule may have values for the property sh:condition to specify shapes
that the target nodes must conform to before they become focus nodes for the rule.
Since global rules are executed without focus nodes, values of sh:condition
have no effect on them.
The values of sh:condition at a rule must be well-formed shapes.
If the conformance check for a sh:condition at a rule produces a failure then the
rule execution also reports a failure.
If the value C of sh:condition is a SHACL instance of both sh:NodeShape
and rdfs:Class, then the target nodes must also conform to the constraints of the
non-deactivated SHACL superclasses of C
that are also SHACL instances of both sh:NodeShape and rdfs:Class.
This is similar to how Implicit Class Targets are interpreted during validation.
Rules may be deactivated by setting sh:deactivated to true.
Deactivated rules are ignored by the rules engine.
Each rule may have at most one value for the
property sh:deactivated.
The values of sh:deactivated are either
of the xsd:boolean literals true or false.
Rules may be grouped into layers, identified by a numeric value.
During execution, a SHACL rules engine will iterate over all rules with the same numeric layer value
before moving to the next layer.
Layers with a smaller numeric value will be executed before those with a larger number.
Two rules are in the same layer if their layer values are equal as numbers,
so that for example 1 and 1.0 identify the same layer.
Each rule may have at most one value for the
property sh:layer.
The values of sh:layer at rules
are literals with datatype xsd:integer or xsd:decimal.
If unspecified and unless it has been computed by a custom rule processor, the default layer of a rule is 0.
An example of sh:layer to control the execution order of rules is provided in Example 6.
Rules may specify their relative execution order within the same layer as defined in this section.
Each rule may have at most one value for the
property sh:order.
The values of sh:order at rules
are literals with datatype xsd:decimal or xsd:integer.
If unspecified and unless it has been computed by a custom rule processor, the default execution order is 0.
In each iteration within a layer, rules are executed in ascending order of their sh:order values.
These values are compared as numbers, so that for example 1 and 1.0 are the same order.
The inferred triples of one rule (or group of same-order rules) become immediately visible to the subsequent rule (or group of same-order rules) in the order.
Rules with the same order are executed concurrently: a rule does not see the triples
newly inferred by other rules with the same order during the current iteration.
The sets of triples individually inferred by these rules are added to the inference graph
once all rules with that order have been executed.
This is defined in detail in 8. General Execution Instructions for SHACL Rules.
In this example, the uncle rule has a lower sh:order than the cousin rule, so the
ex:uncle triples it infers are already visible to the cousin rule within the same iteration.
As a result, all triples are inferred in the first iteration and the second iteration only confirms
that nothing new is produced. If both rules had the same order, ex:cousin triples could only be
inferred in the second iteration, and a third iteration would be needed.
This example is simplified to uncles and their children, and a more realistic version would include aunts.
The property sh:order may also be used on shapes
(see Non-Validating Shape Characteristics).
However, such values have no effect on the execution of a rule set:
the order of a shape rule is determined only by the sh:order value of the rule itself,
not by that of the shape it is attached to.
A SHACL rules engine iterates over the rules, allowing the same rule to be executed multiple times until no further triples are inferred. However, some rules may produce fresh blank nodes with each execution and therefore cause infinite iterations.
Rules may use the property sh:runOnce to instruct a rules engine that the rule is
only executed once and before the other rules in the same layer.
Each rule may have at most one value for the
property sh:runOnce.
The values of sh:runOnce at rules
are literals with datatype xsd:boolean.
A run-once rule is a rule that is executed in only one iteration,
which takes place before the first iteration over the other rules of its layer.
All other rules are called iterating rules.
A rule that has true as its value for sh:runOnce is a run-once rule.
Custom rule processors may compute additional run-once rules when sh:runOnce is absent.
SHACL Core includes the following properties to derive property values that are not necessarily asserted in the data graph:
sh:defaultValue defines what values should be used
when no other values are present for a property.
For example, the default value of ex:childCount could be 0.
sh:values defines general instructions for computing
derived values for a property.
For example, the ex:area of a rectangle may be derived by multiplying its ex:width and ex:height.
Both properties can use node expressions including those defined in SHACL 1.2 Node Expressions.
Both properties can only be used to compute the objects of a given predicate for the
subjects that are targeted by shapes.
This means that sh:defaultValue and sh:values describe implicit triples
that are similar to inferences produced by rules.
When a rule refers to a certain property, it is reasonable for the rule to expect that these implicit triples are present. This section explains how rules can make sure that such derived triples are present before the rule executes.
For a given predicate p and a (non-deactivated) property shape in the shapes graph
that has p as its value of sh:path, the derived value nodes of a focus node
of the property shape are the value nodes that are added by the steps for sh:values and
sh:defaultValue defined by SHACL 1.2 Core.
As defined by these steps, the values of sh:defaultValue are only used if the focus node
has no other value nodes, neither as triples in the graph nor computed by sh:values.
For each derived value node v of a focus node f, there is a derived triple
with f as the subject, p as the predicate and v as the object.
The derived triples of a layer are computed once before its first iteration using the evaluation graph as the data graph, and are added to the inference graph. They are not recomputed during the iterations of the layer, even if rules of that layer infer triples that would change them.
The expected derived triples of a rule are the derived triples for all values
of the property sh:expectedPredicate at the rule.
The values of sh:expectedPredicate at a rule are IRIs.
All this is best explained by an example:
The following data graph defines some rectangle instances:
A SHACL rules engine will remove the derived triples from the inference graph at the end of processing each layer, except those triples that have also been inferred by rules. Some engines may have a setting to keep all derived triples, for example when data is exported to systems that do not support SHACL.
The input to a SHACL rules engine is a set of rules called a rule set.
Except for the default rule set, a rule set is identified by an IRI
that is a SHACL instance of sh:RuleSet.
The property sh:hasRule can be used to declare that a rule set has a given rule as a member.
A rule set may contain both shape rules and global rules.
The default rule set of a graph is the set of all rules in the graph,
regardless of whether they are also members of other rule sets.
Rule sets can use the property sh:includesRuleSet to (transitively) include other rule sets.
All SHACL instances of sh:RuleSet are IRIs.
The values of sh:hasRule at a rule set are rules.
The values of sh:includesRuleSet at a rule set are IRIs.
The rule set ex:RuleSet1 contains ex:Rule1 and ex:Rule2
(via ex:RuleSet2), while ex:RuleSet2 contains only ex:Rule2.
Rule sets may contain rules of different rule types.
However, the behaviour and effects of such a rule set could be difficult to predict and control, particularly when a
custom rule processor computes the values of sh:order or sh:layer
for some of its rules.
Users are therefore advised against mixing rules of different types within the same rule set.
A rules graph is a shapes graph that contains SHACL rules.
The sh:RulesGraph class MAY be used as an rdf:type
of the IRI of a graph acting in the role of a rules graph.
The remainder of this section is non-normative.
The graph type classes (sh:DataGraph, sh:ShapesGraph, sh:RulesGraph)
represent roles that are not mutually exclusive; a single graph may be typed with more than one of these classes.
Rules graphs may contain sh:rule triples that reference shapes defined in
other graphs, allowing rules to be managed independently of shape and ontology definitions.
SHACL Core defines the property sh:entailment to link a shapes graph with entailment regimes.
This section defines two kinds of values of sh:entailment that instruct a SHACL validation engine
to execute SHACL rules prior to starting the validation:
the IRI sh:RulesEntailment, which executes all rules of the shapes graph,
and rule sets, which execute only the rules of the given rule set.
After these entailments have been executed, the data graph that gets validated by the SHACL validation engine is the evaluation graph, i.e. the union of the base graph and the inference graph. The original data graph from the validation becomes the base graph and is not modified.
Following the general policy for SHACL, validation engines that do not support a given entailment regime
MUST signal a failure if the shapes graph uses it as a value of sh:entailment.
The IRI sh:RulesEntailment represents the SHACL rules entailment regime.
In the following example, the shapes graph indicates to a SHACL validation engine that the SHACL rules
inside of the shapes graph need to be executed prior to starting the validation.
Validation engines that do support the SHACL rules entailment regime execute the default rule set of the shapes graph following the rules execution instructions prior to performing the actual validation.
Any rule set can be used as a value of sh:entailment,
i.e. any IRI that is a SHACL instance of sh:RuleSet in the shapes graph.
Validation engines that support this regime execute the given rule set
following the rules execution instructions prior to performing the actual validation.
Only the rules of that rule set are executed, including those of the rule sets that it includes
via sh:includesRuleSet.
Other rules in the shapes graph are ignored.
If the shapes graph has more than one such value for sh:entailment, or also has the value
sh:RulesEntailment, then the rules of all of them are executed together as a single rule set,
and the values of sh:ruleProcessor of all of them apply to that rule set.
In the following example, which uses the rule sets from Example 8,
only ex:Rule2 is executed prior to validation, while ex:Rule1 is ignored.
It is sometimes useful for inference rules to produce triples that are only visible during the execution
of other rules but do not end up in the final inferences.
A temporary triple is an inferred triple for which the inference graph contains a
reifier with the value sh:tempTriple true.
Temporary triples and their triple annotations are visible to executing rules.
Rules can produce such triples as illustrated in the following example:
The first rule computes ex:offspring triples as the (transitive)
children of each Person.
The second rule uses the ex:offspring triples to infer the ex:youngestOffspring
of each Person.
The final inferences only include the ex:youngestOffspring triples.
All temporary triples, i.e., triples whose reifier is marked with sh:tempTriple true,
are automatically deleted by the SHACL engine at the end of the inference process.
Creating temporary triples can be helpful when a computation is too complex to be carried out by a single rule. The complex computation can then be decomposed into multiple rules: some rules infer partial results, from which other rules derive the final results. The partial results are only functional to the computation of the final results and are no longer needed once the latter have been obtained. By marking these partial results as temporary triples, they are automatically removed after the final results have been computed.
A SHACL rules engine is a computer procedure that takes as input a data graph called the base graph, a shapes graph, and an optional rule set (defaulting to the default rule set of the shapes graph) and is capable of producing triples that are not in the base graph. The new triples that are produced by a rules engine are called the inferred triples. The inference graph consists of these inferred triples. The evaluation graph is the union of the base graph and the inference graph. The base graph and the shapes graph are immutable.
An execution of a rule is the process that produces inferred triples from the rule based on the execution instructions of any one of its rule types:
sh:rule),
then its focus nodes are the set of all target nodes of the linked and non-deactivated
shapes that conform to all non-deactivated conditions of the rule.
The rule is executed with this set: execute(rule, focusNodes).
Each focus node is therefore only processed once per execution,
even if several shapes with overlapping targets link to the rule.
sh:rule),
then the rule is executed with an empty set of focus nodes: execute(rule, []).
During the execution of a rule set, the evaluation graph takes the role of the data graph: the target nodes of the shapes, the conformance of these nodes to the conditions, and the results of queries and node expressions are all determined using the evaluation graph as it is when the execution of the rule starts. This means that nodes that only exist in the inference graph can become focus nodes, and that the focus nodes of a rule can change from one iteration to the next. The evaluation graph does not change during the execution of a rule: the triples that are inferred for one focus node are not visible while the rule is executed for its other focus nodes.
For a given rule set in the shapes graph, an iteration over a set of rules consists of the following steps, skipping the rules that are deactivated:
execute functions
are added to the inference graph, before the next group is processed.
The execution of a rule set is defined as follows:
For all layers in the rule set (in ascending order):
Compute the expected derived triples for all non-deactivated rules in the layer
Execute one iteration over all run-once rules in the layer
do
Execute one iteration over all iterating rules in the layer
while the iteration has produced newly inferred triples
Delete the derived triples (except those that were also inferred by rules)
and their triple annotations
Delete the temporary triples and their triple annotations
Note that in this algorithm, adding and deleting triples is only performed on the inference graph.
If any of the rules reports a failure during execution, then the execution of a rule set also produces a failure.
If a rules engine is not able to execute a given rule because it does not support any of the rule types of the rule, then it reports a failure.
Rule engines MAY also report a failure after a pre-configured maximum iteration count has been exceeded or a pre-configured maximum number of inferred triples has been produced. This can help as a guard to avoid out-of-memory problems and infinite loops.
Rule engines MAY have an option to generate additional triples that can be used to track
which rules have produced the inferred triples.
The property sh:sourceRule can be used in a reifier of a triple in the inference graph
to link the triple with the rule.
The values of sh:sourceRule SHOULD be IRIs.
The following example indicates that the triple ex:Alice ex:friend ex:Bob has been
inferred by the rule ex:SymmetryRule.
<< ex:Alice ex:friend ex:Bob >> sh:sourceRule ex:SymmetryRule .
Fully expanded into RDF triples this is equivalent to:
_:id rdf:reifies <<( ex:Alice ex:friend ex:Bob )>> .
_:id sh:sourceRule ex:SymmetryRule .
If a rule engine adds these triples, the triples MUST NOT be visible to executing rules.
The general execution algorithm described above assumes that the author of the rules is responsible for selecting a suitable ordering and layering/grouping of rules to achieve the desired outcome.
Some SHACL rule implementations MAY implement different algorithms to determine:
sh:runOnce is not specified)sh:order is not specified)sh:layer is not specified)This can, for example, be used by engines that support controlled subsets of SHACL rules for which it is possible to compute rule dependencies automatically. Another example is a rule engine that automatically prevents infinite loops because rules generate blank nodes.
Some SHACL rule implementations MAY also report additional failures that are not reported by the default algorithm.
The property sh:ruleProcessor can be used at rule sets or rules
to instruct a rules engine that non-standard processing is required for the given rules.
The values of sh:ruleProcessor are IRIs,
or literals with datatype xsd:string.
When used in a rule set, the values of sh:ruleProcessor from an included rule set also
apply to the including rule set.
A rules engine that encounters rules or rule sets with a value for sh:ruleProcessor
that they are unable to handle MUST report a failure.
This would be a good place to cross-reference the ongoing SPARQL-RL work, if this integrates naturally with SHACL Inference Rules.
For example we could add an example with sh:ruleProcessor "SRL 1.2".
The SHACL inference rules framework defines a general syntax of rules and their execution algorithm. This document defines the two rule types from the following two subsections.
Note that not all implementations are required to implement both of these types for conformance. A rules engine that encounters a rule for which it does not implement any rule type reports a failure, as defined in 8. General Execution Instructions for SHACL Rules.
This section defines a rule type called SHACL SPARQL rules, often just "SPARQL Rules",
identified by the IRI sh:SPARQLRule.
SPARQL rules have the following properties:
| Property | Summary and Syntax Rules |
|---|---|
sh:construct |
The SPARQL CONSTRUCT query.
SPARQL rules must have exactly one
value for the property sh:construct.
The values of sh:construct
are literals with datatype xsd:string.
Using the prefix handling rules,
the value of sh:construct is a valid SPARQL 1.2 CONSTRUCT query.
|
sh:prefixes |
The prefixes to use to turn the sh:construct into a SPARQL query.
SPARQL rules may use the property sh:prefixes to declare a dependency on prefixes based on the
mechanism defined in Prefix Declarations for SPARQL Queries.
This mechanism allows users to abbreviate URIs in the sh:construct strings.
|
Q be the SPARQL CONSTRUCT query derived from the values of the properties
sh:construct and sh:prefixes of the SPARQL rule in the shapes graph.
Q
pre-binding the variable this to the focus node,
and infer the constructed triples.
Q without any pre-binding,
and infer the constructed triples.
The SPARQL function NOW returns the same
result in all SPARQL rules during the execution of a rule set.
For SPARQL rules that are shape rules (i.e., linked to a shape with sh:rule),
a SHACL rules engine also counts as a SHACL-SPARQL processor (as defined by SHACL 1.2 SPARQL-Related Features)
and the syntax limitations required by pre-binding do apply to shape rules.
Since global SPARQL rules do not use pre-binding, the syntax limitations
required by pre-binding do not apply to them.
This section defines a rule type called triple rules, identified by
the IRI sh:TripleRule.
Triple rules have the following properties:
| Property | Summary and Syntax Rules |
|---|---|
sh:subject |
The node expression used to compute the subjects of the triples.
Each triple rule must have at most one
value of the property sh:subject (which must be a well-formed node expression).
|
sh:predicate |
The node expression used to compute the predicates of the triples.
Each triple rule must have at most one
value of the property sh:predicate (which must be a well-formed node expression).
|
sh:object |
The node expression used to compute the objects of the triples.
Each triple rule must have at most one
value of the property sh:object (which must be a well-formed node expression).
|
S, P and O be the output nodes of evaluating
the node expressions that are the values of sh:subject, sh:predicate
and sh:object respectively at the triple rule,
using evalExpr(expr, evaluation graph, focusNode, {}) as defined in
SHACL 1.2 Core, where focusNode is the current focus node (no value for global rules).
If any of these evaluations produces an evaluation failure, then the execution of the
triple rule produces a failure.
Where sh:subject, sh:predicate, or sh:object are absent, use
the list consisting of the current focus node (which is empty for global rules).
For each combination of members s of S, p of P and
o of O, infer a triple with subject s,
predicate p and object o.
Duplicate combinations produce the same triple.
Skip ill-formed triples, for example when a blank node is used as predicate.
In this example, any instance of ex:Rectangle where the width equals the height
will receive an extra rdf:type ex:Square triple.
In this example, a SHACL rules engine will infer a ex:childCount triple for any instance of ex:Person
using a node expression combining shnex:count and shnex:pathValues.
The class sh:SPARQLRuleTemplate can be used to declare new rule types called SPARQL rule templates.
Each SPARQL rule template is itself a class and therefore denotes a set of rules:
the SHACL instances of a template are the individual rules (see examples below).
These rule types define a (reusable) SPARQL CONSTRUCT query and can take parameters that are mapped to pre-bound
variables in the CONSTRUCT query.
This mechanism allows similar rules to reuse the same CONSTRUCT query while the user only needs to specify the parameter values,
without even having to write or understand SPARQL.
Each SPARQL rule template is an IRI.
Each SPARQL rule template is a SHACL subclass of sh:Rule.
The values of sh:parameter at a SPARQL rule template
are parameter declarations that follow the same syntax rules as the
parameter declarations of SPARQL-based constraint components.
Each SPARQL rule template has exactly one value of sh:construct
and that value is a literal with datatype xsd:string.
Using the prefix handling rules,
the value of sh:construct at a SPARQL rule template is a valid SPARQL 1.2 CONSTRUCT query.
Like SPARQL rules, a SPARQL rule template can use the property
sh:prefixes to declare prefixes to be used with the sh:construct.
R be a SHACL instance of the SPARQL rule template T.
Let Q be the SPARQL CONSTRUCT query that is produced from the value of sh:construct
at T in the shapes graph, using the prefix declarations at T.
For each parameter declaration P of T (i.e., each value of sh:parameter)
for which R has a value for the property that is the sh:path of P,
the variable with the parameter name of P is pre-bound to that value.
The variables of the other parameters remain unbound.
Evaluate Q like a corresponding SPARQL Rule but using these extra pre-bound variables.
Report a failure if any of the declared parameters that are not declared as sh:optional true have no value in R.
In the example below, the CONSTRUCT query is executed with the SPARQL variable $property pre-bound to the
value of ex:property.
In this example, a SHACL rules engine will infer missing triples in the inverse direction
for every value of the given properties ex:marriedTo and ex:overlaps, using a SPARQL rule template.
Note that ex:SymmetricPropertyRule is a new rule type, i.e., it denotes a set of rules;
ex:MarriedToRule and ex:OverlapsRule are two members of this set.
The instances of sh:SPARQLRuleTemplate (the SPARQL rule templates) are classes.
The instances of those classes are the actual rule instances.
SPARQL rule templates need to be declared as rdfs:subClassOf sh:Rule so that their instances are SHACL rules.
This also places them into the class hierarchy alongside the other rule types such as sh:SPARQLRule.
The following example uses a SPARQL rule template as a shape rule, meaning that the variable
$this will point at the current focus node when the rule executes.
In this example, a SHACL rules engine will infer a ex:feet triple for any instance of ex:Measurement
using a rule template.
This section enumerates all normative syntax rules of this document. This section is automatically generated from other parts of this spec and hyperlinks are provided back into the prose if the context of the rule is unclear. Nodes that violate these rules in a shapes graph are ill-formed.
| Syntax Rule Id | Syntax Rule Text |
|---|---|
| rule-type | Each SHACL rule has at least one rdf:type
which is an IRI. |
| rule | The property sh:rule can be used to link a shape (subject)
with a shape rule (object).
The subjects of sh:rule triples are IRIs. |
| rule-object | The objects of sh:rule triples are rules. |
| condition-node | The values of sh:condition at a rule must be well-formed shapes. |
| deactivated-maxCount | Each rule may have at most one value for the
property sh:deactivated. |
| deactivated-in | The values of sh:deactivated are either
of the xsd:boolean literals true or false. |
| rule-layer-maxCount | Each rule may have at most one value for the
property sh:layer. |
| rule-layer-datatype | The values of sh:layer at rules
are literals with datatype xsd:integer or xsd:decimal. |
| rule-order-maxCount | Each rule may have at most one value for the
property sh:order. |
| rule-order-datatype | The values of sh:order at rules
are literals with datatype xsd:decimal or xsd:integer. |
| run-once-maxCount | Each rule may have at most one value for the
property sh:runOnce. |
| run-once-datatype | The values of sh:runOnce at rules
are literals with datatype xsd:boolean. |
| expectedPredicate-nodeKind | The values of sh:expectedPredicate at a rule are IRIs. |
| RuleSet-nodeKind | All SHACL instances of sh:RuleSet are IRIs. |
| hasRule | The values of sh:hasRule at a rule set are rules. |
| includesRuleSet-nodeKind | The values of sh:includesRuleSet at a rule set are IRIs. |
| ruleProcessor | The values of sh:ruleProcessor are IRIs,
or literals with datatype xsd:string. |
| construct-count | SPARQL rules must have exactly one
value for the property sh:construct. |
| construct-datatype | The values of sh:construct
are literals with datatype xsd:string. |
| construct-query-valid | Using the prefix handling rules,
the value of sh:construct is a valid SPARQL 1.2 CONSTRUCT query. |
| TripleRule-subject | Each triple rule must have at most one
value of the property sh:subject (which must be a well-formed node expression).
|
| TripleRule-predicate | Each triple rule must have at most one
value of the property sh:predicate (which must be a well-formed node expression).
|
| TripleRule-object | Each triple rule must have at most one
value of the property sh:object (which must be a well-formed node expression).
|
| SPARQLRuleTemplate-nodeKind | Each SPARQL rule template is an IRI. |
| SPARQLRuleTemplate-subClassOf | Each SPARQL rule template is a SHACL subclass of sh:Rule. |
| SPARQLRuleTemplate-parameter | The values of sh:parameter at a SPARQL rule template
are parameter declarations that follow the same syntax rules as the
parameter declarations of SPARQL-based constraint components. |
| SPARQLRuleTemplate-construct | Each SPARQL rule template has exactly one value of sh:construct
and that value is a literal with datatype xsd:string. |
| SPARQLRuleTemplate-construct-query-valid | Using the prefix handling rules,
the value of sh:construct at a SPARQL rule template is a valid SPARQL 1.2 CONSTRUCT query. |
This section is non-normative.
Applying a SHACL inference rule set to a data graph can result in significant computation and memory usage, which may be exploited to cause denial of service. Applications should take care to limit the amount of computation and memory usage that can be caused by applying such rule sets.
SHACL inference rules can be used to process and create arbitrary application data; security considerations will vary by domain of use. Security/privacy protocols should be imposed which reflect the sensitivity of the information in the outcome of rule set evaluation, including potentially sensitive information exposed through the expected derived triples mechanism.
Security considerations of this document include all the security considerations of SHACL SPARQL, SHACL Node Expressions and SHACL Core.
This section is non-normative.
Original SHACL core specifications were produced by the RDF Data Shapes Working Group. See the Core specification's Acknowledgements section and the Advanced Features specification's Acknowledgements section.
Referenced in:
Referenced in:
Referenced in:
Referenced in:
Referenced in:
Referenced in:
Referenced in:
Referenced in:
Referenced in:
Referenced in:
Referenced in:
Referenced in:
Referenced in:
Referenced in:
Referenced in:
Referenced in:
Referenced in:
Referenced in:
Referenced in: