5

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?

pnuts
  • 58,317
  • 11
  • 87
  • 139
CH_
  • 685
  • 1
  • 7
  • 18

2 Answers2

7

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

Tom Morris
  • 10,490
  • 32
  • 53
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.

Will Hanley
  • 457
  • 3
  • 16