Search code examples
sparql

Turn to lowercase using SPARQL replace


Hi I'm trying to simply write a function that lowercase some of the letter of a string, but without success.

Here is what I wrote:

SELECT * 

WHERE {

    BIND (REPLACE ("HELLO", "L",  LCASE("$0") ) AS ?var)

}

I get back "HELLO".

I followed the spec here https://www.w3.org/TR/xpath-functions/#func-replace for the "$x".

However if I write

SELECT * 

WHERE {

    BIND (REPLACE ("HELLO", "L",  LCASE("$0HI") ) AS ?var)

}

I get back "HELhiLhiO".

Why the LCASE can't be applied to $x?


Solution

  • The LCASE is applied to the string, then the result is passed to the REPLACE function, just like writing "function(1+2)" -- the function get passed 3,not 1+2.

    So LCASE is not applied to the value of $0 but to the string "$0".

    LCASE("$0HI") is "$0hi".

    The REPLACE executes as:

    REPLACE ("HELLO", "L", "$0hi")
    

    and each "L" is replaced by "$0hi" with $0 being substituted for "L".