- From: Irene Polikoff <irene@topquadrant.com>
- Date: Fri, 1 Dec 2017 19:36:10 -0500
- To: Florian Kleedorfer <florian.kleedorfer@austria.fm>
- Cc: Holger Knublauch <holger@topquadrant.com>, public-rdf-shapes@w3.org
- Message-Id: <CACB9F0D-B04A-42ED-8D26-D3F4821B878B@topquadrant.com>
Florian, I think for the purpose of isolating resources that pass validation, you just need to remove nodes that have violations i.e., the following will do the job: filter not exists { ?res a sh:ValidationResult ; sh:focusNode ?node ;} You don’t really to figure out what shape or constraint component it violates. If something is in the violation report, there is an issue with it. The fact that the violation exists because there is a sh:ClosedConstraintComponent, is no different from anything else. Unless, for your purposes, you want to treat violations that are the result of closing a shape differently from others. I also believe that, in a general case, handling of paths would still be required - otherwise how do you get the focus nodes for the shapes that are referenced through sh:node? Yes, these shapes could have target statements of their own, but a)these targets are not required; b)these target statements are disregarded when processed in the context of sh:node - this processing only focuses on resources that are reached using whatever is identified in the path. https://www.w3.org/TR/shacl/#NodeConstraintComponent <https://www.w3.org/TR/shacl/#NodeConstraintComponent> If you have a way to limit what you will support, you could say that for your system and use cases every shape referred to by sh:node must have a target and these targets have to include any focus notes that would be computed through sh:node statements referring to them. In other words, if you say :Person a sh:NodeShape; :Person a owl:Class; :property [ sh:path :birthCountry; sh:node :Country] :Country a a sh:NodeShape :property [ sh:path :CountryCode; sh:datatype xsd:string] and there is data :Person1 :birthCountry :Germany :Germany just became a focus node and it will be checked against :Country shape even though :Country has no target statements. In the context of your system and data and shapes it supports, you may be able to assume/require that :Country will have a target statement that will identify :Germany and any other resource that may be used in your data as the object in {target of :Person :birthCountry ?someObject) triple. Or you could decide that you will only support predicate paths when sh:node is used. If you can’t make such assumptions, then you need to fully handle paths. Irene > On Dec 1, 2017, at 1:36 PM, Florian Kleedorfer <florian.kleedorfer@austria.fm> 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? > > > # 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 . > } 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 . > } > } >
Received on Saturday, 2 December 2017 00:36:38 UTC