RDFLib / pySHACL

A Python validator for SHACL
Apache License 2.0
241 stars 63 forks source link

sh:datatype in sh:PropertyShape #181

Closed sennierer closed 1 year ago

sennierer commented 1 year ago

I created a shacl file from a ttl and try to adopt it now to our needs, but datatype validation in PropertyShapes seems to not work. triples:

<http://www.intavia.eu/apis/birth/timespan/26697> a crm:E52_Time-Span ;
    rdfs:label "1776 - 1847" ;
    crm:P81a_end_of_the_begin "1776-12-31T23:59:59"^^xsd:dateTime ;
    crm:P82a_begin_of_the_begin "1776-01-01T00:00:00"^^xsd:dateTime .

and the following shacl definition:

ex:crm_P82a_begin_of_the_begin a sh:PropertyShape ;
    sh:nodeKind sh:Literal ;
    sh:or (
          [sh:datatype xsd:date]
          [sh:datatype xsd:gYear]
     ) ;
    sh:path crm:P82a_begin_of_the_begin .

Shouldnt there be a violation in the report that P82a didnt use the correct xsd:datatype? Or am I doing something wrong?

ajnelson-nist commented 1 year ago

Hi @sennierer ,

I noticed your shape doesn't have a targeting clause, so it won't apply to anything. (This is a permitted implementation style, though not useful yet in your case. Target-less shapes can be incorporated into other shapes with sh:node or sh:property, but otherwise wouldn't be flagged as an error by the SHACL-SHACL validation check (--metashacl flag).)

If you add the triple ex:crm_P82a_begin_of_the_begin sh:targetClass crm:E52_Time-Span . it should work as you expect. I saw that raise the error you were trying to trigger:

$ pyshacl --shacl shapes.ttl data.ttl
Validation Report
Conforms: False
Results (1):
Constraint Violation in OrConstraintComponent (http://www.w3.org/ns/shacl#OrConstraintComponent):
    Severity: sh:Violation
    Source Shape: ex:crm_P82a_begin_of_the_begin
    Focus Node: <http://www.intavia.eu/apis/birth/timespan/26697>
    Value Node: Literal("1776-01-01T00:00:00" = 1776-01-01 00:00:00, datatype=xsd:dateTime)
    Result Path: crm:P82a_begin_of_the_begin
    Message: Node Literal("1776-01-01T00:00:00" = 1776-01-01 00:00:00, datatype=xsd:dateTime) does not conform to one or more shapes in [ sh:datatype xsd:date ] , [ sh:datatype xsd:gYear ]
sennierer commented 1 year ago

Dear @ajnelson-nist ! Thanks very much for the quick help! That did the trick!