<!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>Towards a Robust Semantics for SHACL: Preliminary Discussion</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 Savković</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>Validating RDF graphs against constraints has gained interest in recent years, due to the popularity of RDF and the growth of knowledge bases. SHACL, a constraint language for RDF, has recently become a W3C recommendation, with a specification detailing syntax, semantics and common use cases. Unfortunately, this (otherwise complete) specification does not cover validation against recursive constraints. This omission is important, because SHACL by design favors constraint references. We investigate the possibility of a formal semantics for SHACL which covers the recursive case, while being compliant with the current standard.</p>
      </abstract>
    </article-meta>
  </front>
  <body>
    <sec id="sec-1">
      <title>-</title>
      <p>Introduction
Recent years have seen an increased interest in standardizing a declarative
constraint language for RDF, and devising mechanisms to detect violations of such
constraints. One of the most promising candidate languages is SHACL, or Shapes
Constraint Language,3 which has become a W3C recommendation in 2017.</p>
      <p>SHACL constraints are grouped in so-called “shapes” to be verified by certain
nodes of the graph under validation, and such that a shape may reference
another. Figure 1 presents two SHACL shapes. The left one, named :AddressShape,
is meant to define valid addresses. A node v satisfying this shape must satisfy
two (nested) constraints: the first one states that there must be at least one
successor (sh:minCount 1) of v via property :telephone, and the second one states
that there must be at most one successor of v via property :postalCode.</p>
      <p>Validating an RDF graph against a set of shapes is based on the notion of
“target nodes”, which mandates for each shape which nodes have to conform to
it. In Figure 1, the right shape contains the triple :PersonShape sh:targetClass
:Person, stating that its target nodes are all nodes of type :Person. Nodes may
have to conform to additional shapes, due to shape references. For example,
the right shape of Figure 1 contains one (non-recursive) shape reference,
stating that every node v conforming to :PersonShape has at most one :address,
which must conform to :AddressShape, and one recursive reference, stating that
each foaf:friend of v must conform to :PersonShape. By recursion, we refer to
(possibly n-ary) shape reference cycles. Unfortunately, the validation of a graph
3 https://www.w3.org/TR/shacl
: AddressShape
a sh : NodeShape ;
sh : p r o p e r t y [
sh : path : t e l e p h o n e ;
sh : minCount 1
] ;
sh : p r o p e r t y [
sh : path : postalCode ;
sh : maxCount 1
] .</p>
      <p>: PersonShape
a sh : NodeShape ;
sh : t a r g e t C l a s s : Person ;
sh : p r o p e r t y [
sh : path : a d d r e s s ;
sh : maxCount 1 ;
sh : node : AddressShape
] ;
sh : p r o p e r t y [
sh : path f o a f : f r i e n d ;
sh : node : PersonShape
] .
against recursive shapes is left explicitly undefined in the SHACL specification.
This is an important limitation for RDF graphs which are not tree-shaped. As
an illustration, in Example 1, the RDF graph G1 is valid w.r.t. the shapes of
Figure 1, whereas G2 is invalid, and the validity of G3 is left unspecified.
Example 1.</p>
      <p>G1 = f:p1 rdf:type :Person ; :address :a2 . :a2 :telephone :t3 .g
G2 = G1 [ f:a2 :postalcode :c4 . :a2 :postalcode :c5 .g
G3 = G1 [ f:p1 foaf:friend :p6 . :p6 foaf:friend :p1 .g</p>
      <p>In this work, we set up the task of defining a robust semantics for graph
validation in SHACL (including circular references), and studying its
computational properties. A report is available online, which reflects the current state of
our investigations: https://www.inf.unibz.it/krdb/KRDB%20files/tech-reports/
KRDB18-01.pdf.</p>
      <p>
        Related Work. Boneva et al. [
        <xref ref-type="bibr" rid="ref1 ref2 ref3 ref7">2, 7, 1, 3</xref>
        ] have embarked on a study of a similar constraint
language for RDF, called Shape Expression Language, or ShEx,4 providing in [
        <xref ref-type="bibr" rid="ref3">3</xref>
        ] an
abstract syntax and semantics. A different abstract language in provided in [
        <xref ref-type="bibr" rid="ref1">1</xref>
        ], which
encodes a common fragment of ShEx and SHACL. In both cases, validating a graph
against a recursive set of shapes is based on the existence of a typing (of nodes with
shape names) verifying constraints and targets, which is also the approach we follow
(with the notion of shape assignment described below). Perhaps the most important
difference with our investigations is that these two studies are restricted to constraints
with stratified negation (in the datalog sense), whereas we consider constraints with
arbitrary negation. Another key difference (in the stratified case) is that the semantics
given in [
        <xref ref-type="bibr" rid="ref3">3</xref>
        ] relies on a specific maximal typing (defined inductively on the constraint’s
strata), which is not the only possible one. We hope that both works may complement
each other, towards an optimal constraint language for RDF.
      </p>
      <p>
        Another related line of work, advocated in [
        <xref ref-type="bibr" rid="ref5">5</xref>
        ] as a semantic grounding for SHACL,
is inspired by Description Logics under closed-world assumption [
        <xref ref-type="bibr" rid="ref8">8</xref>
        ], effectively
reducing graph validation to FO satisfiability with closed (binary) predicates [
        <xref ref-type="bibr" rid="ref6">6</xref>
        ]. But as
illustrated with Example 2, (2-valued) FO satisfiability may not be well-suited for
validating target nodes against non-stratified constraints.
4 http://shex.io/shex-semantics
      </p>
      <p>Validating a graph against recursive constraints
In order to devise a formal semantics, we abstract away from the concrete syntax of
SHACL. For shape constraints, we chose a concise notation inspired by Description
Logics, expressive enough to encode the SHACL “Core Constraint Components” of the
specification. For instance, the constraints in Figure 1 would be translated into two
constraint definitions, one for each shape:</p>
      <p>:
AddressShape = ( 1 telephone:&gt;) ^ ( 1 postalCode:&gt;)
PersonShape =: ( 1 address:&gt;) ^ ( 0 address::AddressShape) ^</p>
      <p>
        ( 0 friend::PersonShape)
The semantics given in the SHACL specification needs to be extended in order to
handle recursive shapes. To this end, we follow the same path as in [
        <xref ref-type="bibr" rid="ref3">3</xref>
        ], and consider the
evaluation of a constraint formula given a shape assignment , which may be intuitively
viewed as labeling nodes of the graph with (sets of) shape names. Then a graph is
valid iff there exists an assignment verifying targets and constraints. For instance, one
may validate graph G3 in Example 1, by assigning :PersonShape to :p1 and :p6, and
:AddressShape to :a2.
      </p>
      <p>How to handle non-stratified constraints? For an input graph G and set S of shapes,
let atoms(G; S) be the set of all atoms of the form s(v) built from shape names in S and
nodes in G. Then a shape assignment may be viewed as a function from atoms(G; S)
to truth values. But should be required to be a total function to ftrue; falseg? Such
semantics may not behave well in the presence of non-stratified negation, as illustrated
in Example 2. The only target node is v1, for shape s1. v1 has an r1-successor (namely
v2) in G, therefore it verifies the left disjunct 1 r1:&gt; of the constraint for s1. So
intuitively, one would want to validate this unique target, and therefore the whole
graph. But s2(v1) cannot be assigned a truth value which complies with the constraint
for s2. If (s2(v1)) = true, then v1 does not verify 1 r2::s2 given . Conversely, if
(s2(v1)) = false, then v1 does not violate 1 r2::s2 given .</p>
      <p>Example 2.</p>
      <p>G =: f(v1; r1; v2); (v1; r2; v1)g
s1 =: ( 1 r1:&gt;) _ ( 1 r2:s2)
s2 = 1 r2::s2
target: v1 for s1</p>
      <p>
        A solution is to allow to be a partial function, or equivalently a total function
from atoms(G; S) to ftrue; unknown; falseg, in order to define constraint evaluation
given . This is a key difference from the approach followed in [
        <xref ref-type="bibr" rid="ref3">3</xref>
        ]. For instance, in
Example 2, the assignment = fs1(v1) 7! true; s2(v1) 7! unknown; s1(v2) 7! false;
s2(v2) 7! falseg could be used to validate the graph. Such 3-valued semantics should
still comply with the SHACL specification in the non-recursive case though, which may
not be trivial for constraints with counting.
      </p>
      <p>
        How to define partial validation? The SHACL specification describes a graph
validation mechanism (for non-recursive shapes) which starts from a target atom, and
propagates the constraints required by this target only. One way to generalize this
approach to recursive shapes is to allow assigning unknown to an atom, even though
the corresponding constraint evaluates to true or false. For instance, in Example 2,
assigning a truth value to s1(v2) and s2(v2) seems unnecessary for the (unique)
target under validation. So could one also validate the graph with another assignment
0 = fs1(v1) 7! true; s2(v1) 7! unknown; s1(v2) 7! unknown; s2(v2) 7! unknowng, even
though s1(v2) and s2(v2) evaluate to false given 0? And in which cases (if any) do
these two semantics differ?
Is validation scalable? Our investigations so far indicate that graph validation
under such requirements is intractable in data complexity (i.e. when the constraints are
assumed to be fixed), even for constraints with stratified negation, as opposed to
seemingly comparable frameworks, such as stratified datalog [
        <xref ref-type="bibr" rid="ref4">4</xref>
        ]. To overcome this
limitation, we are currently investigating two options: tractable fragments of the constraint
language on the one hand, and approximation algorithms on the other hand.
Acknowledgements. This work was supported by the QUEST, ROBAST and OBATS
projects at the Free University of Bozen-Bolzano, and the Millenium Institute for
Foundational Research on Data, Chile.
      </p>
    </sec>
  </body>
  <back>
    <ref-list>
      <ref id="ref1">
        <mixed-citation>
          [1]
          <string-name>
            <given-names>I.</given-names>
            <surname>Boneva</surname>
          </string-name>
          .
          <article-title>Comparative expressiveness of ShEx and SHACL (Early working draft</article-title>
          ),
          <year>2016</year>
          .
        </mixed-citation>
      </ref>
      <ref id="ref2">
        <mixed-citation>
          [2]
          <string-name>
            <given-names>I.</given-names>
            <surname>Boneva</surname>
          </string-name>
          ,
          <string-name>
            <given-names>J. E. L.</given-names>
            <surname>Gayo</surname>
          </string-name>
          ,
          <string-name>
            <given-names>S.</given-names>
            <surname>Hym</surname>
          </string-name>
          ,
          <string-name>
            <surname>E. G.</surname>
          </string-name>
          <article-title>Prud'hommeau</article-title>
          ,
          <string-name>
            <given-names>H. R.</given-names>
            <surname>Solbrig</surname>
          </string-name>
          , and
          <string-name>
            <given-names>S.</given-names>
            <surname>Staworko</surname>
          </string-name>
          .
          <article-title>Validating RDF with shape expressions</article-title>
          .
          <source>CoRR, abs/1404.1270</source>
          ,
          <year>2014</year>
          .
        </mixed-citation>
      </ref>
      <ref id="ref3">
        <mixed-citation>
          [3]
          <string-name>
            <given-names>I.</given-names>
            <surname>Boneva</surname>
          </string-name>
          ,
          <string-name>
            <given-names>J. E. L.</given-names>
            <surname>Gayo</surname>
          </string-name>
          , and
          <string-name>
            <surname>E. G.</surname>
          </string-name>
          <article-title>Prud'hommeaux. Semantics and Validation of Shapes Schemas for RDF</article-title>
          .
          <string-name>
            <surname>In</surname>
            <given-names>ISWC</given-names>
          </string-name>
          ,
          <year>2017</year>
          .
        </mixed-citation>
      </ref>
      <ref id="ref4">
        <mixed-citation>
          [4]
          <string-name>
            <given-names>E.</given-names>
            <surname>Dantsin</surname>
          </string-name>
          ,
          <string-name>
            <given-names>T.</given-names>
            <surname>Eiter</surname>
          </string-name>
          ,
          <string-name>
            <surname>G.</surname>
          </string-name>
          <article-title>Gottlob, and</article-title>
          <string-name>
            <given-names>A.</given-names>
            <surname>Voronkov</surname>
          </string-name>
          .
          <article-title>Complexity and expressive power of logic programming</article-title>
          .
          <source>ACM Comput. Surv.</source>
          ,
          <volume>33</volume>
          (
          <issue>3</issue>
          ):
          <fpage>374</fpage>
          -
          <lpage>425</lpage>
          ,
          <year>2001</year>
          .
        </mixed-citation>
      </ref>
      <ref id="ref5">
        <mixed-citation>
          [5]
          <string-name>
            <given-names>P. F.</given-names>
            <surname>Patel-Schneider</surname>
          </string-name>
          .
          <article-title>Using Description Logics for RDF Constraint Checking and Closed-World Recognition</article-title>
          . In AAAI ,
          <year>2015</year>
          .
        </mixed-citation>
      </ref>
      <ref id="ref6">
        <mixed-citation>
          [6]
          <string-name>
            <given-names>P. F.</given-names>
            <surname>Patel-Schneider</surname>
          </string-name>
          and
          <string-name>
            <surname>E. Franconi.</surname>
          </string-name>
          <article-title>Ontology constraints in incomplete and complete data</article-title>
          .
          <source>In ISWC</source>
          ,
          <year>2012</year>
          .
        </mixed-citation>
      </ref>
      <ref id="ref7">
        <mixed-citation>
          [7]
          <string-name>
            <given-names>S.</given-names>
            <surname>Staworko</surname>
          </string-name>
          ,
          <string-name>
            <surname>I. Boneva</surname>
          </string-name>
          ,
          <string-name>
            <given-names>J. E. Labra</given-names>
            <surname>Gayo</surname>
          </string-name>
          ,
          <string-name>
            <given-names>S.</given-names>
            <surname>Hym</surname>
          </string-name>
          ,
          <string-name>
            <surname>E. G.</surname>
          </string-name>
          <article-title>Prud'hommeaux, and</article-title>
          <string-name>
            <given-names>H.</given-names>
            <surname>Solbrig</surname>
          </string-name>
          .
          <article-title>Complexity and Expressiveness of ShEx for RDF</article-title>
          .
          <string-name>
            <surname>In</surname>
            <given-names>ICDT</given-names>
          </string-name>
          ,
          <year>2015</year>
          .
        </mixed-citation>
      </ref>
      <ref id="ref8">
        <mixed-citation>
          [8]
          <string-name>
            <given-names>J.</given-names>
            <surname>Tao</surname>
          </string-name>
          ,
          <string-name>
            <given-names>E.</given-names>
            <surname>Sirin</surname>
          </string-name>
          ,
          <string-name>
            <given-names>J.</given-names>
            <surname>Bao</surname>
          </string-name>
          , and
          <string-name>
            <given-names>D. L.</given-names>
            <surname>McGuinness</surname>
          </string-name>
          .
          <article-title>Integrity Constraints in OWL</article-title>
          . In AAAI ,
          <year>2010</year>
          .
        </mixed-citation>
      </ref>
    </ref-list>
  </back>
</article>