Difference between revisions of "SHACL"
| Line 10: | Line 10: | ||
SHACL is written in RDF itself, making it compatible with existing RDF tools and infrastructures. | SHACL is written in RDF itself, making it compatible with existing RDF tools and infrastructures. | ||
| − | <uml> | + | == UML Class diagram == |
| + | Open in new tab to be able to click the links | ||
| + | <uml format='svg'> | ||
class Shape { | class Shape { | ||
+targetClass : rdfs:Class | +targetClass : rdfs:Class | ||
Revision as of 06:40, 13 July 2025
SHACL (Shapes Constraint Language)
SHACL (Shapes Constraint Language) is a W3C standard for validating and describing the structure of RDF (Resource Description Framework) data. SHACL enables users to define constraints (called "shapes") on RDF graphs, ensuring that data conforms to expected schemas and business rules.
Overview
SHACL provides a way to:
- Describe the expected structure of RDF data using shapes and constraints.
- Validate RDF graphs against these shapes.
- Provide human- and machine-readable documentation of data models.
SHACL is written in RDF itself, making it compatible with existing RDF tools and infrastructures.
UML Class diagram
Open in new tab to be able to click the links
Core Concepts
Shapes
A shape is a node in an RDF graph that specifies constraints about the data. Shapes can be used to describe:
- The types of nodes (e.g., Person, Address).
- The required properties for nodes.
- Value types, ranges, and cardinalities.
Targets
Shapes are associated with target nodes in the data graph using target declarations (e.g., by node type, specific node, or all nodes).
Constraints
SHACL defines a variety of constraint components, including:
- Property constraints (e.g., property must exist, value type).
- Cardinality constraints (e.g., minCount, maxCount).
- Pattern and datatype constraints.
- Logical constraints (AND, OR, NOT).
- Complex expressions via SPARQL-based constraints.
Example
Defining a Person Shape
@prefix sh: <http://www.w3.org/ns/shacl#> .
@prefix ex: <http://example.org/> .
ex:PersonShape
a sh:NodeShape ;
sh:targetClass ex:Person ;
sh:property [
sh:path ex:firstName ;
sh:datatype xsd:string ;
sh:minCount 1 ;
] ;
sh:property [
sh:path ex:age ;
sh:datatype xsd:integer ;
sh:minInclusive 0 ;
] .
This example defines a shape for ex:Person that requires a firstName (string, at least one) and an optional age (integer, must be ≥ 0).
Tools and Libraries
Alternatives
- ShEx (Shape Expressions) – another RDF validation language
- OWL (Web Ontology Language) – can express some constraints, but less focused on data validation
References
Links
⚠️ LLM-generated content notice: Parts of this page may have been created or edited with the assistance of a large language model (LLM). The prompts that have been used might be on the page itself, the discussion page or in straight forward cases the prompt was just "Write a mediawiki page on X" with X being the page name. While the content has been reviewed it might still not be accurate or error-free.