- From: James Hudson <jameshudson3010@gmail.com>
- Date: Mon, 13 Apr 2020 09:02:32 -0400
- To: Irene Polikoff <irene@topquadrant.com>
- Cc: Public Shacl W3C <public-shacl@w3.org>
- Message-ID: <CAEUVO9G7uRMUF-bqUqV3_eeegF4xqN8uzV-k2PB+Vyf3TmeueA@mail.gmail.com>
Hello Irene,
Thank you for helping me to understand how to use SPARQL. I now understand
better what Holger was saying in his comment in the SO answer.
I am still missing something about how to make use of this knowledge
however.
Using the SHACL Playground, let's say that I have the following Data Graph:
@prefix hr: <http://learningsparql.com/ns/humanResources#> .
@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .
@prefix xml: <http://www.w3.org/XML/1998/namespace> .
@prefix xsd: <http://www.w3.org/2001/XMLSchema#> .
hr:Employee a rdfs:Class .
hr:BadThree rdfs:comment "some comment about missing" .
hr:BadTwo a hr:BadOne .
hr:YetAnother a hr:Another .
hr:YetAnotherName a hr:AnotherName .
hr:Another a hr:Employee .
hr:AnotherName a hr:name .
hr:BadOne a hr:Dangling .
hr:name a rdf:Property .
and the following Shapes Graph:
@prefix hr: <http://learningsparql.com/ns/humanResources#> .
@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .
@prefix xml: <http://www.w3.org/XML/1998/namespace> .
@prefix xsd: <http://www.w3.org/2001/XMLSchema#> .
@prefix schema: <http://schema.org/> .
@prefix sh: <http://www.w3.org/ns/shacl#> .
schema:SchemaShape
a sh:NodeShape ;
sh:target [
a sh:SPARQLTarget ;
sh:prefixes hr: ;
sh:select """
SELECT ?this
WHERE {
?this ?p ?o .
}
""" ;
] ;
sh:property [
sh:path rdf:type ;
sh:nodeKind sh:IRI ;
sh:hasValue rdfs:Class
] ;
.
What I think should happen is the SPARQL based target should select every
subject in the Data Graph and then verify that there is a path of rdf:type
which has a value of rdfs:Class.
However, the https://shacl.org/playground/ reports no validation errors.
The expected validation errors should include the following subjects:
| <http://learningsparql.com/ns/humanResources#BadOne> |
| <http://learningsparql.com/ns/humanResources#BadTwo> |
| <http://learningsparql.com/ns/humanResources#BadThree> |
| <http://learningsparql.com/ns/humanResources#AnotherName> |
| <http://learningsparql.com/ns/humanResources#name> |
| <http://learningsparql.com/ns/humanResources#YetAnotherName> |
What am I missing?
Regards,
James
On Fri, Apr 10, 2020 at 10:51 PM Irene Polikoff <irene@topquadrant.com>
wrote:
> Hi James,
>
> You can use SPARQL query to target anything you want - as shown in the
> example here https://w3c.github.io/shacl/shacl-af/#SPARQLTarget.
>
> Strictly speaking, your query would not do it. It will not catch something
> like this:
>
> ex:R1 ex:p ex:R2
>
> Where there are no triples with ex:R2 or ex:p as subjects.
>
> On Apr 10, 2020, at 9:43 PM, James Hudson <jameshudson3010@gmail.com>
> wrote:
>
> Hello Irene,
>
> You are correct, it does not. That was an error on my part, I missed that
> it does not also include all the results returned by
>
> SELECT DISTINCT ?s
> WHERE {
> {
> ?s ?p ?o .
> FILTER NOT EXISTS {
> ?s a ?c .
> FILTER(?c IN (rdfs:Class, rdf:Property))
> }
> }
> }
>
>
> If I understand your comment correction regarding the SHACL Advanced
> Features, SHACL is capable of performing the validation check?
>
> I would love to see how that would be written...
>
> Regards,
> James
>
>
> On Fri, Apr 10, 2020 at 5:08 PM Irene Polikoff <irene@topquadrant.com>
> wrote:
>
>> How does your query find resources that have no type?
>>
>> As for ensuring that the type in either a class or a property, you could
>> for example do the following:
>>
>> ex:Shape1 a sh:NodeShape;
>> sh:targetSubjectsOf rdf:type;
>> sh:or (
>> [
>> sh:path rdf:type ;
>> sh:class rdfs:Class ;
>> ]
>> [
>> sh:path rdf:type ;
>> sh:class rdf:Property ;
>> ]
>> ) .
>>
>> Btw, SHACL Advanced Features supports SPARQL-based targets
>> https://w3c.github.io/shacl/shacl-af/.
>>
>> On Apr 10, 2020, at 4:21 PM, James Hudson <jameshudson3010@gmail.com>
>> wrote:
>>
>> Hello,
>>
>> I asked a question on SO (
>> https://stackoverflow.com/questions/60993789/targeting-all-nodes-for-validation
>> ) regarding how to verify that every node in my graph had a rdf:type and
>> that the type was ultimately either a rdfs:Class or rdf:Property. The
>> response I received was that it was impossible with SHACL because:
>>
>> The problem is that none of the four built-in target types is sufficient
>> to reach all subject/objects regardless of predicate.
>>
>> I was just wondering why such a target type does not exist or if there
>> were plans to include such a target type in the future...?
>>
>> I was able to do what I needed to do with SPARQL with the following query:
>>
>> {
>> ?s rdf:type+ ?o .
>> FILTER NOT EXISTS {
>> ?s rdf:type+ ?c .
>> FILTER(?c IN (rdfs:Class, rdf:Property))
>> }
>> }
>>
>> but, I would have preferred to use SHACL.
>>
>> Regards,
>> James
>>
>>
>>
>
Received on Monday, 13 April 2020 13:02:57 UTC