๐งช Shape Authoring Sandbox
Explore how SHACL shapes are written. Load an example, edit it, and see a live parse of the shape graph structure.
Lecture 7 Interactive Learning Companion ยท SHACL ยท Shape Graphs ยท Validation ยท ShEx
Explore each core topic from Chapter 7. Select a category to see syntax, semantics, and annotated examples.
Explore how SHACL shapes are written. Load an example, edit it, and see a live parse of the shape graph structure.
Step through how a SHACL processor evaluates a data graph against a shapes graph. See which nodes conform and which violate.
Select a scenario above to begin the validation walkthrough
Explore the full set of SHACL constraint components and the SHACL vs ShEx comparison. Click a tip to expand it.
| Constraint | Category | What it checks | Example |
|---|---|---|---|
| sh:minCount / sh:maxCount | Cardinality | Min/max number of values for the path | sh:minCount 1 |
| sh:datatype | Value Type | All values must be a given XSD datatype | sh:datatype xsd:string |
| sh:class | Value Type | All values must be instances of a given class | sh:class ex:Person |
| sh:nodeKind | Value Type | IRI, BlankNode, or Literal | sh:nodeKind sh:IRI |
| sh:minExclusive / sh:maxInclusive | Range | Numeric value range bounds | sh:minInclusive 0 |
| sh:minLength / sh:maxLength | String | Literal string length bounds | sh:minLength 1 |
| sh:pattern | String | Value must match a regular expression | sh:pattern "^\\d{4}-" |
| sh:in | Enumeration | Value must be in a given list | sh:in (ex:A ex:B) |
| sh:hasValue | Enumeration | At least one value must equal a given node | sh:hasValue ex:X |
| sh:node | Shape | All values must conform to another shape | sh:node ex:PersonShape |
| sh:and / sh:or / sh:not | Logical | Boolean combinations of shapes | sh:or ( [...] [...] ) |
| sh:sparql | SPARQL | SPARQL SELECT โ any row = violation | sh:sparql [ sh:select ... ] |
SHACL sh:path supports rich SPARQL-style property paths:
sh:path ex:name โ validates values of a single predicate at the focus node.
sh:path [ sh:inversePath ex:knows ] โ validates nodes that point TO the focus node.
sh:path ( ex:worksFor ex:name ) โ chain two predicates; validates the employer's name.
sh:alternativePath, sh:oneOrMorePath, sh:zeroOrMorePath โ mirrors SPARQL property paths.
Test your knowledge of SHACL, ShEx, and shape-based validation. 10 points per correct answer!
Press "Start" to begin the SHACL Challenge!
12 questions covering SHACL, Shape Graphs, Validation, and ShEx. You can review answers before finishing.
Key syntax, rules, and patterns for SHACL and ShEx. Keep this open during revision.
ex:MyShape a sh:NodeShape ;
sh:targetClass ex:Person ;
sh:property [ sh:path ex:name ;
sh:minCount 1 ;
sh:datatype xsd:string ] .sh:targetNode ex:alice # specific node
sh:targetSubjectsOf ex:p # all subjects of p
sh:targetObjectsOf ex:p # all objects of psh:minCount 1 # at least 1 value
sh:maxCount 1 # at most 1 value
sh:minCount 1 ; sh:maxCount 1 # exactly 1sh:datatype xsd:string
sh:datatype xsd:integer
sh:class ex:Person
sh:nodeKind sh:IRI
sh:nodeKind sh:Literal
sh:nodeKind sh:BlankNodesh:and ( ex:ShapeA ex:ShapeB )
sh:or ( ex:ShapeA ex:ShapeB )
sh:not ex:ForbiddenShape
sh:xone ( ex:A ex:B ) # exactly onesh:closed true ;
sh:ignoredProperties ( rdf:type ) ;[ a sh:ValidationReport ;
sh:conforms false ;
sh:result [
sh:focusNode ex:bob ;
sh:resultPath ex:name ;
sh:sourceConstraintComponent
sh:MinCountConstraintComponent ;
sh:resultMessage "Missing name"
]
]sh:severity sh:Violation # default
sh:severity sh:Warning
sh:severity sh:Info<PersonShape> {
ex:name xsd:string MinLength 1 ;
ex:email IRI + ;
ex:age xsd:integer MinInclusive 0 ?
}
# ? = optional + = 1+ * = 0+<OrgShape> {
ex:name xsd:string ;
ex:subOrg @<OrgShape> * # recursive!
}
# Shape map (node โ shape binding):
<http://ex.org/alice> @ <PersonShape>Feature SHACL ShEx
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
Syntax Turtle/RDF ShExC / ShExJ
Targets sh:target* Shape Map
Recursion โ Core โ Native
W3C Status Rec (2017) Sub (2019)
Extensible SHACL-SPARQL Semantic Actions
Tooling Jena, RDF4J shex.js, PyShEx
Best for Enterprise KG Biomedical/Wikiex:AgeShape a sh:NodeShape ;
sh:targetClass ex:Person ;
sh:sparql [
sh:message "Age inconsistent" ;
sh:prefixes ex: ;
sh:select """
SELECT $this WHERE {
$this ex:birthYear ?by ;
ex:age ?age .
FILTER(?age != (2024 - ?by))
}"""
] .โ Give shapes URIs (not blank nodes)
โ Add sh:message to every constraint
โ Use sh:severity to layer criticality
โ Keep shapes & data graphs separate
โ Validate early in your CI/CD pipeline
โ Avoid sh:closed in open-world data
โ Don't skip sh:ignoredProperties
with sh:closed (rdf:type needed!)
โ Run OWL reasoner FIRST, then SHACL