Searching and replacing multiple values in Google Refine
Asked Answered
S

2

6

I'd like to search and replace multiple values in a column with a single function with GREL (or anything other) in Google Refine.

For example:
1. replace(value, "Buch", "bibo:Book")
2. replace(value, "Zeitschrift", "bibo:Journal")
3. replace(value, "Patent", "bibo:Patent")
4. and many more.

Is there a way to do this with one GREL expression?

Stomy answered 25/2, 2014 at 12:35 Comment(0)
R
8

For your first three, you can do:

value.replace("Buch", "bibo:Book").replace("Zeitschrift", "bibo:Journal").replace("Patent", "bibo:Patent")

Depending how many your "many more" is, that pattern may suffice. Otherwise you could investigate some type of table lookup (which might be easier in Python than GREL - just choose Jython for your expression language).

Rebate answered 25/2, 2014 at 15:58 Comment(0)
A
0

To do this in a single GREL line:

replace(value,/(.+)/,"bibo:$1")

I use this to reformat a column of digit strings with commas:

1,317
2,000
1,055

The GREL expression

replace(value,/(\d),(\d)/,"$1$2")

returns

1317 2000 1055

which I can then use as numbers.

Annettaannette answered 11/12, 2020 at 17:43 Comment(1)
That's going to produce bibo:Buch and bibo:Zeitschrift which is not what was requested.Rebate

© 2022 - 2024 — McMap. All rights reserved.