veleda / shacl-wiki

Open repository for gathering issues connected to SHACL Wiki.
https://kvistgaard.github.io/shacl/
2 stars 0 forks source link

About inheritance #6

Open EmidioStani opened 1 year ago

EmidioStani commented 1 year ago

I believe an important point is the inheritance of SHACL shapes via rdfs:subClassOf relation, allowing validation of instances of sub-models.

Related to the inheritance, the use of sh:deactivated, would allow to put off inherited shapes (if the PropertyShapes are expressed with a URI).

veleda commented 1 year ago

Hi, @EmidioStani ! Can you please elaborate? I'm curious how your trail of thought here relates to sh:node.

EmidioStani commented 11 months ago

Hello, sorry to come back now Imagine you data graph is:

'''@prefix ex: http://example.org/ns# . @prefix rdf: http://www.w3.org/1999/02/22-rdf-syntax-ns# . @prefix rdfs: http://www.w3.org/2000/01/rdf-schema# . @prefix schema: http://schema.org/ . @prefix xsd: http://www.w3.org/2001/XMLSchema# .

ex:Bob a schema:Person ; schema:givenName "Robert" ; schema:givenName "John" .

schema:Person rdfs:subClassOf ex:Person . '''

And your shapes are:

'''@prefix dash: http://datashapes.org/dash# . @prefix rdf: http://www.w3.org/1999/02/22-rdf-syntax-ns# . @prefix rdfs: http://www.w3.org/2000/01/rdf-schema# . @prefix schema: http://schema.org/ . @prefix sh: http://www.w3.org/ns/shacl# . @prefix xsd: http://www.w3.org/2001/XMLSchema# . @prefix ex: http://example.org/ns# .

ex:PersonShape a sh:NodeShape ; sh:targetClass ex:Person ; sh:property [ sh:path schema:givenName ; sh:maxCount 1; ] .

schema:PersonShape a sh:NodeShape ; sh:targetClass schema:Person ; sh:property [ sh:path schema:givenName ; sh:maxCount 2 ; ] . '''

Here the shapes differs on the cardinality and shacl generates a violation because ex:Bob is also an ex:Person. Now a data modeller of "schema" fixed the meaning of subclass but wants more freedom on the cardinality on the property givenName. The data modeller of "ex" could allow flexibility on the cardinality by naming the property shape (that you already mentioned to be a good practice) so that the shape could be deactivated, see example below:

ex:PersonShape a sh:NodeShape ; sh:targetClass ex:Person ; sh:property sh:MyProp .

sh:MyProp a sh:PropertyShape ; sh:path schema:givenName ; sh:maxCount 1 .

schema:PersonShape a sh:NodeShape ; sh:targetClass ex:Person .

sh:MyProp sh:deactivated true .

The more a property shape is granular the better it is.