Summary
Implement full SPARQL 1.1 / XPath fn:matches flag support and pattern syntax compatibility for the REGEX built-in function.
Target Branch
Specification & Semantics
According to W3C SPARQL 1.1 Query (§17.4.3.14 REGEX) invoking XPath fn:matches:
- Flag
i: case-insensitive matching.
- Flag
s: dot-all mode (. matches newline characters).
- Flag
m: multiline mode (^ and $ match start/end of lines).
- Flag
x: extended whitespace and comments (whitespace within pattern is ignored, # marks comments until end of line).
- Flag
q: quote mode (pattern characters are treated literally without regex escaping).
- Character classes and bracket expressions
[] must conform to standard XML Schema / XPath regular expressions.
Technical Context & Implementation Notes
- Flag translation:
- In
NativeExpressionEvaluator.java, map XPath flags to java.util.regex.Pattern flags:
i -> Pattern.CASE_INSENSITIVE | Pattern.UNICODE_CASE
s -> Pattern.DOTALL
m -> Pattern.MULTILINE
x -> Pattern.COMMENTS
q -> Pattern.LITERAL
- Compatibility handling:
- Combinations such as
iq or x with bracket expressions must evaluate properly against target literals.
Targeted W3C SPARQL 1.0 / 1.1 Test Cases
regex-query-003
regex-query-004
REGEX with [] expression
REGEX with the ignore spacing (x) option
REGEX with the ignore spacing (x) option with class expression
REGEX with the q option
REGEX with the iq option
Verification
- Unit tests (
corese-core):
./gradlew test --tests "fr.inria.corese.core.next.query.impl.sparql.bridge.NativeExpressionEvaluatorTest"
- W3C conformance (
corese-w3c):
./gradlew test --tests "fr.inria.corese.w3c.sparql10.Sparql10DynamicTest"
Acceptance Criteria
[ ] All standard XPath flags (i, s, m, x, q) are recognized and properly converted to Java regex flags.
[ ] Flag x correctly ignores whitespaces and ignores comments starting with #.
[ ] Flag q treats the pattern as a literal string.
[ ] The 7 targeted W3C SPARQL 1.0 regex tests pass.
[ ] 0 SonarLint issues and cognitive complexity < 15.
Summary
Implement full SPARQL 1.1 / XPath
fn:matchesflag support and pattern syntax compatibility for theREGEXbuilt-in function.Target Branch
feature/corese-nextSpecification & Semantics
According to W3C SPARQL 1.1 Query (§17.4.3.14
REGEX) invoking XPathfn:matches:i: case-insensitive matching.s: dot-all mode (.matches newline characters).m: multiline mode (^and$match start/end of lines).x: extended whitespace and comments (whitespace within pattern is ignored,#marks comments until end of line).q: quote mode (pattern characters are treated literally without regex escaping).[]must conform to standard XML Schema / XPath regular expressions.Technical Context & Implementation Notes
NativeExpressionEvaluator.java, map XPath flags tojava.util.regex.Patternflags:i->Pattern.CASE_INSENSITIVE | Pattern.UNICODE_CASEs->Pattern.DOTALLm->Pattern.MULTILINEx->Pattern.COMMENTSq->Pattern.LITERALiqorxwith bracket expressions must evaluate properly against target literals.Targeted W3C SPARQL 1.0 / 1.1 Test Cases
regex-query-003regex-query-004REGEX with [] expressionREGEX with the ignore spacing (x) optionREGEX with the ignore spacing (x) option with class expressionREGEX with the q optionREGEX with the iq optionVerification
corese-core):./gradlew test --tests "fr.inria.corese.core.next.query.impl.sparql.bridge.NativeExpressionEvaluatorTest"corese-w3c):./gradlew test --tests "fr.inria.corese.w3c.sparql10.Sparql10DynamicTest"Acceptance Criteria
[ ] All standard XPath flags (
i,s,m,x,q) are recognized and properly converted to Java regex flags.[ ] Flag
xcorrectly ignores whitespaces and ignores comments starting with#.[ ] Flag
qtreats the pattern as a literal string.[ ] The 7 targeted W3C SPARQL 1.0 regex tests pass.
[ ] 0 SonarLint issues and cognitive complexity < 15.