Write your shapes graph (left) and data graph (right) in Turtle syntax. Use the preloaded examples or start from scratch.
Quick-reference material from the book. Pick a topic below.
| Category | Constraint | SHACL Property | Description | Example Value |
|---|---|---|---|---|
| Shape | Property | sh:property | Links a node shape to its property shapes | rule:Book-author |
| Shape | Node | sh:node | Inherit constraints from another node shape | rule:Work |
| Shape | Qualified Value Shape | sh:qualifiedValueShape | Constraints for a number of value nodes conforming to a shape | [ sh:class ex:Finger ] |
| Value Type | Class | sh:class | Value node must be instance of given class | foaf:Person |
| Value Type | Datatype | sh:datatype | Value node must be literal of given datatype | xsd:integer |
| Value Type | Node Kind | sh:nodeKind | Value node must be IRI, Literal, or BlankNode | sh:IRI |
| Cardinality | Min Count | sh:minCount | Minimum occurrences of the property | 1 |
| Cardinality | Max Count | sh:maxCount | Maximum occurrences of the property | 1 |
| Value Range | Min Exclusive | sh:minExclusive | Value must be > given value | "1999-12-31"^^xsd:date |
| Value Range | Min Inclusive | sh:minInclusive | Value must be ≥ given value | 0 |
| Value Range | Max Exclusive | sh:maxExclusive | Value must be < given value | 10000 |
| Value Range | Max Inclusive | sh:maxInclusive | Value must be ≤ given value | 10000 |
| String | Min Length | sh:minLength | Minimum character count | 2 |
| String | Max Length | sh:maxLength | Maximum character count | 11 |
| String | Pattern | sh:pattern | Must match regular expression | "^(?:\d{9}[\dX]|\d{13})$" |
| String | Language In | sh:languageIn | Language tag must be in given list | ("en" "no" "de") |
| String | Unique Lang | sh:uniqueLang | Only one value per language tag | true |
| Prop. Pair | Equals | sh:equals | Values must equal those of another property | ex:mainTitle |
| Prop. Pair | Disjoint | sh:disjoint | Values must not overlap with another property | ex:editor |
| Prop. Pair | Less Than | sh:lessThan | Value must be less than other property's value | ex:secondEdition |
| Prop. Pair | Less Than Or Eq. | sh:lessThanOrEquals | Value must be ≤ other property's value | ex:endDate |
| Logical | Not | sh:not | Must NOT conform to given shape (negation, ¬x) | rule:Agent-status |
| Logical | And | sh:and | Must conform to ALL shapes in list (x ∧ y) | ( rule:A rule:B ) |
| Logical | Or | sh:or | Must conform to at least ONE shape (x ∨ y) | ( rule:A rule:B ) |
| Logical | Xone | sh:xone | Must conform to exactly ONE shape (x ⊕ y) | ( rule:A rule:B ) |
| Other | Closed | sh:closed | Only declared properties allowed | true |
| Other | Ignored Properties | sh:ignoredProperties | Properties excluded from closed check | (rdf:type) |
| Other | Has Value | sh:hasValue | At least one value node must equal given value | ex:Fantasy |
| Other | In | sh:in | Value node must be in given list | ( ex:Fantasy ex:SciFi ) |
| Target | SHACL Property | Targets |
|---|---|---|
| Target Class | sh:targetClass | All instances of a class |
| Target Node | sh:targetNode | One specific node |
| Target Subjects Of | sh:targetSubjectsOf | All subjects of a property (domain) |
| Target Objects Of | sh:targetObjectsOf | All objects of a property (range) |
| Implicit Class Target | Shape typed as rdfs:Class | The class itself is the target |
| Path Type | SPARQL | SHACL (in sh:path) |
|---|---|---|
| Predicate | iri | sh:path ex:author |
| Inverse | ^iri | sh:inversePath ex:author |
| Sequence | a/b | ( ex:author ex:name ) |
| Alternative | a|b | sh:alternativePath ( a b ) |
| Zero-or-more | a* | sh:zeroOrMorePath ex:a |
| One-or-more | a+ | sh:oneOrMorePath ex:a |
| Zero-or-one | a? | sh:zeroOrOnePath ex:a |
Chapters 1–5. Use the Shapes Editor tab to write and test your answers.
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.
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.
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.
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.
Create a shape that targets only ex:TheHobbit and constrains that its ex:genre must have the value ex:Fantasy.
Rewrite Exercise 2.1 using a named property shape rule:Book-author instead of a blank node. Why is this considered best practice?
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.
Chapters 6–8. Build shapes group by group, validate them against sample data.
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.
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.
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?
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.
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.
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.
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.
Test your knowledge of the full SHACL curriculum. Score 80% or higher to earn your completion badge. Choose the best answer for each question.
∈ mean?∈ denotes set membership — it reads "a is an element of B". Subset uses ⊆, intersection uses ∩.ex:Solaris ex:author ex:Lem ., what role does ex:author play?ex:author sits in the middle, making it the predicate (the relationship between subject and object).;) do?,) adds another object sharing the same subject and predicate. The dot (.) terminates a statement.ex:author rdfs:range ex:Person and ex:Hobbit ex:author ex:Tolkien, what does a reasoner infer?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.sh:path, which specifies which property it constrains. Node shapes target focus nodes directly and do not use sh:path.ex:author predicate?sh:targetSubjectsOf selects all nodes that appear as the subject of triples with the given predicate. sh:targetObjectsOf would select the objects instead.sh:path ( ex:author ex:name ) represent?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.sh:minCount 1 and sh:maxCount 1 on ex:mainTitle. A book has two titles. What happens?sh:maxCount 1 is set produces a sh:MaxCountConstraintComponent violation. SHACL constraints are strict — there is no "suggestion" mode.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.ex:birthDate and a ex:birthYear. Does this conform to sh:xone applied to shapes requiring each?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.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?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.sh:disjoint ex:editor on a property shape for ex:author enforce?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.$this represent?$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.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.You scored — you need at least 80% (16/20) to earn the badge. Review the explanations above and try again!