Search code examples
shacl

SHACL validate existing domain and range definitions?


I want to validate the existing rdfs:domain and rdfs:range statements of an existing ontology and knowledge base with SHACL. However it seems like it is extremely verbose to do that with SHACL.

Existing Definition

:prop1 a owl:ObjectProperty ;
  rdfs:domain :A ;
  rdfs:range :B .

In SHACL

:AShape a sh:NodeShape ;
 sh:targetClass :A ;
 sh:property [sh:path :prop1] ;
 sh:closed true .

:ADomainShape a sh:NodeShape ;
 sh:targetSubjectsOf :prop1 ;
 sh:class :A .

:prop1RangeShape a sh:NodeShape ;
 sh:targetObjectsOf :prop1 ;
 sh:class :B .

When you have dozens of properties, this adds a large amount of ceremony over something that is already declared in the original domain and range statements. While it is possible to speed up the process using a script or a multi-line editor, it still seems unnecessary to me. Is there a way to tell a SHACL validator like PySHACL to just validate the existing domain and range statements without requiring all those extra triples?


Solution

  • Let me start by saying that rdfs:domain and rdfs:range are not constraints and don't mean what you imply. They are merely producing inferences. Having said this, many people have in the past used them to "mean" constraints simply because there was no other modeling language. For background, see

    https://www.topquadrant.com/owl-blog/

    If you don't want to duplicate the RDFS triples as individual SHACL constraints, you can write a single generic SHACL shape that has sh:targetSubjectsOf rdfs:domain (and range) and then uses a SPARQL constraint to check that there is no instance of a class other than the domain class that has values for the given property. The end result would be that all rdfs:domain statements would be checked at once.

    But arguably RDFS should be left alone. If you want to use closed-world semantics you should use a language that has been designed for that purpose, i.e. SHACL.

    (BTW there is a Discord group in case you want a higher bandwidth to discuss such things https://twitter.com/HolgerKnublauch/status/1461590465304662019)