An ontology says what is true. It does not check that the data arrived complete. A requirement such as "a person must have exactly one name" is written in SHACL, and the written requirement is called a shape.
Break the data on purpose
Shape: a person has exactly one name, and whatever they keep must be an animal.
Data
ex:minji a ex:Person . ex:minji ex:name "Minji" . ex:minji ex:keeps ex:nabi . ex:nabi a ex:Cat . # Cat ⊂ Animal ex:seoul a ex:City .
Validation report
sh:conforms true · conforms to the shape
Use the buttons above to cause a violation.
Writing a shape
A shape says two things: what to check (the target) and what must hold (the constraints).
ex:PersonShape a sh:NodeShape ;
sh:targetClass ex:Person ; # who is checked
sh:property [
sh:path ex:name ; # which property
sh:minCount 1 ; sh:maxCount 1 ; # exactly one
sh:datatype xsd:string
] ;
sh:property [
sh:path ex:keeps ;
sh:class ex:Animal # the value must be an animal
] .| Constraint | Meaning |
|---|---|
| sh:minCount, sh:maxCount | How many values |
| sh:datatype | The kind of value: string, integer, date |
| sh:class | The class the value must belong to |
| sh:pattern, sh:minLength | The form of a string |
| sh:in | A list of allowed values |
| sh:closed | No properties other than those listed |
The result is a report
The outcome is RDF too. It says whether everything passed (sh:conforms) and, per violation, which node (sh:focusNode), which property (sh:resultPath) and which constraint.
Think the opposite way to OWL
OWL treats what is not stated as unknown. SHACL judges only what is in the graph now. If a name is missing, OWL assumes it exists somewhere; SHACL reports a violation. So they are used together: the ontology fixes meaning, shapes protect quality.
When choosing an ontology, see whether shapes are published with it. They are the most concrete guide to how data for that ontology should be filled in. The application profiles of DCAT are published this way.