TopQuadrant / shacl

SHACL API in Java based on Apache Jena
Apache License 2.0
217 stars 61 forks source link

fetching prefixes from internet when it's already in the file #158

Closed majidaldo closed 10 months ago

majidaldo commented 10 months ago

I'm not sure if this is a question about the expected behavior of a shacl processor or an issue (perhaps related to #53 ).

I get an unresolved prefix error if I remove the below line. What the processor is doing is fetching the ontology from the internet instead of using the prefixes that are (already) in the file. At this time, the internet file did not have the prefixes so it was failing..

Here's the minimal shape file but it's not reproducible because of the web address. shapes.ttl

@prefix owl: <http://www.w3.org/2002/07/owl#> .
@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .
@prefix sh: <http://www.w3.org/ns/shacl#> .
@prefix xsd: <http://www.w3.org/2001/XMLSchema#> .

<https://w3id.org/rec> a owl:Ontology ;
    rdfs:label "RealEstateCore" ;
    owl:imports <http://datashapes.org/dash>,
        # <https://brickschema.org/schema/1.3/Brick>, <<<< ERROR IF REMOVED
        <https://w3id.org/rec/brickpatches> ;
    owl:versionInfo "4.0" .

<https://brickschema.org/schema/1.3/Brick> a owl:Ontology ;
    sh:declare [ sh:namespace "http://www.w3.org/ns/shacl#"^^xsd:anyURI ;
            sh:prefix "sh" ],
        [ sh:namespace "http://www.w3.org/1999/02/22-rdf-syntax-ns#"^^xsd:anyURI ;
            sh:prefix "rdf" ],
        [ sh:namespace "https://brickschema.org/schema/Brick#"^^xsd:anyURI ;
            sh:prefix "brick" ],
        [ sh:namespace "http://www.w3.org/2000/01/rdf-schema#"^^xsd:anyURI ;
            sh:prefix "rdfs" ],
        [ sh:namespace "http://www.w3.org/2002/07/owl#"^^xsd:anyURI ;
            sh:prefix "owl" ],
        [ sh:namespace "https://brickschema.org/schema/Brick/ref#"^^xsd:anyURI ;
            sh:prefix "ref" ] .

error if offending line removed.

Exception in thread "main" org.apache.jena.query.QueryParseException: Line 1, column 18: Unresolved prefixed name: rdf:type
        at org.apache.jena.sparql.lang.QueryParserBase.throwParseException(QueryParserBase.java:578)
        at org.apache.jena.sparql.lang.QueryParserBase.resolvePName(QueryParserBase.java:320)
        at org.apache.jena.sparql.lang.arq.ARQParser.PrefixedName(ARQParser.java:6438)
        at org.apache.jena.sparql.lang.arq.ARQParser.iri(ARQParser.java:6422)
        at org.apache.jena.sparql.lang.arq.ARQParser.VarOrIri(ARQParser.java:4333)
        at org.apache.jena.sparql.lang.arq.ARQParser.Verb(ARQParser.java:3296)
        at org.apache.jena.sparql.lang.arq.ARQParser.PropertyListNotEmpty(ARQParser.java:3257)
        at org.apache.jena.sparql.lang.arq.ARQParser.TriplesSameSubject(ARQParser.java:3221)
        at org.apache.jena.sparql.lang.arq.ARQParser.TriplesTemplate(ARQParser.java:2352)
        at org.apache.jena.sparql.lang.arq.ARQParser.ConstructQuads(ARQParser.java:2233)
        at org.apache.jena.sparql.lang.arq.ARQParser.ConstructTemplate(ARQParser.java:3164)
        at org.apache.jena.sparql.lang.arq.ARQParser.ConstructQuery(ARQParser.java:585)
        at org.apache.jena.sparql.lang.arq.ARQParser.Query(ARQParser.java:35)
        at org.apache.jena.sparql.lang.arq.ARQParser.QueryUnit(ARQParser.java:22)
        at org.apache.jena.sparql.lang.ParserARQ$1.exec(ParserARQ.java:48)
        at org.apache.jena.sparql.lang.ParserARQ.perform(ParserARQ.java:95)
        at org.apache.jena.sparql.lang.ParserARQ.parse$(ParserARQ.java:52)
        at org.apache.jena.sparql.lang.SPARQLParser.parse(SPARQLParser.java:33)
        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.rules.SPARQLRule.<init>(SPARQLRule.java:46)
        at org.topbraid.shacl.rules.SPARQLRuleLanguage.createRule(SPARQLRuleLanguage.java:25)
        at org.topbraid.shacl.rules.RuleEngine.lambda$getShapeRules$2(RuleEngine.java:288)
        at java.base/java.util.HashMap.computeIfAbsent(HashMap.java:1228)
        at org.topbraid.shacl.rules.RuleEngine.getShapeRules(RuleEngine.java:274)
        at org.topbraid.shacl.rules.RuleEngine.executeShape(RuleEngine.java:190)
        at org.topbraid.shacl.rules.RuleEngine.executeShapes(RuleEngine.java:178)
        at org.topbraid.shacl.rules.RuleEngine.executeAll(RuleEngine.java:104)
        at org.topbraid.shacl.rules.RuleUtil.executeRulesHelper(RuleUtil.java:129)
        at org.topbraid.shacl.rules.RuleUtil.executeRules(RuleUtil.java:64)
        at org.topbraid.shacl.tools.Infer.run(Infer.java:54)
        at org.topbraid.shacl.tools.Infer.main(Infer.java:44)
HolgerKnublauch commented 10 months ago

I believe it's because of the mistake that basically 99.5% of SHACL-SPARQL users are making, namely to misunderstand how sh:prefixes works.

        sh:prefixes rdf:, brick: ;
        sh:select "SELECT $this WHERE { $this rdf:type/owl:deprecated true }" ] ;

would look for prefix definitions the given URIs, not use them. But at rdf: there is no prefix declaration. In the brick schema, it needs to be

       sh:prefixes <https://brickschema.org/schema/1.3/Brick>

because that is where the sh:declare triples are.

See https://www.w3.org/TR/shacl/#sparql-prefixes - this needs to be improved in SHACL 1.1 but it is what it is now.

majidaldo commented 10 months ago

Thanks!