Skip to content

Use sh:maxLength/sh:length Instead of SPARQL #112

Description

@VladimirAlexiev

https://github.com/Sveino/Inst4CIM-KG/tree/develop/shacl-improved#use-shmaxlength-instead-of-sparql:
Consider this overcomplicated shape in CGMES-NC/r2.3/ap-con/ttl/NC-AP-Con-Complex-IdentifiedObjecStringLength-SHACL.ttl:

io:IdentifiedObjectStringLength  a sh:NodeShape ;
        sh:property     io:IdentifiedObject.name-stringLength;
        sh:targetNode   cim:IdentifiedObjectStringLength .

io:IdentifiedObject.name-stringLength
        a               sh:PropertyShape ;
        sh:description  "The string IdentifiedObject.name has a maximum of 128 characters." ;
        sh:sparql       io:IdentifiedObject.name-stringLengthSparql ;
        sh:path         rdf:type ;
        sh:group        io:IOstringLength ;
        sh:name         "C:452:ALL:IdentifiedObject.name:stringLength" ;
        sh:order        1 ;
        sh:severity     sh:Violation .

io:IdentifiedObject.name-stringLengthSparql
    a         sh:SPARQLConstraint ;
    sh:message      "String length is greater than 128 characters." ;
    sh:prefixes cim: ;
    sh:select """
      SELECT  $this ?value
      WHERE {
        ?s cim:IdentifiedObject.name ?value
        FILTER (STRLEN(?value)>128) .
      }""" .

We don't need the fake node, the misleading sh:path rdf:type, or in fact any SPARQL. We can target by class or property and simplify it to:

io:IdentifiedObjectStringLength  a          sh:NodeShape ;
        sh:property         io:IdentifiedObject.name-stringLength;
        sh:targetSubjectsOf cim:IdentifiedObject.name .

io:IdentifiedObject.name-stringLength
        a               sh:PropertyShape ;
        sh:description  "The string IdentifiedObject.name has a maximum of 128 characters." ;
        sh:path         cim:IdentifiedObject.name ;
        sh:maxLength    128;
        sh:group        io:IOstringLength ;
        sh:name         "C:452:ALL:IdentifiedObject.name:stringLength" ;
        sh:order        1 ;
        sh:severity     sh:Violation .

@HarisVranaj can you add @nataschake to this repo? She's made a fix and I want to assign to her.

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions