Skip to content

[Query] Support SPARQL XPath REGEX flags (x, q, s, m, i) and pattern matching #592

Closed

Description

@remiceres

Summary

Implement full SPARQL 1.1 / XPath fn:matches flag support and pattern syntax compatibility for the REGEX built-in function.

Target Branch

  • feature/corese-next

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

  1. 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
  1. 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.

Activity

  1. added
    featureNew feature or capability
    w3c-conformanceW3C standards compliance (SPARQL 1.1, Turtle, RDF 1.1)
    on Sep 18, 2026
  2. remiceres commented on Sep 22, 2026

    @remiceres
    ContributorAuthor

    Resolved by #606. All 7 W3C SPARQL regex evaluation tests now pass.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

featureNew feature or capabilityw3c-conformanceW3C standards compliance (SPARQL 1.1, Turtle, RDF 1.1)

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions