On Fri, Dec 6, 2013 at 12:54 PM, Ewa Szwed <[email protected]> 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)
It *is* possible to replace multiple occurrences of a match, but I
don't think you can do what you're trying to do. For instance, what
you can do is:
select * where {
values ?place { "A B C D E" }
bind( replace( ?place, "(B|D)", "[$1]" ) as ?place_updated )
}
and that produces
?place ?place_updated
"A B C D E" "A [B] C [D] E"
so you've done multiple replacements, but each match was replaced with
the same text (parameterized by $1). However, you want to replace
matches with _different_ text depending on what the particular match
was, and I don't think you'll be able to do that, since I don't see a
way to conditionalize the replacement text.
For what it's worth, the pattern of replacements you're describing is
very similar to one of the hits for "split string in sparql", a
answers.semanticweb.com question, Split and trim strings in SPARQL
[http://answers.semanticweb.com/questions/19162/split-and-trim-strings-in-sparql]
.
//JT
--
Joshua Taylor, http://www.cs.rpi.edu/~tayloj/