Sveino / Inst4CIM-KG

Instance of CIM Knowledge Graph
Apache License 2.0
5 stars 1 forks source link

Don't use parasitic `PropertyShape` #16

Open VladimirAlexiev opened 4 months ago

VladimirAlexiev commented 4 months ago

The shape shown in https://github.com/Sveino/Inst4CIM-KG/issues/17 (and many like it) is structured like this:

erc:EnergyComponent  a          sh:NodeShape ;
        sh:property      erc:EnergyComponent-associations;
        sh:targetClass  nc:EnergyComponent .

erc:EnergyComponent-associations
        a               sh:PropertyShape ;
        sh:description  "The EnergyComponent shall be associated with either GeneratingUnit, PowerElecronicsUnit, EnergyConsumer or HydroPump." ;
        sh:sparql       erc:EnergyComponent-associationsSparql ;
        sh:path         rdf:type ;
        sh:group        erc:ERgroup ;
        sh:name         "C:NC:ER:EnergyComponent:associations" ;
        sh:order        2 ;
        sh:severity     sh:Violation .

erc:EnergyComponent-associationsSparql a         sh:SPARQLConstraint ;  
  ...

The PropertyShape is parasitic:

So it should be changed to:

erc:EnergyComponent-associations  a          sh:NodeShape ;
        sh:targetClass  nc:EnergyComponent .
        sh:message "The EnergyComponent shall be associated with either GeneratingUnit, PowerElecronicsUnit, EnergyConsumer or HydroPump." ;
        sh:sparql       erc:EnergyComponent-associationsSparql ;
        sh:name         "C:NC:ER:EnergyComponent:associations" ;
        sh:severity     sh:Violation .

erc:EnergyComponent-associationsSparql a         sh:SPARQLConstraint ;  
  ...

According to https://w3c.github.io/data-shapes/shacl/#constraints-section: sh:name, sh:description, sh:order, sh:group apply only to sh:PropertyShape.

griddigit-ci commented 2 months ago

Here we will need to check all design patterns and describe them. We will also need to see if we change the style depending on the usage and see how this impacts the validation report.

the sh:message was put in sparql part to be able to print variable there using {?x} as part of the message. i am not sure if this would work if the message is in the NodeShape

The pattern to use (at least in most cases) NodeShape, explicit PropertyShape and the SPARQL was to be able to refer to this PropertyShape from multiple nodes and it also brings some more clarity in the validation report. In general W3C is using a lot of blank nodes for the sh:property which was not coming handy in many places

the path rdf:type is an artificial thing as some python validators complained that property shape is missing sh:path. Jena was not having issues with missing sh:path. In that particular case we do not needed as it is not used in the sparql part We need to see how to deal with these nuances and test the patterns in multiple validation engines

VladimirAlexiev commented 2 months ago
VladimirAlexiev commented 2 months ago

We should consider creating new https://www.w3.org/TR/shacl/#sparql-constraint-components because if they are used often, then validator vendor may decide to implement them specially, thus optimizing performance.

griddigit-ci commented 3 weeks ago

I guess this requires to package the issues and have dedicated SHACL discussion