0

Broadly speaking, here's what I'm trying to do: Parse a string in one cell of a spreadsheet, then add keywords to another cell in that row if certain keywords are found in the parsed cell.

I'm using OpenRefine (technically Google Refine 2.5) to try to do this, using the "Add a column based on this column" feature, and I've yet to have anything actually show up in the new column.

Here's the current iteration of the GREL expression I'm working with:

if (contains(cells["dates and codes"].value,"beef"), cells["protein"].value +=" beef", "")

It's throwing the following error:

Parsing error at offset 77: Missing number, string, identifier, regex, or parenthesized expression

I'm new to this software and to GREL, but my searching hasn't turned up this sort of string function. (I think I now have a better idea of how to reference specific cells, but I suppose that could also be the issue.)

A. Is this possible?, and
B. Is there a more efficient way to do this than scripting a bunch of if(contains()) statements?

pnuts
  • 58,317
  • 11
  • 87
  • 139
Dani
  • 73
  • 2
  • 11
  • Alternatively, is there a way to concatenate a keyword onto the text in that new column based on manual text filters? I.e., search for "beef" and then concatenate " beef" into the column for just those rows? My efforts thus far have led to only concatenating rows that already have data in that second column, instead of rows in that text filter. – Dani Oct 16 '14 at 20:27

1 Answers1

0

Your GREL expression make sense and it looks like you have an extra equal sign at offset 77.

if (contains(cells["dates and codes"].value,"beef"), cells["protein"].value +" beef", "")

You will need to define your contains logic in any case so you can either wrap everything in super long GREL expression. Alternatively you can exectuce each if(contains()) separatly. To gain some time I will do as follow:

  1. Write the expression one
  2. Export it to a notepade
  3. Update it using search and replace function
  4. Reapply your new expression to your project.

You can find more details regarding this process in this blog post.

magdmartin
  • 1,712
  • 3
  • 20
  • 43
  • Thanks for your help! Sorry if this is a silly question, but this is my first Refine project. What do you mean by "define my contains logic"? If my code says what I think it does, I've already done that, right? Calling a function with all the parameters? My code still isn't working (it either copies the entire string or is empty), and I'm trying to figure out if there's anything else I'm missing. – Dani Oct 16 '14 at 15:46