w3c / data-shapes

RDF Data Shapes WG repo
87 stars 33 forks source link

Expressing equality between multiple paths #119

Open mthl opened 4 years ago

mthl commented 4 years ago

Hello,

I am trying to express the equality between two nested values inside property paths connected with one specific property http:resp, but fail to express it in SHACL as shown in the following snippets:

Here is the shapes graph I wrote

@prefix cnt: <http://www.w3.org/2011/content#>
@prefix sh: <http://www.w3.org/ns/shacl#>
@prefix xsd: <http://www.w3.org/2001/XMLSchema#>
@prefix ex: <http://example.com/ns#>
@prefix http: <http://www.w3.org/2011/http#>.

ex:simpleEquality a sh:PropertyShape;
    sh:path (http:resp ex:foo);
    sh:equals ex:foo.

ex:nestedEquality a sh:PropertyShape;
    sh:path (http:resp http:body cnt:isFormatOf cnt:chars);
    sh:equals (http:body cnt:isFormatOf cnt:chars).

ex:HttpEchoRequestShape a sh:NodeShape;
    sh:targetClass http:request;
    sh:property ex:simpleEquality;
    sh:property ex:nestedEquality.

and the following data graph

@prefix sh: <http://www.w3.org/ns/shacl#>
@prefix xsd: <http://www.w3.org/2001/XMLSchema#>
@prefix ex: <http://example.com/ns#>
@prefix http: <http://www.w3.org/2011/http#>.
@prefix cnt: <http://www.w3.org/2011/content#>

ex:req a http:request;
    ex:foo "bar";
    http:resp ex:res;
    http:body [
        a cnt:ContentAsBase64;
        cnt:isFormatOf [
            a cnt:ContentAsText;
            cnt:chars "x"
            ]].

ex:res a http:response;
    ex:foo "bar";
    http:body [
        a cnt:ContentAsBase64;
        cnt:isFormatOf [
            a cnt:ContentAsText;
            cnt:chars "x"
            ]].

with SHACL reference implementation (1.3.1-SNAPSHOT) I get the following report

@prefix ex:    <http://example.com/ns#> .
@prefix owl:   <http://www.w3.org/2002/07/owl#> .
@prefix rdf:   <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
@prefix sh:    <http://www.w3.org/ns/shacl#> .
@prefix xsd:   <http://www.w3.org/2001/XMLSchema#> .
@prefix cnt:   <http://www.w3.org/2011/content#> .
@prefix http:  <http://www.w3.org/2011/http#> .
@prefix rdfs:  <http://www.w3.org/2000/01/rdf-schema#> .

[ a            sh:ValidationReport ;
  sh:conforms  false ;
  sh:result    [ a                             sh:ValidationResult ;
                 sh:focusNode                  ex:req ;
                 sh:resultMessage              "Does not have value at property [http:body, cnt:isFormatOf, cnt:chars]" ;
                 sh:resultPath                 ( http:resp http:body cnt:isFormatOf cnt:chars ) ;
                 sh:resultSeverity             sh:Violation ;
                 sh:sourceConstraintComponent  sh:EqualsConstraintComponent ;
                 sh:sourceShape                ex:nestedEquality ;
                 sh:value                      "x"
               ]
] .

which means that it is not possible to use a SHACL property path as the range of the sh:equals property. Is there a way to express an equivalent constraint in SHACL?

Would it make sense for the sh:equals property to have the same range definition than sh:path?

Thanks

HolgerKnublauch commented 4 years ago

The spec requires sh:equals to be IRI properties, i.e. paths are not supported. See "The values of sh:equals in a shape are IRIs." at

https://www.w3.org/TR/shacl/#EqualsConstraintComponent

To express such cases you'd need to revert to SHACL-SPARQL.

mthl commented 4 years ago

Thanks for your explanation, that was my understanding of the standard too. I will try to use SHACL-SPARQL then.

I am not familiar with the W3C process for proposing an evolution of the spec, but is there a chance that the working group could consider adding this “feature”? If yes what can I do to help?

HolgerKnublauch commented 4 years ago

If you are after some free-flowing discussion related to SHACL then the official place is (the mailing list of) https://www.w3.org/community/shacl/

Other than that, I believe we can leave this ticket here open as a feature request or placeholder for future consideration.

mthl commented 4 years ago

I have subscribed to the public-shacl@w3.org mailing-list, thanks.