On Fri, Dec 6, 2013 at 1:41 PM, Andy Seaborne <[email protected]> wrote:
> On 06/12/13 17:54, Ewa Szwed wrote:
>> Is it possible to do multiple replacements in one BINDING.
>> I am trying to avoid the following:
>>
>> BIND( replace(?place, "Alabama", "al") AS ?place_1)
>> BIND( replace(?place1, "Alaska", "ak") AS ?place_3)
>> …
>> BIND( replace(?place50, "Wyoming", "wy") AS ?place_final)
>
> 1/ If you can work with exact replacements:
> You can create a translation table with VALUES:
>
>   VALUES (?place ?rewrite) {
>     ("Alabama"  "al")
> …
>     ("Wyoming", "wy")
>   }
>
> the optionally join it with the pattern that found ?place:
>
> SELECT *
> {
>   ... ?place ...
>
>   OPTIONAL {
>     VALUES (?place ?rewrite) {
>       ("Alabama"  "al")
>       ("Alaska"   "ak")
>       ..
>       ("Wyoming" "wy")
>   } }
>
> }
>
> The OPTIONAL copes with the case of no match.

I think that Ewa wanted to do multiple replacements on the same
string.  E.g., to turn "I moved from New Hampshire to New York" would
turn into "I moved from nh to ny".  This (unless I'm misunderstanding
it) looks like it's just replacing one one exact match with its
replacement.

//JT
-- 
Joshua Taylor, http://www.cs.rpi.edu/~tayloj/

Reply via email to