w3c / shacl

SHACL Community Group (Post-REC activitities)
27 stars 4 forks source link

datacube shapes file contains two invalid SHACL-SPARQL subqueries #11

Closed ashleysommer closed 2 years ago

ashleysommer commented 2 years ago

@HolgerKnublauch let me know if this is not the correct place to report this.

Constraints "IC-12" and "IC-17" in shapes/datacube.shapes.ttl both contain Subquery statements that violate a directive from Appendix A: Pre-binding variables in SPARQL. Specifically

Subqueries must return all potentially pre-bound variables, except shapesGraph and currentShape which are optional

The only other "potentiality pre-bound variable" (if you don't define any of your own) is $this. That means all subqueries must SELECT the variable $this. Eg, the SPARQL for rule "IC-12" should be:

SELECT $this
WHERE {
    {
        # For each pair of observations test if all the dimension values are the same
        SELECT $this (MIN(?equal) AS ?allEqual)
        WHERE {
            $this qb:dataSet ?dataset .
            ?obs2 qb:dataSet ?dataset .
            FILTER (?obs1 != ?obs2)
            ?dataset qb:structure/qb:component/qb:componentProperty ?dim .
            ?dim a qb:DimensionProperty .
            $this ?dim ?value1 .
            ?obs2 ?dim ?value2 .
            BIND( ?value1 = ?value2 AS ?equal)
        }
        GROUP BY $this ?obs2
    }
    FILTER( ?allEqual )
}

and "IC-17" should be:

SELECT $this
WHERE {
    {
    # Count number of other measures found at each point
    SELECT $this ?numMeasures (COUNT(?obs2) AS ?count)
    WHERE {
        {
          # Find the DSDs and check how many measures they have
          SELECT $this ?dsd (COUNT(?m) AS ?numMeasures)
          WHERE {
            ?dsd qb:component/qb:componentProperty ?m.
            ?m a qb:MeasureProperty .
          }
          GROUP BY ?dsd
        }
        # Observation in measureType cube
        $this qb:dataSet/qb:structure ?dsd;
            qb:dataSet ?dataset ;
            qb:measureType ?m1 .
        # Other observation at same dimension value
        ?obs2 qb:dataSet ?dataset ;
            qb:measureType ?m2 .
        FILTER NOT EXISTS {
            ?dsd qb:component/qb:componentProperty ?dim .
            FILTER (?dim != qb:measureType)
            ?dim a qb:DimensionProperty .
            $this ?dim ?v1 .
            ?obs2 ?dim ?v2.
            FILTER (?v1 != ?v2)
        }
    }
    GROUP BY $this ?numMeasures
    HAVING (?count != ?numMeasures)
    }
}
ashleysommer commented 2 years ago

It was pointed out to me by someone else, constraint "IC-17" has another bug: FILTER (?obs1 != ?obs2) should be FILTER ($this != ?obs2).

HolgerKnublauch commented 2 years ago

Thanks, this file was outdated to what we had meanwhile changed in TopBraid. I have fixed the remaining issue and updated it with other changes made in the meantime. Could you check if these changes work for you?

Ideally, such files should be maintained by true experts of this namespace (which I am not), and hosted by datacube itself, if there is interest.

ashleysommer commented 2 years ago

Awesome. Thanks @HolgerKnublauch . This can be closed now.