Page MenuHomePhabricator

sparql replace "q" modifier not accepted
Closed, ResolvedPublic

Description

The below sample adapted from the function spec used in sparql doesn't seem work:

SELECT * { BIND( replace("a\b\c", "\", "\\", "q") as ?test) }

Result should be:

?test
a\\b\\c

Maybe it's deactivated on purpose.

Event Timeline

Esc3300 created this task.Jun 18 2018, 7:01 AM
Restricted Application added a project: Discovery. · View Herald TranscriptJun 18 2018, 7:01 AM
Restricted Application added a subscriber: Aklapper. · View Herald Transcript
Esc3300 updated the task description. (Show Details)Jun 21 2018, 10:11 AM

Apparently, all backslashes need to be escaped, which is the actual problem of the query. While \b is backspace character, \c is nothing.

Another error you've got in the query is the backslash in the second literal...

SELECT * { BIND( replace("a\b\c", "\", "\\", "q") as ?test) }
                                   ^

... which escapes the following double quote mark, causes the second argument to be "\", " (notice the syntax highlighting) and makes the number of quote marks unballanced.

After all, what does the "q" stand for?

q="don't escape the backslash" :)

I think its defined at http://www.w3.org/TR/xpath-functions/#regex-syntax and that should be included in sparql

Smalyshev added a subscriber: Smalyshev.

Yes, it looks like Blazegraph is missing support for "q" option. Fortunately, Java has Pattern.LITERAL mode that does exactly this, which makes fixing this easy.

Smalyshev triaged this task as Normal priority.Jun 21 2018, 5:12 PM

About this query:

SELECT * { BIND( replace("a\b\c", "\", "\\", "q") as ?test) }

I don't think this would work regardless of 'q' option. This option makes regex special characters lose their special meanings (inside regex context) but it does not change SPARQL grammar. And in SPARQL grammar things like "\" are invalid, and the literal parser will still parse literals according to the same set of rules.

Better test case would be:

SELECT * { BIND( replace("abc", ".", "Z", "q") as ?test) }

Here . should lose it's "catch all" meaning with 'q' option.

Smalyshev moved this task from Backlog to Doing on the User-Smalyshev board.Jun 21 2018, 6:23 PM
Smalyshev removed a project: User-Smalyshev.
Smalyshev closed this task as Resolved.Jun 25 2018, 6:19 PM
Vvjjkkii renamed this task from sparql replace "q" modifier not accepted to draaaaaaaa.Jul 1 2018, 1:03 AM
Vvjjkkii reopened this task as Open.
Vvjjkkii removed Smalyshev as the assignee of this task.
Vvjjkkii raised the priority of this task from Normal to High.
Vvjjkkii updated the task description. (Show Details)
Vvjjkkii removed a subscriber: Aklapper.
CommunityTechBot renamed this task from draaaaaaaa to sparql replace "q" modifier not accepted.Jul 2 2018, 4:42 AM
CommunityTechBot closed this task as Resolved.
CommunityTechBot assigned this task to Smalyshev.
CommunityTechBot lowered the priority of this task from High to Normal.
CommunityTechBot updated the task description. (Show Details)
CommunityTechBot added a subscriber: Aklapper.