Validation of SHACL Constraints over KGs with OWL 2 QL Ontologies via Rewriting

Ognjen Savkovic, Evgeny Kharlamov, Steffen Lamparter

Introduction

In the management of Knowledge Graphs (KGs), ensuring data quality through constraint validation is a critical task. The Shapes Constraint Language (SHACL) has emerged as the standard for this purpose. However, a significant challenge arises when KGs are used in conjunction with ontologies, such as those defined in OWL 2 QL. SHACL operates under the Closed-World Assumption (CWA), meaning it validates constraints based solely on explicitly stated facts. In contrast, ontologies operate under the Open-World Assumption (OWA), where facts can be logically inferred.

This discrepancy leads to a "friction point": a standard SHACL engine might flag a constraint violation because a required fact is inferred rather than explicit, or it might miss a violation because it fails to consider the implications of the ontology. This paper, presented at ESWC 2019, proposes a novel "rewriting" technique to bridge this gap, allowing standard SHACL engines to perform ontology-aware validation.

The Rewriting Approach

The core contribution of this work is a rewriting algorithm that transforms both the ontology and the SHACL constraints into a new, expanded set of SHACL shapes. This approach is advantageous because it requires no modifications to existing data or validation engines; the "intelligence" of the ontology is baked directly into the constraints.

The SHACL+ Fragment

The authors identify a fundamental complexity barrier: rewriting the entire SHACL language to account for OWL 2 QL ontologies is mathematically intractable. Specifically, they prove that general SHACL validation with ontologies is co-NP-hard. To overcome this, they focus on SHACL+, a positive fragment of the language that excludes negation (¬) and "at-most" cardinality constraints (≤n).

Algorithm and Logic

The rewriting process involves several key steps:

  1. Target Rewriting: Using established techniques, the algorithm expands the targets of SHACL shapes. For instance, if a shape targets a class Person and the ontology specifies that Professor is a subclass of Person, the rewritten shape will automatically target Professor as well.
  2. Handling Inferred Entities ("Fresh Nodes"): Ontologies can imply the existence of entities not present in the graph (e.g., "Every Parent must have a Child"). The algorithm introduces "virtual" and "successor" shapes to simulate these entities, enabling the SHACL engine to reason about them without the need for materializing new data.
  3. Canonical Models: The approach leverages the "Canonical Model" property of the DL-Lite family (the basis for OWL 2 QL). By ensuring the rewritten SHACL works on a representative model of the KG and ontology, the authors guarantee correctness.

Theoretical Results and Complexity

The paper establishes two primary theorems regarding the feasibility of this approach:

  • Theorem 1 (Negative Result): For the full SHACL language, a polynomial-sized rewriting does not exist unless P = NP. This justifies the need for restricted fragments.
  • Theorem 2 (Positive Result): For the SHACL+ fragment, a polynomial-sized rewriting always exists.

These results demonstrate that validation of SHACL+ over OWL 2 QL remains tractable, making it a viable solution for industrial-scale Knowledge Graphs, such as the Siemens Knowledge Graph used as a running example in the study.

Practical Implications and Limitations

By producing standard SHACL as an output, the proposed algorithm ensures compatibility with existing tools like Stardog or TopBraid. This allows developers to incorporate formal logical reasoning into their data quality workflows without adopting heavy-duty reasoning engines.

However, the current framework has limitations. It cannot handle negation or upper-bound cardinality constraints. Furthermore, it is currently restricted to the OWL 2 QL profile and does not yet fully support data properties or specific data types (e.g., dates, integers). Future work aims to extend these techniques to the OWL 2 EL profile and optimize the complexity of the generated shapes to maintain high performance in production environments.

Summary updated

BibTeX
@inproceedings{savkovic2019validation,
  author = {Ognjen Savkovic and Evgeny Kharlamov and Steffen Lamparter},
  title = {{Validation of SHACL Constraints over KGs with OWL 2 QL Ontologies via Rewriting}},
  booktitle = {ESWC},
  year = {2019},
  doi = {10.1007/978-3-030-21348-0\_21},
}
Figure