zazuko/rdf-validate-shacl

Rules on parent class are not being applied.

gruhnow opened this issue · 6 comments

I created a playground to reproduce the issue here.
Constraints:

@prefix : <http://example.org/ontology#> .
@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .
@prefix owl: <http://www.w3.org/2002/07/owl#> .
@prefix dc: <http://purl.org/dc/elements/1.1/> .
@prefix xsd: <http://www.w3.org/2001/XMLSchema#> .
@prefix sh: <http://www.w3.org/ns/shacl#> .


:hasName a owl:DatatypeProperty ;
    rdfs:domain :Animal ;
    rdfs:range xsd:string ;
    rdfs:label "has name" ;
    rdfs:comment "Specifies the name of an animal.";
.

:Animal a rdfs:Class, sh:NodeShape ;
    rdfs:label "Animal" ;
    rdfs:comment "A general class for all animals." ;
	sh:property [
      rdf:type sh:PropertyShape ;
      sh:path :hasName ;
      sh:minCount 1 ;
    ] ;
.


:Dog a rdfs:Class, sh:NodeShape ;
    rdfs:subClassOf :Animal ;
    rdfs:label "Dog" ;
    rdfs:comment "A class for all dogs." ;
.

Shapes:

@prefix : <http://example.org/ontology#> .
@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .
@prefix owl: <http://www.w3.org/2002/07/owl#> .
@prefix dc: <http://purl.org/dc/elements/1.1/> .
@prefix vcard: <http://www.w3.org/2006/vcard/ns#> .
@prefix xsd: <http://www.w3.org/2001/XMLSchema#> .
@prefix sh: <http://www.w3.org/ns/shacl#> .

:Buddy a :Dog ;
#    :hasName "Buddy" ;
    :hasVaccinationStatus true .

Based on @HolgerKnublauch 's comments here I'd expect constraint validation to fail because Buddy does not have a name which is required by the animal class. Am I missing something?

Thank you for reporting. I would have to look at the code to confirm but I think we may not currently implement sub classes.

(You did forget :Mammal rdfs:subClassOf :Animal but it does not change the outcome)

@tpluscode Nice catch! I simplified my example for the issue, but broke it in the process. I've updated the link to a fixed example.

I'll have to dig more since I'm not familiar with the code base, but it looks like getInstances calls getInstancesOf which is supposed to collect sub classes.

the triple :Dog rdfs:subClassOf :Animal . should be in the data graph. See also w3c/data-shapes#155

Thanks @giacomociti for pointing that out. With this change, the playground example indeed works

I suppose we should close this issue then, lest we intend to deviate from the spec

Thank you for the clarification @giacomociti! Closing.