Table of Contents

Introduction

SHACL (Shapes Constraint Language) is a W3C standard for validating RDF data against defined constraints, ensuring data quality and consistency within semantic web applications. It provides a mechanism to define rules for data structure and content in a way that can be automatically checked by systems.

SHACL is like a "data quality checker" for RDF graphs, ensuring that data follows specific patterns and constraints, similar to how SQL constraints ensure data integrity in relational databases.

Overview

SHACL is a Semantic Web Technology (SWT) used for constraint validation in ontology-aligned data. It enables closed-world analysis, allowing for the verification of data against specific requirements that cannot be easily checked using standard Description Logic (DL) reasoning.

SHACL is particularly valuable in the context of Digital Engineering (DE) for ensuring that models and data meet specific verification criteria. It complements other verification approaches in the Semantic System Verification Layer (SSVL), such as Open World Analysis (DL reasoning) and Graph-Based Analysis.

SHACL is not supported in every triplestore environment, so it’s important to verify compatibility with your chosen repository before implementing SHACL validation.

Relationship to Other Technologies

SHACL works alongside other Semantic Web Technologies to provide comprehensive data validation:

Technology

Role in SHACL Ecosystem

SPARQL

Used to query data for SHACL shapes; SHACL can be combined with SPARQL for more targeted validation

RDF

The data format validated by SHACL

OWL

Provides the ontology structure that SHACL constraints reference

Triplestore

The repository where RDF data and SHACL shapes are stored

SHACL in the Semantic System Verification Layer

SHACL is one of the three prongs of the Semantic System Verification Layer (SSVL), which provides a comprehensive approach to model verification:

Verification Approach

Use Case

Open World Analysis (DL Reasoning)

Checking taxonomic relationships and logical consistency

Closed World Analysis (SHACL)

Verifying specific constraints like existence, cardinality, and data patterns

Graph-Based Analysis

Analyzing graph structures (e.g., checking for cycles in directed graphs)

Position in Knowledge Hierarchy

Broader concepts: - Part IV (is-a)

Details

SHACL works by defining "shapes" that specify constraints on RDF data. These shapes can be applied to specific targets in the graph, and the SHACL engine checks whether the data conforms to the defined constraints.

Basic SHACL Structure

A SHACL shape consists of: 1. A target (the data to validate) 2. A set of constraints (rules to validate against) 3. A message (for reporting violations)

The basic structure of a SHACL shape can be represented as:

@prefix sh: <http://www.w3.org/ns/shacl#> .
@prefix ex: <http://example.org/> .

ex:SocialSecurityNumberShape
    a sh:Shape ;
    sh:targetClass ex:Person ;
    sh:property [
        sh:path ex:ssn ;
        sh:minCount 1 ;
        sh:maxCount 1 ;
        sh:datatype xsd:string ;
        sh:pattern "[0-9]{3}-[0-9]{2}-[0-9]{4}" ;
        sh:message "Social security number must be in the format 123-45-6789" ;
    ] .
The example above shows a SHACL shape that validates social security numbers. It ensures that every Person has exactly one ssn property with a value matching the pattern "123-45-6789".

Advanced SHACL Features

SHACL supports advanced features that allow for more complex validation:

  1. SHACL-SPARQL: Combining SHACL with SPARQL to create more targeted constraints

  2. SHACL-Advanced Features: Using SPARQL queries directly within SHACL shapes for complex validation logic

  3. Validation Messages: Providing specific error messages for different types of violations

SHACL can be combined with SPARQL to create more targeted constraints. This is particularly useful when validation rules depend on data that isn’t directly represented in the graph structure. For example, you might need to check that a value falls within a range defined by other properties.

SHACL Validation Process

The SHACL validation process works as follows:

  1. Define SHACL shapes that specify the constraints to be validated

  2. Load the shapes into the triplestore

  3. Run the SHACL validation engine against the RDF data

  4. Review validation results and handle any violations

When implementing SHACL, it’s important to consider the closed-world assumption. Unlike Description Logic reasoning (which operates under an open-world assumption), SHACL assumes that all relevant data is present and checks for the existence of required properties and values.

Practical applications and examples

SHACL is widely used in Digital Engineering for model verification, particularly in the context of the Armaments Interoperability and Integration Framework (IoIF).

Example: Verifying Value Property Tagging

One practical application of SHACL is verifying that all value properties in a model are tagged with appropriate ontology terms, as required in the System of Analysis (SoA) model requirements.

@prefix sh: <http://www.w3.org/ns/shacl#> .
@prefix ex: <http://example.org/> .
@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .

ex:ValuePropertyTaggingShape
    a sh:Shape ;
    sh:targetClass ex:ValueProperty ;
    sh:property [
        sh:path rdf:type ;
        sh:minCount 1 ;
        sh:datatype rdf:PlainLiteral ;
        sh:or (
            [ sh:in (ex:TaggedWithOntologyTerm) ]
            [ sh:in (ex:TaggedWithDomainTerm) ]
        ) ;
        sh:message "Value property must be tagged with a value from the loaded ontologies" ;
    ] .
This SHACL shape ensures that all ValueProperty instances have at least one rdf:type property that is either "TaggedWithOntologyTerm" or "TaggedWithDomainTerm", which corresponds to Requirement 7 in the SoA model requirements.

Catapult Example: SHACL Validation

In the Catapult example, SHACL is used to verify that value properties are tagged with ontology terms:

The Catapult example intentionally seeds a defect by removing the CircularErrorProbability (CEP) from an objective to demonstrate SHACL validation.

Scenario

Result

Removed CircularErrorProbability (CEP) from objective

SHACL reports: "Violation: Requirement 7 - Value Property: 'CEP' is not tagged with a loaded ontology term"

This demonstrates how SHACL can be used to catch specific data quality issues that would not be detected by open-world reasoning alone.

SHACL with SPARQL for Advanced Validation

SHACL can be combined with SPARQL to create more complex validation rules. The following example shows a SHACL shape that uses a SPARQL query to validate a constraint:

@prefix sh: <http://www.w3.org/ns/shacl#> .
@prefix ex: <http://example.org/> .
@prefix sparql: <http://www.w3.org/ns/sparql#> .

ex:AdvancedShape
    a sh:Shape ;
    sh:targetClass ex:Catapult ;
    sh:property [
        sh:path ex:armLength ;
        sh:datatype xsd:float ;
        sh:validation [
            sh:select """
                SELECT ?armLength
                WHERE {
                    ?catapult ex:armLength ?armLength .
                    FILTER (?armLength > 1.5 && ?armLength < 3.0)
                }
            """ ;
            sh:message "Arm length must be between 1.5 and 3.0 meters" ;
        ] ;
    ] .

This advanced SHACL shape uses a SPARQL query to validate that the armLength property falls within a specific range. This demonstrates how SHACL can be extended beyond basic constraints to handle more complex validation logic.

References

SHACL Relationship Diagram

Visualize SHACL’s relationship to other Semantic Web Technologies and Digital Engineering concepts

graph TD A[SHACL] --> B[Semantic Web Technologies] A --> C[Digital Engineering] A --> D[Verification] B --> E[RDF] B --> F[OWL] B --> G[SPARQL] C --> H[IoIF] C --> I[SoA] C --> J[SSVL] D --> K[Closed World Analysis] D --> L[Data Validation] K --> M[SHACL] L --> N[SHACL] M --> O[Requirement Verification] N --> P[Data Quality Checks] O --> Q[Model Requirements] P --> R[Ontology-Aligned Data] R --> S[Triplestore] S --> T[SHACL Engine]

Associated Diagrams

figure_22.png