W3C home > Mailing lists > Public > public-shacl@w3.org > September 2018

A question on sh:xone and sh:targetObjectsOf

From: Gary Murphy <gary@schemaapp.com>
Date: Fri, 7 Sep 2018 16:00:05 -0400
Message-ID: <CADnyxpv9SuEzVZqgtc3kH5SYzxRQvM1Ymj3BqbnSymJkG97buQ@mail.gmail.com>
To: "public-shacl@w3.org" <public-shacl@w3.org>
I have a novice question about setting alternatives in a NodeShape using
sh:xone, sh:xor and sh:or

I need to evaluate a property of the targetClass such that, if the node is
targetObjectsOf a property in another node, then a particular property
should not be defined, but if not, then it is -- this pattern occurs
several times in schema.org validation rules.

So for example, here was my naive attempt using sh:xone but also with
sh:xor and sh:or ...

hmshape:AggregateRatingShape
    a sh:NodeShape ;
    sh:targetClass schema:AggregateRating ;
    sh:property [
        sh:xone (
         [
           sh:not [ sh:targetObjectsOf schema:review ] ;
           sh:path schema:itemReviewed ;
           sh:minCount 1 ;
           sh:severity sh:Error ;
         ]
         [
           sh:targetObjectsOf schema:review ;
           sh:path schema:itemReviewed ;
           sh:maxCount 0 ;
           sh:severity sh:Warning ;
         ]
       ) ;
       ] ;
    .


and my graph:

@prefix ex: <http://example.org/ns#> .
@prefix schema: <http://schema.org/> .

ex:Bob
    a schema:Person ;
    schema:review ex:BobsAggregateRating ;
..
ex:BobsAggregateRating
    a schema:AggregateRating ;
    schema:itemReviewed ex:Bob ;
..



   1. When I take the schema:itemReviewed only out of BobsAggregateRating,
   the validations passes for all three xone/xor/or, which is correct.
   2. When I take the schema:review only out of Bob, I
   get sh:sourceConstraintComponent sh:XoneConstraintComponent although I
   expect it to be valid by the first clause; when I use sh:xor it works as
   expected and there is no violation
   3. When I take out both properties, the validation passes with all of
   sh:xone, sh:xor, and sh:or, although I expect a violation for the missing
   schema:itemReviewed as per the first clause
   4. When I leave them both in, I get two violations,
   one sh:MaxCountConstraintComponent warning because of the second clause,
   and, with sh:xone or sh:or, I get one generic sh:Violation because none of
   clauses fit, which is perhaps expected since sh:xone/sh:or only need one
   failure to satisfy, but when I use sh:xor, I just get the one
   sh:MaxCountContraintComponent warning.

Because of (1) and (4) it appears the (sh:not) sh:targetObjectOf is working
as a selector for each rule, but why do the other two cases fail with
sh:xone?  I am testing this using the shacl.org/playground; I also tried
this same pattern using sh:or with the same results.

What am I missing here?  Is this an appropriate use of sh:xone/sh:xor/sh:or
and/or sh:targetObjectOf?  sh:xor gets me three out of the four cases as
expected, but why would it fail (3)?

Any and all guidance is most welcome :)

-- 
*Gary Murphy*
Developer, Schema App
e: gary@schemaapp.com <martha@schemaapp.com>
w: https://www.schemaapp.com
Received on Friday, 7 September 2018 20:09:33 UTC

This archive was generated by hypermail 2.3.1 : Friday, 7 September 2018 20:09:33 UTC