Skip to content

Return empty string from STRAFTER/STRBEFORE when there is no match - #82

Open
MathiasVDA wants to merge 1 commit into
DataTreehouse:mainfrom
MathiasVDA:fix/strafter-strbefore-no-match
Open

MathiasVDA wants to merge 1 commit into
DataTreehouse:mainfrom
MathiasVDA:fix/strafter-strbefore-no-match

Conversation

@MathiasVDA

Copy link
Copy Markdown

Requested by Mathias

Fixes #79.

Before: when the second argument does not occur in the first, STRAFTER and STRBEFORE returned the whole first argument, e.g. STRAFTER("abc", "xyz") = "abc".

After: they return the empty string, as SPARQL 1.1 §17.4.3.9 and §17.4.3.10 require: STRAFTER("abc", "xyz") = "", STRBEFORE("abc", "xyz") = "". Matches and empty second arguments behave as before.

How: the None branch of the find in str_after and str_before now returns Some("").

One gap remains for language-tagged input: with no match, the result keeps its tag (""@en), while the spec asks for an empty simple literal. Fixing that needs a per-row result type, so I left it out of this change.

Tests: py_maplib/tests/test_str_before_after.py (11 cases: simple and language-tagged literals, plus values read from a graph).

🤖 Generated with Claude Code

SPARQL 1.1 17.4.3.9/17.4.3.10: if the second argument does not occur in the
first, an empty simple literal is returned. Previously the whole first
argument was returned. Refs DataTreehouse#79.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>

This branch has not been deployed

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

SPARQL STRAFTER/STRBEFORE return the whole string instead of "" when there is no match

1 participant