Skip to content

exactCount constraint not working with topquadrant shacl engine #374

@TShapinsky

Description

@TShapinsky

The following graph is generated via the shape_builder tests

@prefix brick: <https://brickschema.org/schema/Brick#> .
@prefix ns1: <https://nrel.gov/BuildingMOTIF/constraints#> .
@prefix sh: <http://www.w3.org/ns/shacl#> .
@prefix xsd: <http://www.w3.org/2001/XMLSchema#> .

<http://exampleshapes.org/ahu_shape> a sh:NodeShape ;
    sh:property [ a sh:PropertyShape ;
            sh:class brick:Outside_Air_Temperature_Sensor ;
            sh:maxCount 1 ;
            sh:minCount 1 ;
            sh:path brick:hasPoint ] ;
    sh:targetClass brick:AHU ;
    ns1:class brick:AHU ;
    ns1:exactCount 1 .

<http://exampleshapes.org/application_shape> a sh:NodeShape ;
    sh:targetClass brick:AHU ;
    sh:targetNode [ ] ;
    ns1:class brick:AHU ;
    ns1:exactCount 1 .


@prefix brick: <https://brickschema.org/schema/Brick#> .
@prefix ns1: <https://nrel.gov/BuildingMOTIF/constraints#> .
@prefix owl: <http://www.w3.org/2002/07/owl#> .
@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
@prefix sh: <http://www.w3.org/ns/shacl#> .
@prefix xsd: <http://www.w3.org/2001/XMLSchema#> .

<http://example.org/> a owl:Ontology .

<http://example.org/AHU_1> a brick:AHU .

<http://exampleshapes.org/ahu_shape> a sh:NodeShape ;
    sh:property <urn:well-known/4fc84634> ;
    sh:targetClass brick:AHU ;
    ns1:class brick:AHU ;
    ns1:exactCount 1 .

<http://exampleshapes.org/application_shape> a sh:NodeShape ;
    sh:targetClass brick:AHU ;
    sh:targetNode [ ] ;
    ns1:class brick:AHU ;
    ns1:exactCount 1 .

<https://nrel.gov/BuildingMOTIF/constraints> a owl:Ontology .

ns1:countConstraintComponent a sh:ConstraintComponent ;
    sh:parameter [ sh:datatype xsd:integer ;
            sh:description "the minimum required number of instances" ;
            sh:path ns1:exactCount ],
        [ sh:datatype rdf:Resource ;
            sh:description "the class to count" ;
            sh:path ns1:class ] ;
    sh:validator ns1:hasExactCount .

ns1:hasExactCount a sh:SPARQLAskValidator ;
    sh:ask """
        ASK WHERE {
            {
                SELECT * 
                WHERE { ?i a $class . }
                HAVING (COUNT(DISTINCT ?i) = $exactCount)
            }
        }""" ;
    sh:message "Not the right number {$exactCount} of instances of {$class}" .

<urn:well-known/4fc84634> a sh:PropertyShape ;
    sh:class brick:Outside_Air_Temperature_Sensor ;
    sh:maxCount 1 ;
    sh:minCount 1 ;
    sh:path brick:hasPoint .

This evaluates properly with pyshacl but with topquadrant I get the following error.

Error out: WARNING: java.io.tmpdir directory does not exist
Exception in thread "main" java.lang.IllegalArgumentException: Validator https://nrel.gov/BuildingMOTIF/constraints#hasExactCount does not define a valid body
        at org.topbraid.shacl.arq.functions.SHACLSPARQLARQFunction.<init>(SHACLSPARQLARQFunction.java:74)
        at org.topbraid.shacl.arq.SHACLFunctions.perhapsRegisterFunction(SHACLFunctions.java:98)
        at org.topbraid.shacl.arq.SHACLFunctions.registerFunctions(SHACLFunctions.java:80)
        at org.topbraid.shacl.validation.ValidationUtil.createValidationEngine(ValidationUtil.java:63)
        at org.topbraid.shacl.validation.ValidationUtil.validateModel(ValidationUtil.java:119)
        at org.topbraid.shacl.validation.ValidationUtil.validateModel(ValidationUtil.java:104)
        at org.topbraid.shacl.tools.Validate.run(Validate.java:60)
        at org.topbraid.shacl.tools.Validate.main(Validate.java:48)
Caused by: org.apache.jena.query.QueryParseException: SELECT * not legal with GROUP BY
        at org.apache.jena.sparql.lang.SyntaxVarScope.check(SyntaxVarScope.java:104)
        at org.apache.jena.sparql.lang.SyntaxVarScope.check(SyntaxVarScope.java:59)
        at org.apache.jena.sparql.lang.SyntaxVarScope$SubQueryScopeChecker.visit(SyntaxVarScope.java:205)
        at org.apache.jena.sparql.syntax.ElementWalker$EltWalker.visit(ElementWalker.java:192)
        at org.apache.jena.sparql.syntax.ElementSubQuery.visit(ElementSubQuery.java:52)
        at org.apache.jena.sparql.syntax.ElementWalker$EltWalker.visit(ElementWalker.java:113)
        at org.apache.jena.sparql.syntax.ElementGroup.visit(ElementGroup.java:120)
        at org.apache.jena.sparql.syntax.ElementWalker.walk(ElementWalker.java:37)
        at org.apache.jena.sparql.syntax.ElementWalker.walk(ElementWalker.java:32)
        at org.apache.jena.sparql.lang.SyntaxVarScope.checkSubQuery(SyntaxVarScope.java:78)
        at org.apache.jena.sparql.lang.SyntaxVarScope.check(SyntaxVarScope.java:63)
        at org.apache.jena.sparql.lang.SyntaxVarScope.check(SyntaxVarScope.java:54)
        at org.apache.jena.sparql.lang.SPARQLParser.validateParsedQuery(SPARQLParser.java:51)
        at org.apache.jena.sparql.lang.SPARQLParser.parse(SPARQLParser.java:34)
        at org.apache.jena.query.QueryFactory.parse(QueryFactory.java:144)
        at org.topbraid.jenax.util.ARQFactory.doCreateQuery(ARQFactory.java:201)
        at org.topbraid.jenax.util.ARQFactory.doCreateQuery(ARQFactory.java:183)
        at org.topbraid.jenax.util.ARQFactory.createQuery(ARQFactory.java:173)
        at org.topbraid.shacl.arq.functions.SHACLSPARQLARQFunction.<init>(SHACLSPARQLARQFunction.java:71)
        ... 7 more

line: 11:27:52 WARN  riot       :: [line: 13, col: 17] Bad IRI: <urn:well-known/4fc84634> Code: 61/SCHEME_PATTERN_MATCH_FAILED in PATH: The scheme specific syntax rules are violated.
line: 11:27:52 WARN  riot       :: [line: 46, col: 1 ] Bad IRI: <urn:well-known/4fc84634> Code: 61/SCHEME_PATTERN_MATCH_FAILED in PATH: The scheme specific syntax rules are violated.

I don't think these features have been leveraged a lot right now. I only found this when attempting to switch all tests over to topquadrant these tests started failing.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions