SHACL (Shapes Constraint Language)
W3C Recommendation of 20 July 2017, from the RDF Data Shapes Working Group; editors Holger Knublauch (TopQuadrant) and Dimitris Kontokostas (University of Leipzig). Tier T1: the specification itself, read directly.
SHACL is the validation layer of the rdf stack. The spec defines it as a language for checking RDF graphs against a set of conditions, and the conditions are themselves written in RDF.
Two graphs
Validation takes a shapes graph (the rules) and a data graph (what is being checked). Neither
may change during validation, so running it twice gives the same answer. The data graph is expected to
carry its own rdfs:subClassOf triples so that class targets resolve. Full RDFS inferencing is not
required, and a shapes graph can ask for an entailment regime with sh:entailment.
Shapes, targets, constraints
- A node shape constrains the focus node itself. A property shape has exactly one
sh:pathand constrains the values reached along it. Paths are a subset of SPARQL property paths: sequence, alternative, inverse, and the zero-or-more, one-or-more and zero-or-one operators. - Targets pick the focus nodes: a named node, every instance of a class (subclasses included), a shape that is itself a class, or the subjects or objects of a given predicate.
- Core constraint components every processor must support: value type (
sh:class,sh:datatype,sh:nodeKind), cardinality (sh:minCount,sh:maxCount), value ranges, string tests (length, regex pattern, language tags), comparisons between two properties, logical combinators (sh:not,sh:and,sh:or,sh:xone), nested shapes,sh:closed,sh:hasValueandsh:in. - Results carry a severity:
sh:Violationby default, orsh:Warningandsh:Info.
Some properties do nothing during validation and exist for building forms: sh:name,
sh:description, sh:order, sh:group, sh:defaultValue. The spec states that shapes can also
drive user interfaces, code generation and data integration.
Two levels
SHACL Core needs no SPARQL engine. SHACL-SPARQL adds constraints written as SPARQL queries
and a mechanism for declaring new constraint components; a Core-only processor ignores sh:sparql.
Validation of recursive shapes is left undefined, so each implementation chooses its own behaviour.
The report
Output is one sh:ValidationReport with a boolean sh:conforms (true only when there are no results)
and zero or more results. Each result must name the focus node, the severity and the constraint
component that fired, and may add the path, the offending value, the source shape and a message.
Where it sits
knowledge-representation and rdf list SHACL beside RDFS/OWL as the validation layer, and
ontology-pipeline reads the stack as a build order. The spec text does not discuss open-world
versus closed-world reasoning. The usual contrast is that OWL treats a missing fact as unknown, while a SHACL shape reports it as a
violation. That is a reading of the two designs, not a sentence in this document. sh:closed, which rejects any property a shape does not name, is the clearest closed-world
feature in it.
Related: schema-org markup is RDF too, so a SHACL shapes graph can check it; whether any large consumer of schema.org does so is not something this source says.