Difference between revisions of "SHACL"

From BITPlan cr Wiki
Jump to navigation Jump to search
(Created page with "https://github.com/rudof-project/rudof")
 
Line 1: Line 1:
 +
{{LLMHint}}
 +
= 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.
 +
 +
== 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 ===
 +
<syntaxhighlight lang="turtle">
 +
@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 ;
 +
  ] .
 +
</syntaxhighlight>
 +
 +
This example defines a shape for <code>ex:Person</code> that requires a <code>firstName</code> (string, at least one) and an optional <code>age</code> (integer, must be ≥ 0).
 +
 +
== Tools and Libraries ==
 +
 +
* [https://github.com/TopQuadrant/shacl SHACL API (Java)]
 +
* [https://www.w3.org/2017/SHACL/ SHACL at W3C]
 +
* [https://github.com/RDFLib/pySHACL pySHACL (Python)]
 +
* [https://jena.apache.org/documentation/shacl/ Apache Jena SHACL]
 +
 +
== Alternatives ==
 +
 +
* [[ShEx]] (Shape Expressions) – another RDF validation language
 +
* [[OWL]] (Web Ontology Language) – can express some constraints, but less focused on data validation
 +
 +
== References ==
 +
 +
* [https://www.w3.org/TR/shacl/ W3C Recommendation: SHACL]
 +
* [https://www.w3.org/TR/shacl-ucr/ SHACL Use Cases and Requirements]
 +
 +
 +
= Links =
 
https://github.com/rudof-project/rudof
 
https://github.com/rudof-project/rudof

Revision as of 08:04, 10 July 2025

⚠️ 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.

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.

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

https://github.com/rudof-project/rudof