A Tractable Notion of Stratification for SHACL

Julien Corman, Juan L. Reutter, Ognjen SavkovicISWC (P&D/Industry/BlueSky) 2018

Introduction

Validating recursive constraints in the Shapes Constraint Language (SHACL) is a significant challenge for RDF-based data quality assurance. While recursion is a powerful feature for modeling complex data relationships, its inclusion in SHACL often leads to exponential processing times. This paper addresses this intractability by introducing strict stratification, a syntactic restriction that ensures graph validation can be performed in polynomial time (PTIME) while maintaining support for core SHACL operators.

The Complexity of Recursive SHACL

The W3C standard for SHACL does not explicitly define how to handle recursive constraints—situations where Shape A depends on Shape B, which in turn depends back on Shape A. Previous research has demonstrated that even "stratified" SHACL, which prohibits negation within recursive loops, remains NP-hard. This is unexpected because stratification typically guarantees efficiency in other logic programming languages like Datalog. The intractability in SHACL stems from the expressiveness of core constraint components, which can force validators to backtrack through an exponential number of possible assignments.

Strict Stratification

To overcome these complexity hurdles, the authors propose a more rigorous structural requirement called strict stratification. This approach relies on analyzing the dependency graph of the shapes.

  1. Contracted Dependency Graph: The graph is simplified by collapsing positive cycles (loops without negation) into single nodes.
  2. The Strict Rule: A set of shapes is considered strictly stratified if, in the contracted graph, any two shapes are connected by either a single path or multiple paths that contain no negation.
Figure 1: A set of shapes and its corresponding contracted dependency graph, illustrating the structural relationships between shapes.

By enforcing this rule, the structural patterns that necessitate backtracking are eliminated, allowing for more efficient processing.

Validation via 3-Valued Logic

The paper introduces a 3-valued fixed-point algorithm for the actual validation process. This algorithm handles the ambiguity inherent in recursion by labeling nodes as "true" (1), "false" (0), or "unknown" (0.5).

Figure 2: An example graph under validation, showing nodes and their relationships via property P.

The algorithm iteratively updates these labels until they stabilize. Strict stratification ensures that assignments can be made "greedily"—once a shape is assigned a value in a lower stratum, it never needs to be changed to satisfy constraints in a higher layer. This prevents the "backtracking trap" where a negative constraint might otherwise veto a previous assignment, leading to computational blowup.

Key Results and Future Work

The primary contribution of this work is the proof that validation for strictly stratified SHACL is in PTIME. This provides a concrete guarantee that validation will scale reasonably as both the data graph and the constraint set grow. The authors provide a concrete, iterative procedure that correctly identifies graph validity without complex search.

While strict stratification is a powerful tool, it is currently a sufficient but not necessary condition. Many safe and efficient shape definitions might still be rejected by this rule. Future work will focus on relaxing these constraints—perhaps by counting the parity of negations—and integrating these techniques into Datalog engines to leverage existing high-performance logic processors for RDF validation.

Summary updated

BibTeX
@inproceedings{corman2018tractable,
  author = {Julien Corman and Juan L. Reutter and Ognjen Savkovic},
  title = {{A Tractable Notion of Stratification for SHACL}},
  booktitle = {ISWC (P\&D/Industry/BlueSky)},
  year = {2018},
  url = {https://openreview.net/forum?id=ls7f10BvnyV},
}
Figure