On 24/03/2019 14:34, Jerven Tjalling Bolleman wrote:
Hi All,
Cross posting as this seems to be a question of spec implementation and
I am not sure what the correct answer is supposed to be.
SELECT *
WHERE {
BIND("ABCDEFGHIJK" AS ?s2)
BIND(SUBSTR(?s2, 0, 1) AS ?sub)
}
SUBSTR => XPath fn:substring
"""
Otherwise, the function returns a string comprising those ·characters·
of $sourceString whose index position (counting from one) is greater
than or equal to the value of $start (rounded to an integer), and (if
$length is specified) less than the sum of $start and $length (both
rounded to integers).
"""
Note: it says "less than the sum of $start and $length" i.e. less (not
equal to) 1. It does not correct for the $start being zero or negative.
What does
substr("12345", 0, 3) return?
It should be "12"
substr("12345", -3, 5) return?
It should be "1"
These are examples from [F&O] section 5.4.3 "substr"
This gives "" in jena but "A" in rdf4j and virtuoso.
Seems to be some ambiguity in
https://www.w3.org/TR/sparql11-query/#func-substr
I think it is because while 1 is given as the index of the first
character for susbtring. the way that virtuoso and rdf4j seem to deal
with it is to take for the first value at least 1. While jena actually
uses the given value in the calculation.
Jena's custom function "afn:substr" does things java-style - zero based.
e.g.
SELECT *
WHERE {
BIND("ABCDEFGHIJK" AS ?s2)
BIND(SUBSTR(?s2, 0, 2) AS ?sub)
}
Gives "A" in jena but "AB" in virtuoso
Regards,
Jerven
[F&O]
XPath and XQuery Functions and Operators 3.1