SHACL Course Playground

This resource is for enrolled students.
Enter the course password to continue.

SHACL Course Playground

Playground

SHACL Shapes Editor

Write your shapes graph (left) and data graph (right) in Turtle syntax. Use the preloaded examples or start from scratch.

Shapes Graph

Data Graph

Output / Notes

Reference

SHACL Reference

Quick-reference material from the book. Pick a topic below.

Core Constraint Components (Ch. 6)

CategoryConstraintSHACL PropertyDescriptionExample Value
ShapePropertysh:propertyLinks a node shape to its property shapesrule:Book-author
ShapeNodesh:nodeInherit constraints from another node shaperule:Work
ShapeQualified Value Shapesh:qualifiedValueShapeConstraints for a number of value nodes conforming to a shape[ sh:class ex:Finger ]
Value TypeClasssh:classValue node must be instance of given classfoaf:Person
Value TypeDatatypesh:datatypeValue node must be literal of given datatypexsd:integer
Value TypeNode Kindsh:nodeKindValue node must be IRI, Literal, or BlankNodesh:IRI
CardinalityMin Countsh:minCountMinimum occurrences of the property1
CardinalityMax Countsh:maxCountMaximum occurrences of the property1
Value RangeMin Exclusivesh:minExclusiveValue must be > given value"1999-12-31"^^xsd:date
Value RangeMin Inclusivesh:minInclusiveValue must be ≥ given value0
Value RangeMax Exclusivesh:maxExclusiveValue must be < given value10000
Value RangeMax Inclusivesh:maxInclusiveValue must be ≤ given value10000
StringMin Lengthsh:minLengthMinimum character count2
StringMax Lengthsh:maxLengthMaximum character count11
StringPatternsh:patternMust match regular expression"^(?:\d{9}[\dX]|\d{13})$"
StringLanguage Insh:languageInLanguage tag must be in given list("en" "no" "de")
StringUnique Langsh:uniqueLangOnly one value per language tagtrue
Prop. PairEqualssh:equalsValues must equal those of another propertyex:mainTitle
Prop. PairDisjointsh:disjointValues must not overlap with another propertyex:editor
Prop. PairLess Thansh:lessThanValue must be less than other property's valueex:secondEdition
Prop. PairLess Than Or Eq.sh:lessThanOrEqualsValue must be ≤ other property's valueex:endDate
LogicalNotsh:notMust NOT conform to given shape (negation, ¬x)rule:Agent-status
LogicalAndsh:andMust conform to ALL shapes in list (x ∧ y)( rule:A rule:B )
LogicalOrsh:orMust conform to at least ONE shape (x ∨ y)( rule:A rule:B )
LogicalXonesh:xoneMust conform to exactly ONE shape (x ⊕ y)( rule:A rule:B )
OtherClosedsh:closedOnly declared properties allowedtrue
OtherIgnored Propertiessh:ignoredPropertiesProperties excluded from closed check(rdf:type)
OtherHas Valuesh:hasValueAt least one value node must equal given valueex:Fantasy
OtherInsh:inValue node must be in given list( ex:Fantasy ex:SciFi )
Targets

Target Types (Ch. 5)

TargetSHACL PropertyTargets
Target Classsh:targetClassAll instances of a class
Target Nodesh:targetNodeOne specific node
Target Subjects Ofsh:targetSubjectsOfAll subjects of a property (domain)
Target Objects Ofsh:targetObjectsOfAll objects of a property (range)
Implicit Class TargetShape typed as rdfs:ClassThe class itself is the target
Property Paths

Property Paths (Ch. 5.5)

Path TypeSPARQLSHACL (in sh:path)
Predicateirish:path ex:author
Inverse^irish:inversePath ex:author
Sequencea/b( ex:author ex:name )
Alternativea|bsh:alternativePath ( a b )
Zero-or-morea*sh:zeroOrMorePath ex:a
One-or-morea+sh:oneOrMorePath ex:a
Zero-or-onea?sh:zeroOrOnePath ex:a
Course Day

The Shape of the Day

A one-day introduction to SHACL. About 4½ hours of instruction, with roughly a third of it (~90 minutes) spent hands-on in this playground. The rhythm is deliberate: ~35 minutes of teaching, then a hands-on, then a debrief — repeated.

TimeDurationBlockHands-on
09:00 – 09:2020 minIntroduction—
09:20 – 10:1555 minWhy SHACL (use cases, motivation)—
10:15 – 10:3015 min☕ Break—
10:30 – 11:3060 minShapes, targets & paths (Ch. 5)Exercise 1
11:30 – 12:3060 minCore constraints I (§6.1–6.5)Exercises 2, 3
12:30 – 13:3060 min🍽️ Lunch—
13:30 – 14:3060 minCore constraints II (§6.6–6.8) + SHACL engine (Ch. 8)Exercises 4, 5, 6
14:30 – 14:4515 min☕ Break—
14:45 – 15:0015 minFree practice & wrap-upCapstone
Exercises · ~90 min hands-on

Six exercises plus a capstone challenge, sequenced to match the teaching blocks. 1 follows Shapes & Targets, 2–3 follow Core Constraints I, 4–5 follow Core Constraints II, and the Capstone is for free practice. See the Exercises tab.

What each block does

Introduction + Why SHACL. Set the scene: OWA vs. CWA, where SHACL fits alongside OWL, the data-pipeline architecture. Use cases and motivation — why validation matters.

Shapes, targets & paths (Ch. 5). Node vs. property shapes, target kinds, property-path kinds, and the linking convention. Lord of the Rings as the running example. Then Exercise 1 — deliberately small, a "does everyone's setup work?" checkpoint.

Core constraints I (§6.1–6.5). Value type, cardinality, value range, string-based. Then Exercises 2 and 3 back-to-back. Exercise 3 is where the Turtle-string escaping gotcha for sh:pattern bites — a good pain point to have in class.

Core constraints II (§6.6–6.8) + SHACL engine (Ch. 8). Logical constraints with the truth tables (walk them live — see the Reference → Logic tab), then sh:closed, sh:hasValue, sh:in. Segue into the SHACL engine: validation report structure, result vocabulary, severity levels. Exercises 4, 5, 6. (SHACL-SPARQL from Ch. 7 gets a two-minute mention, not a demo.)

Free practice & wrap-up. The Capstone exercise: bring your own domain, design shapes, read validation reports. This is where SHACL becomes real. Closes with Q&A and pointers for post-course reading.

Running long? Ch. 6 always eats time. If the morning constraints block overruns, drop Exercise 3 and give the ten minutes back to the afternoon. The engine block (Exercise 6) is the one not to squeeze.

Exercises

Hands-on Exercises

Pick a block below to start. Each block has exercises, a shapes editor and pre-loaded data to validate your answers against.

A

Shapes, Targets & Paths

Your first shape — node shapes, target classes, property paths, cardinality and datatype.

Exercise 1 · Ch. 5
B

Core Constraints I

Value range, string patterns, the Turtle-escaping gotcha for sh:pattern.

Exercises 2 – 3 · §6.1 – 6.5
C

Core Constraints II

Logical constraints (sh:or, sh:xone) and closed shapes.

Exercises 4 – 5 · §6.6 – 6.8
D

The SHACL Engine

Read a validation report: focus nodes, result paths, constraint components, severity.

Exercise 6 · Ch. 8
★

Free Practice & Capstone

Combine four or more constraint categories in one shape — or bring your own domain.

Capstone Challenge
Assessment

SHACL Course Quiz

Test your knowledge of the full SHACL curriculum. Score 80% or higher to earn your completion badge. Choose the best answer for each question.

Score: 0 / 20
Question 1 — The Semantic Web
Which organisation standardises the core Semantic Web technologies (RDF, OWL, SPARQL, SHACL)?
  • IEEE
  • ISO
  • W3C
  • IETF
The World Wide Web Consortium (W3C) is responsible for standardising the Semantic Web stack, including RDF, RDFS, OWL, SPARQL, and SHACL.
Question 2 — Logic & Set Theory
In set theory notation, what does the symbol ∈ mean?
  • A is a subset of B
  • a is a member (element) of set B
  • A intersects with B
  • A is the complement of B
The symbol ∈ denotes set membership — it reads "a is an element of B". Subset uses ⊆, intersection uses ∩.
Question 3 — Knowledge Hierarchy
What is the correct order in the knowledge hierarchy, from most basic to most advanced?
  • Information → Data → Knowledge → Insight → Wisdom
  • Data → Knowledge → Information → Wisdom → Insight
  • Data → Information → Insight → Knowledge → Wisdom
  • Data → Information → Knowledge → Insight → Wisdom
The classic knowledge hierarchy runs: Data → Information → Knowledge → Insight → Wisdom, each level building on the previous with added context and understanding.
Question 4 — RDF Fundamentals
In the RDF triple ex:Solaris ex:author ex:Lem ., what role does ex:author play?
  • Predicate
  • Subject
  • Object
  • Namespace
An RDF triple has the structure: subject – predicate – object. ex:author sits in the middle, making it the predicate (the relationship between subject and object).
Question 5 — Turtle Syntax
In Turtle syntax, what does the semicolon (;) do?
  • Terminates a triple
  • Separates multiple objects sharing the same subject and predicate
  • Continues with a new predicate-object pair for the same subject
  • Starts a comment
The semicolon lets you add another predicate-object pair to the same subject. The comma (,) adds another object sharing the same subject and predicate. The dot (.) terminates a statement.
Question 6 — RDFS Inference
Given ex:author rdfs:range ex:Person and ex:Hobbit ex:author ex:Tolkien, what does a reasoner infer?
  • ex:Hobbit is of type ex:Person
  • ex:Tolkien is of type ex:Person
  • ex:Hobbit is of type ex:Author
  • The data is invalid and rejected
rdfs:range means the object of the property is inferred to be of the given type. So the reasoner infers ex:Tolkien a ex:Person. Domain/range is for inference, not validation.
Question 7 — Open vs. Closed World
Under the Open World Assumption (OWA), if a fact is not stated in the data, what is its truth value?
  • Unknown — it might be true or false
  • False
  • True by default
  • An error is raised
OWA (used by OWL/RDF) treats missing information as unknown — absence of evidence is not evidence of absence. The Closed World Assumption (used by SHACL and databases) treats missing information as false.
Question 8 — OWL vs. SHACL
Which statement best describes the relationship between OWL and SHACL?
  • SHACL is designed to replace OWL
  • OWL is for validation, SHACL is for reasoning
  • They do exactly the same thing in different syntax
  • OWL is for reasoning/inference, SHACL is for validation — they are complementary
OWL and SHACL serve different purposes. OWL reasons over data and infers new facts (Open World). SHACL validates data against constraints (Closed World). A good pipeline often uses OWL first, then SHACL.
Question 9 — SHACL Fundamentals
SHACL operates under which assumption?
  • Open World Assumption
  • Unique Name Assumption only
  • Closed World Assumption
  • No particular assumption
SHACL operates under the Closed World Assumption: if a fact is not stated, it is considered false. This is what allows SHACL to detect missing data as a validation error.
Question 10 — Shapes
What distinguishes a property shape from a node shape in SHACL?
  • A property shape uses sh:targetClass
  • A property shape must have sh:path
  • A property shape cannot be reused
  • A node shape always contains sh:path
The defining feature of a property shape is that it contains sh:path, which specifies which property it constrains. Node shapes target focus nodes directly and do not use sh:path.
Question 11 — Targeting
Which SHACL target declaration selects all nodes that appear as the subject of the ex:author predicate?
  • sh:targetSubjectsOf ex:author
  • sh:targetObjectsOf ex:author
  • sh:targetClass ex:author
  • sh:targetNode ex:author
sh:targetSubjectsOf selects all nodes that appear as the subject of triples with the given predicate. sh:targetObjectsOf would select the objects instead.
Question 12 — Property Paths
What does sh:path ( ex:author ex:name ) represent?
  • An alternative path — either ex:author or ex:name
  • An inverse path from ex:name to ex:author
  • A zero-or-more repetition of ex:author
  • A sequence path — first follow ex:author, then follow ex:name
An RDF list in sh:path defines a sequence path. It follows each step in order: starting from the focus node, follow ex:author, then from that node follow ex:name.
Question 13 — Cardinality
A shape requires sh:minCount 1 and sh:maxCount 1 on ex:mainTitle. A book has two titles. What happens?
  • It conforms — sh:maxCount is just a suggestion
  • Only the sh:minCount violation is reported
  • A sh:maxCount violation is reported
  • The second title is silently ignored
Having two values when sh:maxCount 1 is set produces a sh:MaxCountConstraintComponent violation. SHACL constraints are strict — there is no "suggestion" mode.
Question 14 — Value Type Constraints
Which constraint checks that a value is an IRI (not a literal or blank node)?
  • sh:class
  • sh:nodeKind sh:IRI
  • sh:datatype xsd:anyURI
  • sh:hasValue sh:IRI
sh:nodeKind sh:IRI constrains the node kind to be an IRI. sh:class checks rdf:type, and sh:datatype checks literal datatypes — neither checks for IRI vs literal directly.
Question 15 — Logical Constraints
A person has both a ex:birthDate and a ex:birthYear. Does this conform to sh:xone applied to shapes requiring each?
  • No — sh:xone requires exactly one to be true
  • Yes — at least one is present
  • Yes — sh:xone is the same as sh:or
  • It depends on the datatypes
sh:xone (exclusive or) requires that exactly one of the listed shapes conforms. If both conform, it is a violation. sh:or allows one or more to conform.
Question 16 — Closed Shapes
A node shape has sh:closed true and sh:ignoredProperties ( rdf:type ), with one property shape for ex:mainTitle. A node has rdf:type, ex:mainTitle, and ex:author. Does it conform?
  • Yes — ex:author is allowed by default
  • No — ex:author is not declared in the shape or ignored
  • Yes — sh:closed only checks for missing properties
  • No — rdf:type is never allowed on closed shapes
sh:closed true means only properties declared in the shape (via sh:property) or listed in sh:ignoredProperties are allowed. ex:author is neither, so it violates.
Question 17 — Property Pairs
What does the constraint sh:disjoint ex:editor on a property shape for ex:author enforce?
  • The author and editor must be the same person
  • The focus node must not have an editor at all
  • The values of ex:author and ex:editor must share no common values
  • The author property must appear before the editor property
sh:disjoint ensures the set of values for the constrained property shares no elements with the set of values for the referenced property. If the same person appears as both author and editor, it is a violation.
Question 18 — SHACL-SPARQL
In a SHACL-SPARQL constraint on a node shape, what does the variable $this represent?
  • The current focus node being validated
  • The shape itself
  • The property path value
  • The validation report node
$this is a pre-bound variable that refers to the current focus node being validated. On a property shape, $PATH refers to the property path.
Question 19 — Validation Report
What are the two required inputs to a SHACL validation engine?
  • An OWL ontology and a SPARQL query
  • A shapes graph and a validation report
  • A data graph and a SPARQL endpoint
  • A shapes graph and a data graph
A SHACL engine takes a shapes graph (the constraints) and a data graph (the data to validate) as input, and produces a validation report as output.
Question 20 — Validation Result
In a SHACL validation result, which property identifies the specific node that caused the violation?
  • sh:sourceShape
  • sh:resultPath
  • sh:focusNode
  • sh:value
sh:focusNode identifies the node being validated that caused the result. sh:value is the specific value that failed, sh:resultPath is the property, and sh:sourceShape is the shape that defined the constraint.
🏆

SHACL Course Completed!

You scored — you need at least 80% (16/20) to earn the badge. Review the explanations above and try again!