This specification defines elements of the SHACL Shapes Constraint Language created to allow for profiles of SHACL and profiling with SHACL.
SHACL is a language for validating RDF graphs against a set of conditions, so this document's scope is limited to profiling of RDF graphs, including graphs containing SHACL Shapes.
The namespace for SHACL Profiling terms is http://www.w3.org/ns/shpr#
The suggested prefix for the SHACL Profiling namespace is shpr
The introduction provides background concepts of profiling and states this specification's scope. It also provides term definitions and describes document conventions.
Section 2 covers packaging of SHACL for management.
Sections 3 & 4 cover the two main modes of profiling with SHACL, building on packaging.
Profiling is the act of creating a "profile" of something.
Generically, in English, a "profile" of something is as follows:
The outline of a physical object or feature, or a representation of this
- Oxford English dictionary, use of the word "profile" since the 17th century
Within the world of data, a derived definition of "profile" consistent with the above is:
A summary or an extraction
In this definition, the essence of the English word is retained, since a summary or extraction of or from a data object may be an outline of it; for example, a 2D representation of a 3D spatial object. or a statistical summary of a dataset having lots of parts.
Warning: This background of profiling up to this point in the Introduction may be up-streamed to an updated version of [[dx-prof]].
By definition, SHACL constrains RDF data. Therefore, any data that is valid according to a shapes graph will be a profile of the data graph that was validated. If a shapes graph validates all elements of a data graph, the resulting valid data will be a "null" profile of the data graph, meaning it is identical to the original data graph.
[[[dx-prof]]] defines a profile in the context of a specification to be:
a specification that constrains, extends, combines, or provides guidance or explanation about the use of other specifications
If a shapes graph is taken to be a "specification," then not only is the data that is valid according to the shapes graph a profile of the validated data graph, but the shapes graph itself also serves as a profile of the data model used for the data graph.
Within this document, we describe how to package SHACL information for optimal profiling and we exemplify this with packaging of the SHACL shapes created for each of the SHACL Specifications.
With the above section's concepts in mind, this specification defines the following:
Terminology used throughout this specification is either defined here or taken from one of several sources. Those other sources are:
Terms taken from other sources are linked to their definitions in text.
The terms defined here are:
Warning: The definition of null profile may be up-streamed to an updated version of [[dx-prof]].
All the defined terms used in this specification are listed in the index.
Within this specification, the following namespace prefix definitions are used:
| Prefix | Namespace |
|---|---|
owl: |
http://www.w3.org/2002/07/owl# |
rdfs: |
http://www.w3.org/2000/01/rdf-schema# |
sh: |
http://www.w3.org/ns/shacl# |
ex: |
http://example.com/ns# |
Within this specification, the following JSON-LD context is used:
{
"@context": {
"owl": "http://www.w3.org/2002/07/owl#",
"rdfs": "http://www.w3.org/2000/01/rdf-schema#",
"sh": "http://www.w3.org/ns/shacl#",
"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 specification, color-coded boxes containing RDF graphs in 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. The JSON-LD specification fragments use the context given above. Only the Turtle specifications will have parts highlighted.
// This box represents an input shapes graph
{
"@id": "ex:s",
"ex:p": {
"@id": "ex:o"
}
}
// This box represents an input data graph
{
"@graph": [
{
"@id": "ex:Alice",
"@type": "ex:Person"
},
{
"@id": "ex:Bob",
"@type": "ex:Person"
}
]
}
// This box represents an output results graph
Grey boxes such as this include syntax rules that apply to the shapes graph.
true denotes the RDF term "true"^^xsd:boolean.
false denotes the RDF term "false"^^xsd:boolean.
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]
Packaging of SHACL is the presentation of SHACL elements - shapes, rules, etc. - in relation to container objects.
There are multiple reasons to want to identify groups of SHACL Elements and to be able to know the relations between groups and individual Elements. These reasons include wanting to understand the purpose of groups, how changes in one group affect other groups, and how to create new groups. Three Use Cases have been articulated for this:
Solutions to the Use Cases indicated above result in the following recommendations that build on well-established practice, such as the use of instances of owl:Ontology to group SHACL Elements:
owl:Ontology SHOULD be used to group instance of SHACL Elementsowl:Ontology that defines it with the rdfs:isDefinedBy predicateowl:Ontology that uses a SHACL Element, but does not define it, SHOULD indicate the SHACL Element as a member with the rdfs:member predicateowl:Ontology being used to group SHACL Elements SHOULD indicate dependence on other groups of SHACL Elements identified using instances of owl:Ontology with the owl:imports predicateThe following subsections detail each of these recommendations.
Instances of owl:Ontology SHOULD be used to group instance of SHACL Elements.
SHACL Elements, like much other RDF definitional data, is often grouped within instances of [[[owl2-rdf-based-semantics]]]'s owl:Ontology class.
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:Property within a Turtle
file. The file also contains an instance of owl:Ontology presenting metadata for the validator, such as its
modified date, a license for its use, and so on.
This recommendation formalizes that style of packaging.
The use of a specialised object, perhaps a subclass of owl:Ontology, for grouping of SHACL Elements
was considered for this recommendation but rejected since it's easy enough to understand what kind of
ontology is identified by an instance of owl:Ontology by just inspecting its contained elements.
See the following recommendations for ontology/element linking.
An instance of a SHACL Element SHOULD indicate the instance of an owl:Ontology 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 an owl:Ontology 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 suggests that the SHACL Element creator should indicate the group within which a SHACL Element is defined. An example of such an assertion in RDF is as follows:
{
"@graph": [
{
"@id": "ex:ont-M",
"@type": "owl:Ontology"
},
{
"@id": "ex:shape-1",
"@type": "sh:NodeShape",
"rdfs:isDefinedBy": {
"@id": "ex:ont-M"
}
}
]
}
An instance of owl:Ontology that uses a SHACL Element, 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 the rdfs:isDefinedBy, as in the example above, is as follows:
{
"@graph": [
{
"@id": "ex:ont-M",
"@type": "owl:Ontology",
"rdfs:member": {
"@id": "ex:shape-1"
}
},
{
"@id": "ex:ont-Other",
"@type": "owl:Ontology"
},
{
"@id": "ex:shape-1",
"@type": "sh:NodeShape",
"rdfs:isDefinedBy": {
"@id": "ex:ont-Other"
}
}
]
}
Instances of owl:Ontology being used to group SHACL Elements SHOULD indicate dependence on other groups of SHACL Elements identified using instances of owl:Ontology 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's 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.
{
"@graph": [
{
"@id": "ex:ont-M",
"@type": "owl:Ontology"
},
{
"@id": "ex:ont-N",
"@type": "owl:Ontology",
"owl:imports": {
"@id": "ex:ont-M"
}
}
]
}
Dependency implications can be drawn from the use of the four recommendations above which can be used to answer the three Use Cases indicated in the Motivation section.
TODO
This section describes some profiles of SHACL 1.2 that were created alongside the SHACL 1.2 Specifications. It also indicates how to create more profiles of SHACL.
To validate RDF data against any of these Specification Profiles, or the Union Profile defined below, use the validators listed in the SHACL 1.2 Overview's SHACL-SHACL appendix.
The Specification Profiles are profiles of SHACL 1.2 defined in each of the specifications listed above.
When described using terminology from [[[dx-prof]]], the online document form of each specification is just one of many resources that altogether make the specification. It 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 validator for each profile that plays the role of Validation - "Supplies instructions about how to verify conformance of data to the profile". These validation resources are listed in SHACL 1.2 Overview's SHACL-SHACL appendix.
Together, these Base Profiles cover all of SHACL 1.2 and they are bundled together within the Union Profile, defined below.
The Union profil
This section describes how to profile specifications with SHACL.
SHACL is a language that can implement constraints and inference rules for RDF data. These two things are not the complete set of things that a profile designer may wish to do; for example, they may want to include documentation about why and how the profile was created, or provide new model elements (classes, predicates, etc.) within an extended schema.
Since SHACL cannot be used for all possible profile parts, profile designers need to look to specifications outside the SHACL family of specifications for guidance on a profile's total set of parts and how to relate them to one another. [[[dx-prof]]] is expected to be used for this.
Referencing [[[dx-prof]]]'s vocabulary of Resource Role Instances, it seems clear that SHACL graphs can be applied to the role of Validation within a profile and perhaps also to the role of Specification, since SHACL can be used to declare Node and Property Shapes just as OWL can be used to declare Classes and Properties.
SHACL resources can also document the constraints they implement validation shapes for, therefore they can also be applied to the Constraints role.
They could also be applied to the Mapping role, if SHACL Rules are implemented to transform data from one model to another.
SHACL lists of values required for use with a model could be applied to the Vocabulary role.
A null profile of a specification, created using SHACL, is a profile of that specification in which SHACL is used to implement some, and likely all the specification's rules, but no other rules, in SHACL.
The main purpose of creating a null profile of a specification using SHACL is to enable the testing of conformance to that specification by SHACL validation. This purpose exists because many RDF data models exist that have a model specification, perhaps an OWL model or only a natural-language document of a model, but do not provide a mechanism for data validation, such as a SHACL validator.
While null profiles of specifications can be created using mechanism other than SHACL, here we focus only on the use of SHACL.
An example of a non-SHACL validator for RDF data that acts as a null profile is the W3C's [[[prov-constraints]]] which provides a list of constraints that apply to provenance data formulated according to [[[prov-o]]]. [[[prov-constraints]]] implements no constraints beyond those stated or implied in [[[prov-o]]] and the conceptual [[[prov-dm]]], however it does include tests for things that the models do not explicitly model but whose proper use requires, e.g., for ordering of temporal entities. Implementations of those constraints have been made as Python scripts that execute SPARQL queries, allowing for RDF data validation.
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 specifications, profile creators need to ensure that their constraints do not violate those specification's rules. If any did so, and if only the profile's rules, but not the specification'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.
Many people contributed to this specification, including members of the RDF Data Shapes Working Group.
TODO
Descriptions of each SHACL 1.2 specification as a Profiles Vocabulary profile, including a listing of all their resources and the roles they play, is given in Appendix G below.
The individual profiles are as follows:
http://www.w3.org/ns/shacl#shacl12-core-profile
The set of SHACL 1.2 elements defined in the SHACL 1.2 Core specification.
http://www.w3.org/ns/shacl#shacl12-sparql-profile
The set of SHACL 1.2 elements defined in the SHACL 1.2 SPARQL specification.