Re: ValidationResult for missing data?

On 2/12/2017 4:36, Florian Kleedorfer wrote:
> Hi Holger!
>
> Part 2 of my answer - see below.
>
>>
>> The definitions in the spec only cover the "negative" cases, i.e. what
>> target nodes produce errors. The spec furthermore does not prescribe
>> any algorithm, or whether and how these target nodes even need to be
>> touched upon. The result vocabulary thus also does not include terms
>> for positive results. Since this is likely a common use case, we have
>> defined dash:SuccessResult as a possible term:
>>
>>     http://datashapes.org/dash.html#SuccessResult
>>
>> The algorithm to find these is hopefully straight-forward - just get
>> the set of target nodes for a shape that doesn't show up in the
>> violation report.
>
> After some experimentation, I came up with this SPARQL query to find 
> the triples 'covered' by the shapes, according to the explanation you 
> gave. In the middle there is a quoted part where I tried to account 
> for target nodes being referenced through property paths (just to show 
> the approach). I eventually decided that such nodes do not become part 
> of the shape, though, because when closing the shape, they are 
> reported as ValidationResults. I think we will go with this query for 
> the time being - unless there is something wrong with it?

You'll also want to query for instances of subclasses, e.g.

>
>
> # Query for extracting data based on a SHACL validation resultPath
> #
> # * returns triples that match the shape. Additional triples found
> #   in the data are not returned.
> # * triples that cause errors (ValidationResults) are not returned
>
> prefix dash: <http://datashapes.org/dash#>
> prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
> prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#>
> prefix schema: <http://schema.org/>
> prefix sh: <http://www.w3.org/ns/shacl#>
> prefix xsd: <http://www.w3.org/2001/XMLSchema#>
> prefix sh-ext: <http://www.example.org/shacl-ext#>
> prefix ex: <http://www.example.org/data#>
>
> construct {
>  ?node ?prop ?val .
> } where {
>     ?node ?prop ?val .
>     {
>       select distinct ?target ?shape
>       where {
>         {
>             ?shape sh:targetNode ?target .
>         } union {
>             ?shape sh:targetClass ?class .
>             ?target a ?class .

?target rdf:type/rdfs:subClassOf* ?class .

>         } union {
>             ?class a rdfs:class;
>                    a sh:NodeShape.
>             ?target a ?class .
>             bind (?shape as ?class) .
>         } union {
>             ?shape sh:targetSubjectsOf ?property.
>             ?target ?property ?any.
>         } union {
>             ?shape sh:targetObjectsOf ?property.
>             ?any ?property ?target.
>         }
>       }
>    }
>   {
>     bind (?target as ?node)
>   } union {
>     # handle sh:node references: the referenced node also
>     # becomes a target node
>       ?target ?property ?node .
>     ?shape sh:property ?propShape .
>     ?propShape sh:path ?property .
>     ?propShape sh:node ?otherNodeShape .
> # } union {
> #    # handle property paths: the triples matched by the property path 
> are
> #   # 'covered' by the shape
> #   ## NOTE: such properties do not seem to be
> #   ## part of the shape (they are reported when the shape is closed)
> #   ## so we actually don't need to handle them here... same reasoning
> #    ## is appliccable for all property pair constraints: e.g. object
> #   ## of sh:lessThan does not become part of the shape and is reported
> #   ## when the shape is closed.
> #    ?shape sh:property ?propShape .
> #    ?propShape sh:path ?pathStart .
> #    ?pathStart rdf:rest*/rdf:first ?prop .
> #   ?target (!rdf:noprop)* ?node.
> #    ?target (!rdf:noprop)* ?val.
> #    ?node ?prop ?val.
>   }
>   filter not exists {
>     # filter triples based on any ValidationResult except the two below
>     ?res a sh:ValidationResult ;
>          sh:focusNode ?node ;
>            sh:sourceConstraintComponent ?constraint .
>     filter (?constraint != sh:NodeConstraintComponent &&
>             ?constraint != sh:ClosedConstraintComponent)
>   }
>   filter not exists {
>     # filter triples based on value when a NodeConstraint
>     # (sh:node) is violated
>     ?res a sh:ValidationResult ;
>          sh:sourceConstraintComponent sh:NodeConstraintComponent ;
>          sh:value ?node
>   }
>   filter not exists {
>     # filter triples based on focusNode/resultPath when a closed
>     # (sh:closed) shape is violated
>     ?res a sh:ValidationResult ;
>          sh:focusNode ?node ;
>          sh:resultPath ?prop ;
>            sh:sourceConstraintComponent sh:ClosedConstraintComponent .
>   }
> }

Interesting approach - I was assuming this is executed as part of some 
API that already has this logic implemented, but the SPARQL query can 
work too.

Holger

Received on Friday, 1 December 2017 19:28:33 UTC