Quantcast
Channel: Apache Timeline
Viewing all articles
Browse latest Browse all 5648

Replace doesn't error on patterns that match zero length strings

$
0
0
The SPARQL function replace is based on XPath's fn:replace, With fn:replace

An error is raised [err:FORX0003] if the pattern matches a zero-length
string, that is, if the expression fn:matches("", $pattern,
$flags)returns true. It is not an error, however, if a captured
substring is zero-length. [1]
<<<

This is the behavior exhibited by Virtuoso. E.g,. running the
following query on the DBpedia endpoint [2] produces an error:

select (replace( "foo", ".*", "x" ) as ?bar) where {}

Virtuoso 22023 Error The regex-based XPATH/XQuery/SPARQL replace()
function can not search for a pattern that can be found even in an
empty string
<<<

Jena accepts it without a problem (for an empty file data.n3):

$ sparql --data data.n3 'select (replace( "foo", ".*", "x" ) as ?bar)
from <> where {}'

| bar |
========
| "xx" |

$ sparql --version
Jena: VERSION: 2.11.0
Jena: BUILD_DATE: 2013-09-12T10:49:49+0100
ARQ: VERSION: 2.11.0
ARQ: BUILD_DATE: 2013-09-12T10:49:49+0100
RIOT: VERSION: 2.11.0
RIOT: BUILD_DATE: 2013-09-12T10:49:49+0100
<<<

Is this an *intended* extension? I ran into while trying to implement
some approximate string matching in pure SPARQL [3]. It's easy enough
to work around (just add a character to the pattern and the string),
but I wasn't sure whether it's a permissible and intentional
extension, or a bug.

//JT

[1] http://www.w3.org/TR/xpath-functions/#func-replace
[2] http://dbpedia.org/sparql
[3] http://stackoverflow.com/q/24557020/1281433

Viewing all articles
Browse latest Browse all 5648

Trending Articles