On 06/12/13 17:54, Ewa Szwed wrote:
Hi,

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)
.
.
.

50 times

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")
    ("Alaska"   "ak")
    ...
    ("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.

2/
Or add a custom function:

  BIND( my:fixup(?place) AS ?place_final)

and write the translation in Java which can use a regex or any other string manipulation you want.

        Andy

Reply via email to