RDFLib / pySHACL

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

Some DASH vocabulary features don't work in PySHACL #144

Open miroli opened 2 years ago

miroli commented 2 years ago

I realize there's a high probability that I've misunderstood something basic here, but I can't seem to make extensions work. Here's a toy example. I expected this to produce a validation result for the ex:author property since it's not declared in either shape, but the DASH rules aren't applied.

data.ttl

PREFIX ex: <http://example.org#>
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>

ex:ElectronicBook
    rdfs:subClassOf ex:Book .

ex:MyElectronicBook a ex:ElectronicBook ;
    ex:numberOfPages 200 ;
    ex:fileSize 3300 ;
    ex:author ex:JohnSmith .

shape.ttl

PREFIX dash: <http://datashapes.org/dash#>
PREFIX ex: <http://example.org#>
PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
PREFIX sh: <http://www.w3.org/ns/shacl#>
PREFIX owl: <http://www.w3.org/2002/07/owl#>

<http://example.org#>
     owl:imports <http://datashapes.org/dash#> .

ex:BookShape
    a sh:NodeShape ;
    sh:targetClass ex:Book ;
    sh:property [
        sh:path ex:numberOfPages ;
        sh:minCount 1
    ] .

ex:ElectronicBookShape
    a sh:NodeShape ;
    sh:targetClass ex:ElectronicBook ;
    dash:closedByTypes true ;
    sh:property
        [
            sh:minCount 1 ;
            sh:path ex:fileSize ;
        ] .

Command:

$ pyshacl -s shape.ttl -m -i rdfs -a -j -f human data.ttl
miroli commented 2 years ago

Oh, so I finally found issue #18 and learned that I had to add a owl:Ontology ; to the importing graph. However, I'm now faced with a new problem. I get this error message when running the same command above with the modified import triple.

Validator feature is not implemented: SPARQL Constraint text has $shapesGraph in it, but Shapes Graph is not currently supported. If your use-case requires this feature, open an Issue on the pyshacl github page.

ashleysommer commented 2 years ago

Hi @miroli Thanks for your issue report.

PySHACL does not officially support the DASH Extensions. It is not part of the original W3C SHACL Standard Specification. It is published as a draft ontology and is subject to change.

Case in point; many DASH features used to work fine in PySHACL, but recently the addition of ClosedByTypesConstraintComponent, a SPARQLValidator definition that uses $shapesGraph querying, that is not supported by PySHACL.

It is possible that DASH will work with PySHACL again in the future (eg, if PySHACL gets the ability to query the $shapesGraph, or if DASH ontology validators change again).

miroli commented 2 years ago

Thanks for taking the time to clear that up!

KeironO commented 2 years ago

I'm working on implementing DASH and SHACL. I'd be interested in writing an 'extension' of some sort for pySHACL to validate, but I have no idea whether the project can support that?

ashleysommer commented 2 years ago

Hi @KeironO Can you please clarify what you are asking? The DASH SHACL Extensions are already implemented in SHACL, that is how they work. PySHACL does support some DASH SHACL Extensions, because they are simply custom SHACL Shapes, there is no need to add extra extension code to PySHACL in order to validate the DASH Extensions (aside from the missing feature for ClosedByTypesConstraintComponent as described above).