a SHACL specification based on SPARQL

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Here is the core of what I think a SHACL specification based on SPARQL
should look like.

peter




  SHACL Specification


Preliminaries

Throughout the text of this document IRIs are written in CURIE form using
the following prefixes:
rdf = ...
rdfs = ...
xsd = ...
shacl = ...


The SHACL Core Constraint Language

SHACL is based on the SPARQL 1.1 Query Language.  In SHACL, certain results
of the evaluation of SPARQL 1.1 Query Language queries (hereafter SPARQL
queries) on an RDF graph or dataset under the RDFS entailment regime are
interpreted as constraint violations.

The different kinds of results for SPARQL queries require different ways of
interpreting results in SHACL.  For a SELECT query, each separate mapping is
interpreted as a separate violation of the constraint.  If there are no
mappings then the constraint is not violated.  For a CONSTRUCT query, each
RDFS instance of shacl:violation (node whose denotation is in the class
extension of shacl:violation in all RDFS models of the constructed graph) is
a separate violation of the constraint.  If there are no RDFS instances of
shacl:violation in the constructed graph then the constraint is not
violated.  For an ASK query, a true result is interpreted as a violation and
a false result is interpreted as not a violation.  (This interpretation
makes ASK constraints similar to the other kinds of constraints.)  DESCRIBE
queries are not used in SHACL.


The SHACL Control Language

SHACL constraints can be directly evaluated, just as SPARQL queries are.
All that is needed is a SHACL constraint and an RDF graph or dataset.  The
result of the constraint is the result of the query, and is interpreted as
above.

SHACL constraints can also be encoded and collected in RDF graphs.  Each
node in such a graph that is an RDFS instance of shacl:Constraint is the
control node of a SHACL constraint.  A SHACL engine evaluates the
constraints in an RDF graph by taking each such node and evaluating the
node's constraint against an RDF graph or dataset.

SHACL control nodes can also have a shacl:severity link to one or more of
shacl:fatal, shacl:warning, or shacl:informative, indicating the severity of
any violations of the constraint.

The SHACL Core Control Language

The simplest kind of SHACL control node is a node linked via a
shacl:constraint triple to a SPARQL constraint encoded as an RDF string
literal.  These nodes are called SHACL Core Control Nodes.

The SHACL Extended Control Language

Other SHACL control nodes allow the separation of a constraint into three
sections: a scope section, a shape section, and a reporting section.  These
SHACL control nodes, called SHACL Extended Control Nodes, must have
precisely one of the ways below of specifying the scope and the shape, at
most one way of specifying reporting, and at most one way of specifying
severity.

The scope of a SHACL constraint is specified via
1/ a shacl:individualScope link to an IRI literal,
2/ a shacl:classScope link to an IRI literal,
3/ a shacl:shapeScope link to a SHACL shape (see below), or
4/ a shacl:constraintScope link to a string literal.

The shape of a SHACL constraint is specified via
1/ a shacl:shape link to a SHACL shape (see below), or
2/ a shacl:constraint link to a string literal.

The reporting for a SHACL constraint is specified via
1/ a shacl:report link to a string literal.

These kinds of SHACL control nodes are handled by first constructing three
parts of the SHACL constraint.
1/ The control portion of the constraint, <control>, is
   a/ VALUES ?this { <IRI> }
      for a shacl:individualScope link to "<IRI>"^^xsd:anyURI
   b/ ?this rdf:type <IRI> .
      for a shacl:classScope link to "<IRI>"^^xsd:anyURI
   c/ <shape>
      for a shacl:shapeScope link to a node that encodes <shape> (see below)
   d/ <query>
      for a shacl:queryScope link to "<query>"^^xsd:string
2/ The shape portion of the constraint, <shape>, is
   a/ <shape>
      for a shacl:shape link to a node that encodes <shape> (see below)
   b/ <query>
      for a shacl:query link to the string "<query>"^^xsd:string
3/ The reporting portion of the constraint, <report>, is
   a/ SELECT ?this
      when there is no shacl:report link
   b/ <report>
      for a shacl:report link to "<report>"^^xsd:string

The constraint for a SHACL Extended Control Node is then constructed as

  PREFIX rdf: ...
  PREFIX rdfs: ...
  PREFIX xsd: ...
  PREFIX shacl: ...
  <report> WHERE
  { <control> MINUS { <shape> } }


SHACL Simple Shape Language

SHACL provides a vocabulary for generating the shape portion of constraints.
In conjunction with the SHACL Extended Control Language this vocabulary
permits the construction of many, but not all, constraints without needing
to write SPARQL queries.

A SHACL shape node is a node that is an RDFS instance of shacl:Shape.  Each
SHACL shape encodes some SPARQL syntax, their shape, that can be used in
SHACL constraints.

Many SHACL shapes utilize an RDF property.  This property is specified by a
shacl:property link to an IRI literal.

A SHACL property shape with a shacl:valueType link to an IRI literal limits
the values of a property to be RDFS instances of a class.  The shape by a
SHACL property node with a shacl:property link to "<property>"^^xsd:anyURI
and a shacl:valueType link to "<valueType>"^^xsd:anyURI is
  FILTER NOT EXISTS { ?this <property> V .
               FILTER NOT EXISTS { V rdf:type <valueType> . } }
where V is a fresh variable.

... add other high-level-language constructs here ...


SHACL Errors

If a node in an RDF graph is both a core control node and an extended
control node the result of evaluating the graph is undefined.  If a node in
an RDF graph that is an RDFS instance of shacl:constraint is neither a SHACL
Core Control Node nor a SHACL Extended Control Node the result of evaluating
the graph is undefined.  If a SHACL shape node in an RDF graph encodes more
than shape then the result of evaluating the graph is undefined.  SHACL
engines should signal an error on such graphs.

If evaluation of a constraint would produce a SPARQL error the constraint is
invalid.  SHACL engines should signal an error for that constraint.
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1

iQEcBAEBAgAGBQJU9fdOAAoJECjN6+QThfjzCxIIAKVyBK6lu1wQu9r9yDDffoS8
jd0HYzb8OoqvrHhNCS6snvnF/y4C1DVgtI+xUkSsd0wyt1s+JaKrvSRnB7LQ+pPW
Qoi5wiCHUyMEmObgQHRHPCrNwzQX3wPAKD3mtTWu0OX/GlV+qAfy6hGCPLxiYLnh
pTokHfIy5/mBFsIUG7HQJCUNric8iM10R8VCcKkB0qRo2fcEcKN4XbPgTlYQNDM1
rT3l3WkEICCj59i5IcuX+R202a8XiJPM+RCA/EEsVajS1kjK2uO26I2/zCs4Rpjn
fvO/poHaV+wMhOspUNQI3zxiFVWkYrYge1aoEl3a0hRnslrzEJOyv7aYRCFS83I=
=yYam
-----END PGP SIGNATURE-----

Received on Tuesday, 3 March 2015 18:03:26 UTC