@prefix owl: <http://www.w3.org/2002/07/owl#> .
@prefix qudt: <http://qudt.org/schema/qudt/> .
@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .
@prefix sh: <http://www.w3.org/ns/shacl#> .

qudt:DimensionalityShape a owl:Class,
        sh:NodeShape ;
    rdfs:label "Dimensions Shape" ;
    rdfs:isDefinedBy <http://qudt.org/3.2.0/schema/datatype>,
        <http://qudt.org/3.2.0/schema/shacl/datatype> ;
    sh:severity sh:Warning ;
    sh:sparql [ sh:message "\"{$this}\" has {$actualDimensions} dimensions extent and needs to have {$specifiedDimensions}" ;
            sh:prefixes <http://qudt.org/3.2.0/schema/shacl/datatype> ;
            sh:select """
        SELECT $this $actualDimensions $specifiedDimensions
        WHERE {
            $this qudt:dimensionality $dimensionality .
            $this qudt:dimensions ?dimensions .
            ?dimensions rdf:rest*/rdf:first $specifiedDimensions .
            { SELECT $this (COUNT(?listValue )AS $actualDimensions)
              WHERE {
              $this qudt:value/rdf:rest*/rdf:first ?listValue .
              } GROUP BY $this
            }
            FILTER ($actualDimensions != $specifiedDimensions)
          }
        """ ] ;
    sh:targetClass qudt:Array,
        qudt:List .

