Summary
Enforce SPARQL syntax validation and blank node scoping in the ANTLR parsing and semantic analysis pipeline, focusing on blank node scope validation across graph patterns and proper rejection of negative syntax test cases (syn-bad-*, syntax-query/, syntax-update-1/).
Context and Specification Requirements
According to W3C SPARQL specifications (Section 12.3: Scope of Blank Node Labels):
- Blank node labels (
_:label) are scoped to a single Basic Graph Pattern (BGP).
- Reusing the same blank node label across distinct BGPs, or across
UNION, OPTIONAL, or GRAPH pattern blocks, is a syntax violation and must be rejected with QuerySyntaxException (or a semantic error diagnostic).
- Negative syntax test cases must be rejected during query parsing or semantic analysis rather than producing an AST.
Implementation Details
1. Semantic Validation and AST Architecture
- Rules package:
fr.inria.corese.core.next.query.impl.sparql.parser.semantic.rule
- Reference implementation:
SelectProjectionScopeValidationRule.java implements SemanticValidationRule (or extends AbstractSemanticValidationRule).
- New rule: Implement blank node scope validation (e.g.,
BlankNodeScopeValidationRule.java) to traverse patterns and detect blank node label reuse across disjoint BGPs or pattern blocks (UNION, OPTIONAL, GRAPH).
- Register the new rule in
SparqlQuerySemanticValidator.java.
- AST / Parser builders:
fr.inria.corese.core.next.query.impl.sparql.parser.SparqlAstBuilder and SparqlQueryAstBuilder.java maintain groupStack and unionStack. Ensure blank node occurrences retain scope context or are verified during AST construction.
- Syntax errors: Handled by
SparqlErrorListener.java and SparqlQueryAnalyzer.java.
2. Escapes and Lexical Rules
- Ensure SPARQL escape sequences in IRIs and string literals adhere to standard rules (
syntax-esc-04.rq, syntax-esc-05.rq).
Test Execution and Verification
Unit tests in corese-core
mvn test -Dtest=SparqlParserValidationTest,SparqlParserTest
Unit test location: corese-core/src/test/java/fr/inria/corese/core/next/query/impl/sparql/parser/SparqlParserValidationTest.java
W3C test suite in corese-w3c
mvn test -Dtest=Sparql10DynamicTest
mvn test -Dtest=Sparql11DynamicTest
Test classes: Sparql10DynamicTest.java and Sparql11DynamicTest.java in corese-w3c.
Targeted W3C Test Cases
SPARQL 1.0 Syntax
syn-bad-UNION-breaks-BGP
syn-bad-OPT-breaks-BGP
syn-bad-GRAPH-breaks-BGP
syn-blabel-cross-union-bad
syn-blabel-cross-optional-bad
syn-blabel-cross-graph-bad
syn-bad-34.rq through syn-bad-38.rq
syntax-esc-04.rq, syntax-esc-05.rq
SPARQL 1.1 Negative Syntax
syntax-query/ negative tests (e.g. syntaxselectscope2, syntaxbindscope6)
syntax-update-1/ negative update syntax tests
Quality Standards
- 0 SonarLint issues.
- Cognitive complexity strictly below 15 for all methods.
- Braces on all control statements.
Acceptance Criteria
Summary
Enforce SPARQL syntax validation and blank node scoping in the ANTLR parsing and semantic analysis pipeline, focusing on blank node scope validation across graph patterns and proper rejection of negative syntax test cases (
syn-bad-*,syntax-query/,syntax-update-1/).Context and Specification Requirements
According to W3C SPARQL specifications (Section 12.3: Scope of Blank Node Labels):
_:label) are scoped to a single Basic Graph Pattern (BGP).UNION,OPTIONAL, orGRAPHpattern blocks, is a syntax violation and must be rejected withQuerySyntaxException(or a semantic error diagnostic).Implementation Details
1. Semantic Validation and AST Architecture
fr.inria.corese.core.next.query.impl.sparql.parser.semantic.ruleSelectProjectionScopeValidationRule.javaimplementsSemanticValidationRule(or extendsAbstractSemanticValidationRule).BlankNodeScopeValidationRule.java) to traverse patterns and detect blank node label reuse across disjoint BGPs or pattern blocks (UNION,OPTIONAL,GRAPH).SparqlQuerySemanticValidator.java.fr.inria.corese.core.next.query.impl.sparql.parser.SparqlAstBuilderandSparqlQueryAstBuilder.javamaintaingroupStackandunionStack. Ensure blank node occurrences retain scope context or are verified during AST construction.SparqlErrorListener.javaandSparqlQueryAnalyzer.java.2. Escapes and Lexical Rules
syntax-esc-04.rq,syntax-esc-05.rq).Test Execution and Verification
Unit tests in
corese-coremvn test -Dtest=SparqlParserValidationTest,SparqlParserTestUnit test location:
corese-core/src/test/java/fr/inria/corese/core/next/query/impl/sparql/parser/SparqlParserValidationTest.javaW3C test suite in
corese-w3cTest classes:
Sparql10DynamicTest.javaandSparql11DynamicTest.javaincorese-w3c.Targeted W3C Test Cases
SPARQL 1.0 Syntax
syn-bad-UNION-breaks-BGPsyn-bad-OPT-breaks-BGPsyn-bad-GRAPH-breaks-BGPsyn-blabel-cross-union-badsyn-blabel-cross-optional-badsyn-blabel-cross-graph-badsyn-bad-34.rqthroughsyn-bad-38.rqsyntax-esc-04.rq,syntax-esc-05.rqSPARQL 1.1 Negative Syntax
syntax-query/negative tests (e.g.syntaxselectscope2,syntaxbindscope6)syntax-update-1/negative update syntax testsQuality Standards
Acceptance Criteria
UNION,OPTIONAL,GRAPH, or distinct BGPs raises a syntax or semantic error.corese-w3c.corese-corepass without regression.