Reputation: 765
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?
Upvotes: 6
Views: 5721
Reputation: 525
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.
Upvotes: 0
Reputation: 10540
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).
Upvotes: 8