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
Day 1 — Foundations

Exercises: RDF, Shapes & Targets

Chapters 1–5. Use the Shapes Editor tab to write and test your answers.

Exercise 1.1 — Triples

Write RDF Turtle

Model the following facts as RDF Turtle triples: "The Hobbit" is a Book, authored by J.R.R. Tolkien, published in 1937, with 310 pages. Use the prefix ex: for your namespace.

Reference Solution
Exercise 1.2 — OWA vs CWA

World Assumptions

Given: ex:TheHobbit ex:author ex:JRRTolkien . — Under the Open World Assumption, can we say The Hobbit has exactly one author? What about the Closed World Assumption? Explain why SHACL operates under CWA.

Reference Answer
OWA: No — there might be unknown co-authors.
CWA: Yes — what we see is all there is.
SHACL uses CWA because validation requires
a definitive true/false answer.
Exercise 2.1 — Your First Node Shape

Target Class

Create a node shape rule:Book that targets all instances of ex:Book. Add a property shape requiring that every book has at least one ex:author.

Reference Solution
Exercise 2.2 — Target Node

Constrain a Specific Individual

Create a shape that targets only ex:TheHobbit and constrains that its ex:genre must have the value ex:Fantasy.

Reference Solution
Exercise 2.3 — Named Property Shapes

Reusable Shapes

Rewrite Exercise 2.1 using a named property shape rule:Book-author instead of a blank node. Why is this considered best practice?

Reference Solution
Exercise 2.4 — Property Paths

Sequence & Inverse Paths

Write a property shape that constrains the names of authors of books (sequence path: ex:author / ex:name). Then write another that uses an inverse path to find all things authored by a person.

Reference Solution
Day 2 — Constraints & Stories

Exercises: Core Constraints & Validation

Chapters 6–8. Build shapes group by group, validate them against sample data.

Exercise 3.1 — Value Type Constraints

Class, Datatype & NodeKind

Extend rule:Book with three property shapes: (1) ex:author must be of class foaf:Person, (2) ex:pages must be xsd:integer, (3) ex:publisher must be an IRI. Write conforming and non-conforming data for each.

Reference Solution
Exercise 3.2 — Cardinality

Mandatory & Unique Properties

Make ex:mainTitle mandatory and unique (exactly one) for all books. Make ex:author mandatory but allow multiple. Write data that conforms and data that violates each constraint.

Reference Solution
Exercise 3.3 — Value Range

Date & Number Ranges

Constrain that books can only have a ex:publishedDate after January 1st 2000 (use sh:minExclusive). Constrain ex:pages to less than 10,000. Does "The Hobbit" (1937) conform?

Reference Solution
Exercise 3.4 — String Constraints

Length, Pattern & Language

Add constraints for: (1) ex:mainTitle must be at least 2 characters, (2) ex:isbn must match the regex for ISBN-10 or ISBN-13, (3) ex:mainTitle must be in English, Norwegian, or German.

Reference Solution
Exercise 3.5 — Property Pairs

Equals, Disjoint & Less Than

Constrain that: (1) ex:title must equal ex:mainTitle, (2) ex:author and ex:editor must be disjoint (no person is both), (3) ex:firstEdition must be less than ex:secondEdition.

Reference Solution
Exercise 3.6 — Logical Constraints

Not, And, Or, Xone

Model a rule:Person shape where: (1) persons must NOT have a foaf:status property (sh:not), (2) persons must have both ex:firstname AND ex:surname (sh:and), (3) persons must have either ex:birthDate OR ex:birthYear (sh:or). Bonus: change OR to XONE and explain the difference.

Reference Solution
Capstone — Build Your Own

Design a Shapes Graph for Your Domain

Pick a domain you work with (or invent one). Define at least 2 node shapes, 5 property shapes, and use constraints from at least 4 different categories. Include both conforming and non-conforming sample data. Use the "Capstone Template" button in the editor to get started.

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!