SHACL, the Shapes Constraint Language, is a language for describing the structure
of RDF graphs.
SHACL may be used for a variety of purposes such as validating, inferencing,
modeling domains, generating ontologies to inform other agents, building user
interfaces, generating code, and integrating data.
SHACL Profiling defines elements of the SHACL Shapes Constraint Language that allow for the description of profiles of SHACL
and profiling with SHACL. This document's scope is limited to profiling of RDF graphs, including graphs
containing SHACL Shapes.
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.
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.
defines an RDF syntax for expressing SHACL concepts
Note
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.
Document Outline
The introduction provides background concepts of profiling and states this specification's scope. It also provides
term definitions and describes document conventions.
This document deals with a narrow set of profiling tasks only - profiling of SHACL and profiling of RDF graphs with
SHACL - and, as such, only defines vocabulary elements needed for that.
By definition, SHACL shapes constrain RDF data, therefore, any data that is valid
according to a shapes graph
will be a profile of the data
graph. If a shapes graph
validates all elements of a data
graph, the resulting valid data will be identical
to the original data graph.
a standard that constrains, extends, combines, or provides guidance or explanation about the use of
other standards
If a shapes graph is taken to
be a standard, then not
only is data that is valid according to it a profile of
the data graph, but
the shapes graph itself is also
a profile of the data model used for the
data graph.
This document describes how to profile data and standards, including SHACL itself, and how to package
SHACL for optimal understanding and reuse. It also covers storing the results of SHACL processing.
1.2 Scope
This specification includes the following sections that indicate its scope:
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 specification, color-coded boxes containing graphs in RDF 1.1 Turtle and JSON-LD will appear.
The color and title of a box indicate whether it is a
shapes graph, a
data graph, or something
else.
The Turtle specification fragments use the prefix bindings given above.
JSON-LD 1.1 is also used alongside Turtle as another RDF format. When given, assume that the above JSON-LD
context is applied.
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, RECOMMENDED, SHALL, SHOULD, and SHOULD NOT 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 extensions to the data model of the SHACL Core specification [shacl12-core] for the purposes of profiling.
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 syntactic rules specified here are given in English and use keywords MAY, MUST, MUST NOT, RECOMMENDED, SHOULD, and SHOULD NOT that are to be interpreted as described in BCP 14 [RFC2119] [RFC8174] when, and only when, they appear in all capitals, as shown here.
Conformance claims of data to this specification's rules can be tested by validation using the SHACL-SHACL Profiling validator in the SHACL-SHACL Annex of the SHACL Overview specification [shacl12-overview].
An instance of a SHACL element used for validation SHOULD indicate the instance of a sh:ShapesGraph that defines it with the rdfs:isDefinedBy predicate
An instance of sh:ShapesGraph that uses a SHACL element for validation, but does not define it, SHOULD indicate the SHACL element as a member with the rdfs:member predicate
Instances of sh:ShapesGraph being used to group SHACL elements used for validation SHOULD indicate dependence on other groups of SHACL elements identified using instances of sh:ShapesGraph with the owl:imports predicate
When persisting SHACL validation, inference or combined results, the results and the inputs SHOULD be represented and linked using elements of the SHACL Profiling Vocabulary; the processing activity and the agent MAY also be represented
The following subsections detail each of these recommendations.
For example, the Open Geospatial Consortium's
GeoSPARQL 1.1 standard for spatial RDF data provides a
SHACL validator
containing 27 instances of sh:NodeShape and a similar number of instances of sh:PropertyShape within a Turtle
file. The file also contains an instance of owl:Ontology presenting metadata for the validating resource, such as its
modified date, a license for its use, and so on.
This recommendation supersedes that practice and recommends that sh:ShapesGraph, a specialised class
defined in SHACL 1.2 Core specifically for grouping SHACL elements, be used instead.
For mixed SHACL and OWL elements, such as NodeShapes and Class definitions, owl:OntologySHOULD
continue to be used.
2.4 Indicating Element definition
An instance of a SHACL element used for validation SHOULD indicate the instance of a sh:ShapesGraph that defines it with the rdfs:isDefinedBy predicate.
Common practice when placing SHACL elements into groups identified by use of an owl:Ontology instance
has been to just contain the elements and the ontology instance in an RDF file. This is reasonable for data exchange
but, when exchanged files are stored in an RDF database, associations between a container instance
and the SHACL elements defined within it may be lost. If loaded into a named graph,
the association might be kept with the named graph grouping the ontology and the SHACL elements but this is a non-semantic
association, i.e. one not seen directly in a graph.
This recommendation is that the creator of a SHACL elementSHOULD indicate the group
within which the SHACL element is defined. An example of such an assertion in RDF is as follows:
An instance of sh:ShapesGraph that uses a SHACL element for validation, but does not define it, SHOULD indicate the SHACL element as a member with the rdfs:member predicate.
When a SHACL element is used within a group of elements but not defined by it, it SHOULD NOT be indicated as being
defined by that group, so the recommendation in the section above is irrelevant. Reuse of SHACL elements within groups
that do not define them is expected and encouraged, according to Linked Data principles [LDP].
An example of the use of the rdfs:member predicate to indicate inclusion of a SHACL element in a group
that does not define it, as well use of rdfs:isDefinedBy, as in the example above, is as follows:
2.6 Indicating group dependence
Instances of sh:ShapesGraph being used to group SHACL elements used for validation SHOULD indicate dependence on other groups of SHACL elements identified using instances of sh:ShapesGraph with the owl:imports predicate.
It is established practice within SHACL validation tooling to import SHACL elements from one collection, such as a
file containing RDF data, into another via an owl:imports instruction. Many SHACL validation engines
do this, such as pySHACL [PYSH], and this practice is recommended to indicate dependence from one collection/group
to another, even if no particular validation engine actions are expected to arise from the assertion: it is
likely usefully informative for SHACL data management too.
An example of owl:imports is as per the example below.
To be very specific regarding the versions of dependencies, owl:importsMAY target a particular
version of a sh:ShapesGraph indicated with a owl:versionIRI predicate, as per the
example below.
# 'Shapes Graph N' imports 'Version 4.2 of Shapes Graph M'
ex:sg-M
a sh:ShapesGraph ;
owl:versionIRI ex:sg-M-4.2 ;
.
ex:sg-N
a sh:ShapesGraph ;
owl:imports ex:sg-M-4.2 ;
.
Calculating Dependencies
Dependency of a shapes graph on another
shapes graphSHOULD be indicated with a predicate such as
dcterms:requires. When the packaging recommendations above are followed, dependency of
one shapes graph on another MAY be calculated with the following rules, which use dcterms:requires:
# dependency through element definition and reuse
RULE {
?sg1 dcterms:requires ?sg2 .
}
WHERE {
?sg1
a sh:ShapesGraph ;
rdfs:member ?shape ;
.
?shape rdfs:isDefinedBy ?sg2 .
?sg2 a sh:ShapesGraph .
FILTER (?sg1 != ?sg2) # exclude self-dependencies
}
# dependency through importing
# rule linking means un-versioned importing only runs if versioned importing does not
RULE {
?sg1 dcterms:requires ?sg2 .
}
WHERE {
?sg1 owl:imports ?sg2 .
NOT {
?sg1 dcterms:requires ?sg2 .
}
}
# versioned importing
RULE {
?sg1 dcterms:requires ?sg2_v .
}
WHERE {
?sg1 owl:imports ?sg2 .
?sg2 owl:versionIRI ?sg2_v .
}
# transitive dependency
RULE {
?sg1 dcterms:requires ?sg3 .
}
WHERE {
?sg1 dcterms:requires ?sg2 .
?sg2 dcterms:requires ?sg3 .
FILTER (?sg1 != ?sg3)
}
2.7 Persisting processing results
When persisting SHACL validation, inference or combined results, the results and the inputs SHOULD be represented and linked using elements of the SHACL Profiling Vocabulary; the processing activity and the agent MAY also be represented.
It may be useful to persist the results of SHACL processing. For example, a data graph
might be validated repeatedly and the results of validation, their time of generation and the configuration of the
validation engine used stored for later analysis.
We consider the event of SHACL processing, validation, inferencing or both, to be an activity with input
and output entities, undertaken by a SHACL processor which is an agent. Figure 2
shows these elements of SHACL processing as defined in 5. SHACL Profiling Vocabulary, stylized according to PROV-O: The PROV Ontology's
Figure 1.
Details of the timing and duration of SHACL processing MAY be recorded using PROV-O properties for the
sh:ShaclActivity such as prov:startedAtTime. Details about the processor MAY be recorded
using annotations and other properties for the sh:ShaclAgent. For example, the name, version, code
repository and so on may be recorded using schema:name, schema:version and
schema:codeRepository, or similar properties from other vocabularies.
Validation-only processing, i.e. not including inferencing, need only represent a sh:DataGraph and
sh:ShapesGraph input and a sh:ValidationReport output.
The following example data shows an "activity-centric" formulation of provenance of a validation process
with prov:generated used as the inverse relation to prov:wasGeneratedBy as per
Figure 2 and the sh:usedDataGraph and sh:usedShapesGraph sub-properties
of prov:used indicating inputs. The conforms to shapes graph
rule may be used to create a direct relationship between the data graph
and shapes graph.
Inferencing-only processing, i.e. not including validation, need only represent a sh:DataGraph and
sh:ShapesGraph or sh:RulesGraph input and a sh:InferenceGraph output.
The following example data shows an "entity-centric" formulation of the provenance of an inference process with
the output inference graph indicated as being derived from the inputs and attributed to the SHACL agent: no
activity is shown. Timing can still be indicated in such a formulation with a prov:generatedAtTime
assigned to outputs - the inference graph.
Combined processing involving both validation and inference can use appropriate validation and inferencing inputs
and outputs.
2.7.1 PROV-O alignment and reasoning
SHACL does not present ontology statements beyond basic RDFS relations, so if reasoning beyond what RDFS provides
is needed, perhaps to calculate direct relations between SHACL processing inputs and outputs, the section
5.11.2 PROV-O Alignment may be used. It relates Figure 2's elements to PROV-O which does allow
for reasoning with the OWL 2 RL profile [owl2-profiles].
3. Profiling SHACL
This section describes how profiles of SHACL 1.2 are made, gives examples of some and indicates how to
create more.
See A. Profiles of SHACL Examples for a listing of profiles of SHACL 1.2 known at the time of this specification's
publication and for links to community managed profiles.
3.1 Defining Profiles of SHACL
Profiles of SHACL SHOULD be declared using The Profiles Vocabulary 1.0. The declaration of the Core profile of SHACL 1.2 using
it is as follows:
This declaration identifies the Core profile with the IRI <http://www.w3.org/ns/shacl/profile/core>
and indicates it is an instance of prof:Profile, that it is a profile of the Union Profile of SHACL
1.1. (see A. Profiles of SHACL Examples for more info) and that it has three profile resources: a
specification, a schema and a validator.
Due to SHACL being used to validate SHACL (see SHACL-SHACL),
the data model to which the schema is indicated as conforming is this Core profile's own validator.
When described using terminology from The Profiles Vocabulary 1.0, the online document form of each specification linked to
above is just one of many resources that together make a profile of SHACL 1.2. The document plays the resource
role of Specification — "Defining the profile
in human-readable form" — and other resources play other roles. Of particular interest to SHACL users is the SHACL
shapes graph for each profile that plays the role of
Validation —
"Supplies instructions about how to verify conformance of data to the
profile". The various profiles of SHACL 1.2
may supply additional resources with other profile resource roles, for example the Core supplies the core schema —
the SHACL ontology — and SHACL UI presents an extended vocabulary of terms as well as a vocabulary of UI widgets.
Note
To validate RDF data against any of these Specification Profiles, or the Union Profile defined below, use their
validation profile resources which are listed as SHACL-SHACL shapes graphs
in the SHACL 1.2 Overview's SHACL-SHACL appendix.
3.2 Creating Profiles
Additional profiles of SHACL 1.2 may be created using any criteria. For example, it may be desirable to have profiles
of SHACL 1.2 Core that only implement shape types limited to particular computational complexities, much like the
profiles of OWL defined in OWL 2 Web Ontology Language Profiles (Second Edition). In this case, a profile definition could be made that uses the mechanisms given
in the Packaging SHACL section above, to only include some of SHACL 1.2 Core's elements.
Any other criteria can be used to select SHACL elements or to constrain their use, not just computational
complexity, and the examples in A. Profiles of SHACL Examples show profiles created with different criteria.
When making profiles of SHACL 1.2, it is important to identify and present the profile as per the currently known
profiles of SHACL 1.2 so they can be used effectively, including by others. Creators of profiles of SHACL 1.2 SHOULD:
Multiple other profiles of SHACL have been created by the W3C's Data Shapes Working Group, and they are listed in
A. Profiles of SHACL Examples also. However, that listing is indicative of different kinds of profiles, such
as specifications-based, computational effort based - similar to profiles of OWL [owl2-profiles] and so on, but
it is not intended to be a comprehensive listing of profiles of SHACL.
The W3C SHACL community-controlled repository at SHACL Resources Repository
is proposed as a central point for the collection of SHACL profile definitions.
4. Profiling with SHACL
This section describes how to create profiles of RDF resources with SHACL.
Since SHACL was released in 2017, it has been used extensively to make closed-world RDF data models for use by
applications, building on open-world RDF models such as W3C ontologies.
A typical example: the Indigenous Data Network defines a
profile of schema.org which constrains
that general-purpose RDF vocabulary for use in the field of Indigenous data cataloguing. The IDN provides a
SHACL validator to test catalogued objects' metadata with
for conformance to that profile.
In addition to constraining a general-purpose or permissive model, shapes graphs
can be defined for specifications that do not provide a resources to validate data according to their rules. Where the shapes graph
imposes no additional rules on the original model and also attempts to implement all the specification's rules, it creates a
null profile of it.
SHACL can also be used to extract parts of a data graph by matching them with a shapes graph using
SHACL elements allowed in the SPARQL Extraction Profile of SHACL. Data extracted in
this way is a profile of the original data graph.
The following sections describe and provide guidance on these forms of profiling.
As per The Profiles Vocabulary 1.0, resources within a profile perform roles and in this above formulation,
SG1 is undertaking both schema - data
model - and validation - actionable Shapes Graph -
roles, so a more complete formulation that indicates the Shapes Graph artifact itself conforms to
SHACL 1.2 Core and is available in the RDF 1.1 Turtle format and which leaves out the SHACL classing, follows.
Note
There are additional profile roles that SHACL resources may play, for example, rules formulated according to
SPARQL 1.2 RL may in the mapping role allowing
for conversions to/from a profile to another data model.
4.2.2 Reasoning
The Profiles Vocabulary 1.0 contains a single reasoning axiom which allows data conformant with a profile to be understood to
conform to the standard that the profile is a profile of:
This rule is presented to allow data which is declared to be valid according to a shapes graph that is a
profile of a standard to be understood to conform to that standard. This rule is important for the
creation of null profiles using SHACL, as per section 4.2.4 Creating Null Profiles.
4.2.3 Profile Hierarchies
If data must be tested for conformance to a profile defined using SHACL and also the standards that the profile is
a profile of, if those standards are either defined also using SHACL or if they provide resources with role
validation created using SHACL, then a shapes graph
may be created that is a compound of the profile and the standards or their validators.
This is expected to be important when a profiling situation is complex - perhaps multiple standards are
profiled or profiles of other profiles are created - for assembling the automated shapes graphs from
standards and profiles might be far preferable to manual assembly.
4.2.4 Creating Null Profiles
Before the creation of SHACL, there was no easy, standardized way of expressing sophisticated validation rules for
RDF vocabularies so many RDF standards made before 2017 do not provide a simple way for users to validate data
according to them.
Many RDF vocabulary standards do provide model constraints in the form of OWL axioms, but these are not readily
usable as data validators. Others have unofficial validation tools provided by the standards editors or third
parties, for example PROV-O: The PROV Ontology has prov-check,
an application code (Python) package created by one of the standard's editors, that runs SPARQL queries.
Now that we have SHACL, we can create null profiles of standards
that express many, and perhaps all, of their axioms and implied rules in a standardized data validation language.
While null profiles of standards may be created using modeling or rule systems other than SHACL, here we
focus only on the use of SHACL.
No universal and precise methodology can be given for creation of a null profile of a standard, because standards
without validators don't usually itemize their rules in a testable way. However, there are methods known to be
useful. One commonly seen approach is converting OWL rules to SHACL using any of the many available tools, such as
software packages or
functions within products.
Additionally, class or property definitions or other annotations often state their intended
use in natural language. For example, Data Catalog Vocabulary (DCAT) - Version 3's usage note for the dcat:Role class
says "Used in a qualified-attribution to specify the role of an Agent with respect to an Entity".
See B. Null Profile Examples for examples of null profiles of standards with notes on their creation.
4.3 Profiling Data
SHACL can be used to profile data in potentially many ways. One known way is to convert shapes graphs to SPARQL
queries. The SPARQL Extraction Profile of SHACL provides a profile of SHACL that
limits the SHACL elements able to be used to ensure reasonably efficient SPARQL queries can be generated, for example by prohibiting the use of recursion.
When a shapes graph is used to subset a
data graph, via SHACL-to-SPARQL data extraction or some other method,
any extracted data is a profile of the data graph.
In this scenario, the shapes graph used is also a profile of the data model of the data graph, even when that
data model is not known.
These relations might be of importance to record known relations between the various inputs and outputs of this
specialized form of SHACL processing. Figure 3 shows the relations between elements of SHACL-based
data extraction. No specialized SHACL vocabulary classes are given for "Data Model", "Extracted Data" or the
activity of data extraction though owl:Ontology reasonably be used for the first two and sh:ShaclActivity
for the third.
Figure 3
SHACL data profiling relations. If the dashed dcterms:conformsTo is known and Extracted Data
is produced then the red prof:isProfileOf and dcterms:conformsTo triples SHALL be inferred.
The Content Negotiation by Profile standard defines mechanisms for Internet clients to obtain data from servers based on
profiles to which the data conforms. When such "content negotiation by profile" is used and the profile is defined
using SHACL, the data received by the client will be Extracted Data, the content of the server being the
sh:DataGraph and the profile being the sh:ShapesGraph, as per Figure 3
above.
The classes and predicates detailed here are shown in relation to one another in Figure 4.
All SHACL elements of this vocabulary are members of the SHACL Core vocabulary, which has RDF serializations available at
its namespace location of http://www.w3.org/ns/shacl#.
sh:Graph and transitively through that,
owl:Ontology
Definition:
A shapes graph is an RDF graph containing zero or more shapes that is passed into a processing
activity so that a data graph can be validated against the shapes.
It may also contain SHACL rules that can be used to infer
new triples from a data graph.
For the purposes of SHACL profiling, this class is to be used to group SHACL elements together, as per
Section 2. Packaging SHACL. Note also that while shapes graph is a subclass of shacl's generic graph class,
that class is, in turn, a subclass of owl:Ontology.
Shapes graphs are expected to be used as parent objects for SHACL elements where previously OWL ontology
instances were used.
For the purposes of SHACL profiling, this predicate is to be used to indicate dependency between Shapes
Graphs, as per Section 2.6 Indicating group dependence.
For the purposes of SHACL profiling, this predicate is to be used to associate a shapes graph with each
Shape that it uses, whether defined by it or elsewhere, as per Section 2.5 Indicating Element use.
When used, this property indicates unqualified conformance whereas provenance of validation, as per
2.7 Persisting processing results, can record validity at a point in time if the 'activity-centric'
form is used.
As per SHACL 1.2 Inference Rules, a rules graph is a
shapes graph that contains SHACL rules, so every sh:RulesGraph is also a sh:ShapesGraph.
Use this class to indicate that an input to processing is used for its rules.
The rule 'conforms to shapes graph' is a reasoning rule that allows a data graph to be indicated as conforming
to a shapes graph if there is a Validation Report that used the data graph
and shapes graph for validation and whose sh:conforms property indicates true.
This reasoning rule cannot be articulated as an OWL property chain axiom due to the test of the
sh:conforms property value, so it is presented here as both a SPARQL 1.2 Query Language rule and a SPARQL 1.2 RL rule.
5.10 Rule: conforms to standard
The rule 'conforms to standard' is a reasoning rule that allows for a data graph to be indicated as
conforming to a Standard if the data graph conforms to a
shapes graph that is a profile of that Standard.
This reasoning allows for static conformance claims of data to profiles of standards and standards
themselves to be made, which will have utility for data whose conformance to these things must be known but which
cannot be continuously validated.
The result of this rule also enables the The Profiles Vocabulary 1.0 property chain axiom
dcterms:conformsTo owl:propertyChainAxiom ( dcterms:conformsTo prof:isProfileOf )
to propagate conformance claims up a profile hierarchy.
5.11 Alignments
This section is non-normative.
Elements of this vocabulary, as presented in the main SHACL vocabulary, do not indicate alignment with other
domain models, to keep SHACL's dependencies low. However, this document introduces informative alignments here.
This appendix lists profiles of SHACL 1.2 known at the time of this specification's publication, formulated as per
the section Profiling of SHACL. It shall be used to indicate different kinds of
profiles of SHACL only, not as a comprehensive listing of profiles of SHACL. For a comprehensive, or at least
community controlled and growing list of profiles of SHACL, see the SHACL Resources Repository.
A.1 Specification Profiles
A.1.1 SHACL 1.2 Specifications
The profile definitions of the profiles of SHACL 1.2 made according to the SHACL Specifications
are available here:
The Union Profile of SHACL 1.2 is the conceptual whole of SHACL 1.2 which covers all aspects of the
SHACL Specifications. There is no single human-readable Union Profile
specification document — you must read all the documents individually —
but there is both a profile definition and a single validation resource: a
shapes graph comprising
the individual profiles' validation shapes graphs.
Here are a few profiles of SHACL 1.2 that are defined by criteria other than the scope of the various SHACL 1.2
specification documents.
Note
The sections here provide descriptions of the profiles however the maintained definitional resources for them are
contained in the SHACL Community's SHACL Resources Repository
within the folder profiles-of-shacl.
A.2.1 OWL Consistent Profile
Issue 1260: [PROF] Provide details of the SHACL 1.2 OWL Consistent Profile Profiling
The OWL Consistent profile of SHACL is a subset of the vocabulary elements of SHACL that are selected to ensure
shapes definitions do not violate OWL constraints on the classes and predicates they target.
A.2.2 Pretty Print Profile
Issue 1259: [PROF] Provide details of the SHACL 1.2. Pretty Print Profile Profiling
A.2.3 Disallowing Recursive Constraints Profile
This profile establishes structural validation rules for defining SHACL shapes, explicitly prohibiting
the authoring of recursive constraints. While the core SHACL specification permits structural recursion, it
acknowledges that different implementations may evaluate recursive definitions differently. This variance
frequently leads to non-deterministic behavior or infinite validation loops when processors encounter cyclic
data graphs. To ensure predictable and consistent validation outcomes across all compliant processors,
this profile defines the specific shape authoring patterns that are disallowed, such as
self-referencing shapes, mutually dependent shapes, and recursive tree structures.
Definition of Recursive Constraints
A SHACL shapes graph SG conforms to the Non‑Recursive Constraints Profile
iff its shape reference graph (defined below) is acyclic.
Let R(SG) be a directed graph where:
Each node is a shape in SG (any RDF node that is a sh:Shape,
sh:NodeShape, or sh:PropertyShape, or that is used in a position
that denotes a shape as defined below).
There is a directed edge s → t in R(SG) whenever, in SG, shape
s references shape t via a SHACL property whose value directly
identifies a shape or identifies an RDF list containing shape references.
To determine whether a shapes graph conforms to this profile, implementations MUST treat
each of the following properties and list constructs as shape-reference relationships when
constructing the shape reference graph and checking it for cycles:
sh:node
sh:property (edge to the referenced property shape)
sh:qualifiedValueShape
the list members of sh:and, sh:or, and sh:xone
sh:not
sh:memberShape
sh:reifierShape
sh:someValue
A shapes graph violates this profile if it contains any cycle s → ⋯ → s, including:
direct self-reference (a shape references itself), and
indirect self-reference (a shape references another shape that eventually
references the original shape)
self-referential negation (a shape that negates itself)
Validating the Absence of Recursive Constraints
The following SHACL-SHACL shapes graph can be used to validate that a given shapes graph does not
contain any recursive constraints.
Examples of Disallowed Recursive Constraints
The following examples illustrate the types of recursive constraints that are disallowed by this profile.
Direct recursion in a single shape exampleMutually referencing shapes exampleSelf-referential negation
A.2.4 SPARQL Extraction Profile
Note
This profile is described here only, not defined. The various community approaches to SHACL for SPARQL
extraction are being folded into a community-maintained version of this profile in the
SHACL Resources Repository.
The purpose of this profile is to allow SHACL to be used as a data extraction tool. It defines
SHACL elements and patterns for their use that allow shapes graphs using them to be converted into SPARQL
queries SPARQL 1.2 Query Language. Such queries are then able to subset data graphs.
Data extraction from SHACL-to-SPARQL is a task known to be carried out in industry with rules of thumb around
what SHACL elements can be used in this way, for example, the Prez API defines
data payloads for API endpoints using shapes graphs that are limited to basic SHACL elements
such as sh:path, sh:targetClass. An example Prez data definition shapes graph follows.
In the shapes graph above, two shapes are given with the first indicating the values for all properties of a
focus node and its dependent
blank nodes to a path distance of two for
GeoSPARQLFeature objects. The second
indicates only name, bounding box coordinates and members' type and name for GeoSPARQL
FeatureCollection objects. The SPARQL queries Prez generates from these shapes follows.
B. Null Profile Examples
This section is non-normative.
Issue 1464: Ensure Null Profiles in Doc are available in SHACL Community repo Profiling
The null profile descriptions here are for demonstration purposes only. See the
SHACL Community's SHACL Resources Repository for maintained
versions of these null profiles and many more
B.1 Null Profile of POS
This profile is a null profile of the Basic Geo (WGS84 lat/long) Vocabulary also
known as POS. The
purpose of including it here is to demonstrate what a null profile of a very simple RDF
vocabulary looks like and how such is easily made.
The original RDF declaration of POS with all but the first and last change notes removed for brevity is:
The vocabulary above defines two RDFS Class and 5 RDFS Property instances with 3 RDFS domain and one RDFS range
constraint. It does not define an ontology but the namespace of
http://www.w3.org/2003/01/geo/wgs84_pos# is annotated as if it was one.
In the comments on properties, some additional constraints are indicated, such as, for pos:alt: "The
WGS84 altitude of a SpatialThing (decimal meters above the local reference ellipsoid)". From these sorts of
comments we can infer additional SHACL constraints that we can test data with. In this case, we can test that a
value for the predicate pos:alt is a decimal. We cannot require it to be positive as a negative
height can be sensibly interpreted as a depth.
The following shapes graph is a simple attempt at a comprehensive set
of constraints for POS' rule presented as per the recommendations in the 2. Packaging SHACL section.
The above shapes graph was created in two steps:
direct creation of SHACL constraints from OWL constraints
this was done easily and automatically with a common AI tool and then manually enhanced
creation of SHACL constraints from descriptions / usage notes in the POS vocabulary annotations
this was done easily and manually
The resultant shapes graph has good coverage of the POS vocabulary: 9 SHACL shapes for the 2 classes and 6
properties.
To complete the null profile of POS, we need more than just this shapes graph: we also need a profile declaration.
As per the procedure for defining profile of SHACL in 3.1 Defining Profiles of SHACL, we can declare a null profile of
POS like this:
In the profile declaration above, four resources are described: the original vocabulary, here assigned a profile
resource role of Schema, the shapes graph with role of Validation and a human-readable
document with role of Guidance. This last resource is not given here and is
included just to indicate what you might expect a complete null profile to provide. The guidance document would
likely describe how the null profile does and does not implement constraints in the standard profiled - POS - and
perhaps how best to use it.
This profile is meant to provide a SHACL-based validator for SKOS, a very popular RDF
vocabulary for which many non-SHACL validators and related tools have been made, such as
qSKOS
and Skosify.
This null profile implements all the OWL rules of SKOS, as well as some rules stated in
the SKOS standard that are not implemented in the SKOS ontology.
The SHACL validator for this profile is as follows:
Shapes graph for the null profile of SKOS' validation resource
The shapes graph above was generated from SKOS' ontology rules and the SKOS Simple Knowledge Organization System Reference annotations. As with
the POS null profile, a profile declaration is needed in addition to the shapes graph:
Unlike for POS, SKOS has neatly documented requirements in its specification document, so validation shapes have
been created for it referencing those requirements. As with the null profile for POS, the original standard's
specification is used as this null profile's specification because the intent of the null profile is to match
that specification exactly.
Note
A SHACL community-maintained version of this null profile is available at
https://github.com/w3c/shacl-resources. That profile uses the
identifier https://w3id.org/profile/skos-null so that, following 5.10 Rule: conforms to standard, any resource
that conforms to this null profile - by passing its validator - conforms to SKOS, at least to the extent of the
authors of the null profiles shapes graph creation skills.
C. Security Considerations
This section is non-normative.
Like most RDF-based technologies, SHACL processors may operate on graphs that are assembled
from various sources. Some applications may have an open "linked data" ("LD") architecture and dynamically
assemble RDF triples from sources that are outside an organization's network of trust.
Since RDF allows anyone to add statements about any resource, triples may modify the originally
intended semantics of shape definitions or nodes in a data graph and thus feed
into misleading results.
Protection against this (and the following) scenario is achievable by using only trusted
and verified RDF sources and eliminating the possibility that graphs are dynamically added via
owl:imports and sh:shapesGraph.
When creating profiles of other standards, profile creators need to ensure that
their constraints do not violate those standard's rules. If any did so, and if only the
profile's rules, but not the standard's rules, were used to check for data validity, by accident or by design,
data could be wrongly calculated to be valid. This could lead to accidental data release or use, potentially
introducing security issues.
D. Privacy Considerations
This section is non-normative.
Persisted validation results may identify data graphs, shapes graphs, validation agents, and the times at which
validation occurred. Publishers should consider whether this information reveals personal or confidential
information and apply appropriate access controls before sharing it.
E. Acknowledgements
This section is non-normative.
Many people contributed to this specification, including members of the RDF Data Shapes Working Group.