<!DOCTYPE article PUBLIC "-//NLM//DTD JATS (Z39.96) Journal Archiving and Interchange DTD v1.0 20120330//EN" "JATS-archivearticle1.dtd">
<article xmlns:xlink="http://www.w3.org/1999/xlink">
  <front>
    <journal-meta />
    <article-meta>
      <title-group>
        <article-title>A Tractable Notion of Stratification for SHACL</article-title>
      </title-group>
      <contrib-group>
        <contrib contrib-type="author">
          <string-name>Julien Corman</string-name>
          <xref ref-type="aff" rid="aff0">0</xref>
        </contrib>
        <contrib contrib-type="author">
          <string-name>Juan L. Reutter</string-name>
          <xref ref-type="aff" rid="aff1">1</xref>
        </contrib>
        <contrib contrib-type="author">
          <string-name>Ognjen Savkovic´</string-name>
          <xref ref-type="aff" rid="aff0">0</xref>
        </contrib>
        <aff id="aff0">
          <label>0</label>
          <institution>Free University of Bozen-Bolzano</institution>
          ,
          <addr-line>Bolzano</addr-line>
          ,
          <country country="IT">Italy</country>
        </aff>
        <aff id="aff1">
          <label>1</label>
          <institution>PUC Chile and Center for Semantic Web Research</institution>
          ,
          <addr-line>Santiago</addr-line>
          ,
          <country country="CL">Chile</country>
        </aff>
      </contrib-group>
      <abstract>
        <p>This article introduces a restriction on the usage of negation in SHACL “core constraint components” constraints, called strict stratification, which guarantees tractability of graph validation. SHACL Specification and Formal Semantics</p>
      </abstract>
    </article-meta>
  </front>
  <body>
    <sec id="sec-1">
      <title>1 Introduction</title>
      <p>
        One of the challenges of recent RDF-based applications is managing data quality [
        <xref ref-type="bibr" rid="ref1">1</xref>
        ],
and several systems already provide RDF validation procedures (e.g., https://www.
stardog.com/docs/, https://www.topquadrant.com/technology/shacl/).
This created the need for a standardized declarative constraint language for RDF, and for
mechanisms to detect violations of such constraints. An important step in this direction is
SHACL, or Shapes Constraint Language (https://www.w3.org/TR/shacl/) which
has become a W3C recommendation in 2017.
      </p>
      <p>
        The SHACL specification however leaves explicitly undefined the validation of
recursive constraints. In a previous article [
        <xref ref-type="bibr" rid="ref2">2</xref>
        ], we showed that extending the
specification’s semantics to accommodate for recursion leads to intractability (in the size of the
graph) for the so-called “core constraint components” of SHACL. This result holds for
stratified constraints already, which may come as a surprise, considering that stratification
guarantees tractability in well-studied recursive languages such as Datalog.
      </p>
      <p>Our previous work identified a tractable fragment of SHACL’s core components.
In this paper, we propose an alternative approach to gain tractability, retaining all
SHACL operators, but strengthening the stratification condition traditionally used in logic
programming. More exactly, we introduce a syntactic condition on shape constraints
called “strict stratification”, which guarantees that graph validation is in PTIME in
combined (i.e. graph and constraints) complexity. We also describe a procedure to
perform such validation.</p>
      <p>
        The current paper is not self-contained, due to space limitations, but all definitions
can be found in our previous article [
        <xref ref-type="bibr" rid="ref2">2</xref>
        ] or its online extended version [
        <xref ref-type="bibr" rid="ref3">3</xref>
        ].
We briefly recall some notions introduced in [
        <xref ref-type="bibr" rid="ref2 ref3">2, 3</xref>
        ]. We defined a graph validation problem
which captures the target-based validation procedure depicted in the SHACL specification.
An instance of the validation problem is a tuple hG; S; s0; v0i, where G is a labeled
graph, S = fs0 =: s0 ; : : : ; sn =: sn g is a set of shape definitions (also called “shapes”
in what follows), s0 is a shape defined in S, and v0 is a node in G. The problem consists
in deciding whether v0 verifies the constraint s0 for s0, given S and G. We will call
hs0; v0i the target of this instance. Each constraint si follows the following syntax:
::=
&gt; j s j I j 1 ^ 2 j : j
n r: j EQ(r1; r2)
where &gt; means boolean true, s is a shape name defined in S, I is an IRI, r is a SPARQL
property path, and n 2 N+. Further, ^ stands for conjunction, : for negation, “ n r: ”
means “must have at least n r-successors in G verifying ”, and “EQ(r1; r2)” means
that the r1 and r2-successors of a node must coincide. A translation from SHACL core
constraint components to this syntax and conversely can be found in [
        <xref ref-type="bibr" rid="ref3">3</xref>
        ].
      </p>
      <p>
        According to this syntax, a shape can reference another. But the SHACL specification
leaves open the recursive case, i.e. when a shape references itself, either directly, or via a
reference cycle. As a solution, we proposed a semantics based on the notion of assignment,
that maps (positive and negative) shape labels to sets of nodes, and we defined constraint
evaluation given an assignment. Formally, a shape assignment for G and S is a total
function from pairs hs; vi of shape name and node to f0(false); 0:5(unknown); 1(true)g
(the “unknown” value is used to deal with cases when recursion and negation can be
arbitrarily combined). The evaluation of formula at node v given assignment is
written J Kv;G; (for a formal definition we refer to [
        <xref ref-type="bibr" rid="ref2">2</xref>
        ] or [
        <xref ref-type="bibr" rid="ref3">3</xref>
        ]). The input hG; S; s0; v0i
is valid ff there exists a shape assignment for G and S such that (i) (s0; v0) = 1, and
(ii) (s; v) = J sKv;G; for each shape s defined in S and node v in G.
3
      </p>
    </sec>
    <sec id="sec-2">
      <title>Strictly Stratified SHACL and Validation</title>
      <p>This section defines strict stratification of a set of SHACL shapes, and proposes a PTIME
validation algorithm (combined complexity) for this case. We chose to convey the general
intuition behind stratification from a procedural perspective, as follows: if there is a
satisfying assignment for a given input, then it may be built stratum by stratum, starting
from the lowest stratum, and assigning shapes in a greedy fashion, without the need to
backtrack from a higher to a lower stratum. However, adopting the classical definition of
stratified negation (borrowed from Datalog) is not sufficient to avoid such backtracking.
This is why we define the stronger notion of strict stratification.</p>
      <p>Let S be a set of shapes. We say that shape s1 references shape s2 if s2 appears in
the definition of s1. Further, we define the dependency graph of S as the directed graph
with all shape names defined in S as nodes, and an edge from s1 to s2 iff s1 references
s2. If the reference is in the scope of negation, then the edge is labeled with a negation
symbol (as in Fig. 1), and we call it a negative edge. A path between two nodes is called
negative if it contains at least one negative edge, and positive otherwise. S is stratified iff
its dependency graph has no negative cycle. Finally, we define the contracted dependency
graph of S as the graph obtained from its dependency graph by contracting all positive
strongly connected components.</p>
      <p>Definition 1 (strict stratification). A set S of shapes is strictly stratified if, for any pair
(s1; s2) of nodes in its contracted dependency graph, either:
– there is at most one path from s1 to s2, or
– all paths from s1 to s2 are positive.
s1
s0
v2</p>
      <p>P
P
:
s2
In this definition, using the contracted dependency graph (rather than the dependency
graph) allows us to capture a more expressive fragment of SHACL. We also note that
from this definition, a strictly stratified set of shapes must be stratified.
Example 1. Consider the three shape definitions and their contracted dependency graph
in Figure 1. This set of shape is stratified, but not strictly stratified, since there are more
than one paths from s0 to s2, and one of them is negative.</p>
      <p>s2 =: ( 1 P:s2)
s0 =: ( 1 P:s1) ^ ( 1 P:s2)</p>
      <p>:
s1 = :( 1 P:s2)
Example 2. Consider again the shapes from Example 1, together with the graph in
Figure 2. Assume now that one tries to build a validating assignment for the target
hv0; s0i in a greedy fashion, taking advantage of stratification, thus starting from the
lowest stratum fs2g. Then s2 can be assigned to v0; v2 and v3. Moving up to the next
stratum fs0; s1g, s0 cannot be assigned to v0, because the definition of s1 is violated by
v1, and therefore the conjunct ( 1 P:s1) is not verified by v0. In order to find a validating
assignment, one would need to backtrack, reverting the decision to assign s2 to v2. But
the decision to assign s2 to v3 on the other hand should not be reverted, otherwise the
conjunct ( 1 P:s2) would not be verified by v0 anymore. It can be easily seen that such
pattern can lead to a blowup of backtracking alternatives, exponential in the size of the
graph under validation.</p>
      <p>
        The intuition for intractability is illustrated by Example 2 (in terms of backtracking),
and was made more formal in [
        <xref ref-type="bibr" rid="ref3">3</xref>
        ], with a reduction from boolean circuit satisfiability.
Intractability does not hold for strictly stratified shapes though, which intuitively
guarantees that no backtracking is needed. We make this more precise in the following (a
complete formalization with proofs can be found in [
        <xref ref-type="bibr" rid="ref3">3</xref>
        ]).
      </p>
      <p>Let G;S be the family of all (3-valued) assignments for G and S. The operator TG;S :
eaGch;Ssh!ape cGo;nSsttarakienst adnefiasnsiitgionnmaetnetac,hannoddreetguirvnesnthe, ai.ses.ig(TnmGe;Snt(ob))ta(isn;evd)b=y eJvaslKuva;tGin;g
for each s and v. So from the definition of graph validation given in Section 2, hG; S;
s0; v0i is valid iff TG;S admits a fixed-point verifying (s; v) = 1. We also need the
Algorithm 1 VALIDATION PROCEDURE FOR STRICTLY STRATIFIED SHAPES
Input: G; S; s0; v0
1: Initiate with (s; v) = 0:5, for each shape s and node v
2: repeat
3: 0
4: TG;S( )
5: until = 0
6: if (s0; v0) = 0 then return Invalid
7: else return Valid
partial order over G;S , defined by 1 2 iff 1(s; v) = 0 implies 2(s; v) = 0,
and 1(s; v) = 1 implies 2(s; v) = 1, for any s and v.</p>
      <p>
        Next, it is shown in [
        <xref ref-type="bibr" rid="ref3">3</xref>
        ] that TG;S must admit a unique minimal fixed-point minFix
w.r.t over G;S , and that minFix can be reached by recursive applications of TG;S ,
starting with the empty assignment. Finally, TG;S is monotone w.r.t. , which guarantees
that minFix can be computed in polynomial time. So if minFix(s0; v0) = 1, because
minFix is a fixed-point of TG;S , the graph is valid. If minFix(s0; v0) = 0, because
minFix is a minimal fixed-point of TG;S , any other fixed-point 0 must verify 0(s0;
v0) = 0, therefore the graph is invalid. Finally, for the case minFix(s0; v0) = 0:5, we
showed in [
        <xref ref-type="bibr" rid="ref3">3</xref>
        ] that if S is strictly stratified (thus regardless of G), then G;S must contain
a fixed-point 00 of TG;S s.t. 00(s0; v0) = 1. The corresponding validation procedure is
shown in Algorithm 1.
4 Discussion and Future Work
As a possible continuation, we observe that strict stratification is only a sufficient condition
for tractability. This means that the requirement may be relaxed, identifying a wider class
of instances which can be validated in polynomial time. Our preliminary investigations
indicate that additional properties of the dependency graph may be used, such as odd/even
number of negative references in a path, or morphisms between multiple paths from one
node to another.
      </p>
      <p>We are also currently developing implementation techniques for validation based on
logic programming. More exactly, since validation is based on the the existence of a
fixed-point evaluation/assignment, we are investigating an encoding into Datalog for
the strictly stratified case, and into to more expressive logic formalisms for non-strictly
stratified constraints.</p>
      <p>Acknowledgments. This work was supported by the QUEST, QUADRO and
ADVANCE4KG projects at the Free University of Bozen-Bolzano.</p>
    </sec>
  </body>
  <back>
    <ref-list>
      <ref id="ref1">
        <mixed-citation>
          [1]
          <string-name>
            <given-names>M.</given-names>
            <surname>Arenas</surname>
          </string-name>
          ,
          <string-name>
            <given-names>C.</given-names>
            <surname>Gutierrez</surname>
          </string-name>
          , and
          <string-name>
            <given-names>J.</given-names>
            <surname>Pérez</surname>
          </string-name>
          .
          <article-title>Foundations of RDF databases</article-title>
          .
          <source>In Reasoning Web International Summer School</source>
          , pages
          <fpage>158</fpage>
          -
          <lpage>204</lpage>
          . Springer,
          <year>2009</year>
          .
        </mixed-citation>
      </ref>
      <ref id="ref2">
        <mixed-citation>
          [2]
          <string-name>
            <given-names>J.</given-names>
            <surname>Corman</surname>
          </string-name>
          ,
          <string-name>
            <given-names>J. L.</given-names>
            <surname>Reutter</surname>
          </string-name>
          , and
          <string-name>
            <given-names>O.</given-names>
            <surname>Savkovic</surname>
          </string-name>
          <article-title>´. Semantics and Validation of Recursive SHACL</article-title>
          .
          <string-name>
            <surname>In</surname>
            <given-names>ISWC</given-names>
          </string-name>
          ,
          <year>2018</year>
          .
        </mixed-citation>
      </ref>
      <ref id="ref3">
        <mixed-citation>
          [3]
          <string-name>
            <given-names>J.</given-names>
            <surname>Corman</surname>
          </string-name>
          ,
          <string-name>
            <given-names>J. L.</given-names>
            <surname>Reutter</surname>
          </string-name>
          , and
          <string-name>
            <given-names>O.</given-names>
            <surname>Savkovic</surname>
          </string-name>
          <article-title>´. Semantics and Validation of Recursive SHACL</article-title>
          .
          <source>Technical Report KRDB18-1</source>
          , Free University of Bozen-Bolzano,
          <year>2018</year>
          . Available at https: //www.inf.unibz.it/krdb/KRDB%20files/tech-reports/
          <fpage>KRDB18</fpage>
          -01.pdf.
        </mixed-citation>
      </ref>
    </ref-list>
  </back>
</article>