GREL and multiple if conditions (for RDF extension)

630 views
Skip to first unread message

Go S

unread,
Dec 2, 2019, 11:32:46 AM12/2/19
to OpenRefine

Hello!

 

I am new to GREL and have a quick question. If you know it, maybe easy thing.

 

I have a column which contains dozens of controlled values.

I use RDF extension and I created a simple IF like below to generate RDF, which works fine for the records containing 'Place' (which is a part of the controlled values).

if (value == 'Place', 'http://www.example.com/Location', null)

 


But, of course, others got null, which needs to be further modified. Basically I would like to add more IFs in order to change the values, based on different conditions. For instance,

if (value == 'Person', 'http://www.example.com/Agent', null)

if (value == 'Book', 'http://www.example.com/Publication', null)

and so on.

 

I could not find an example in the documentation. What can I do?

Your help would be highly appreciated. Thank you very much in advance!

Thad Guidry

unread,
Dec 2, 2019, 11:55:35 AM12/2/19
to openr...@googlegroups.com
You can nest the if's.
You can also drag out the Expression editor window in the lower right corner to increase the edit input size to make it easier to see.
Then, just indent to make things easier on your eyes. (but GREL doesn't care about indents)
And ensure you wrap with enough ending parenthesis as needed for your IF conditions.

Example:

if(value == 'Place', 'http://www.example.com/Location',
  if(value == 'Person', 'http://www.example.com/Agent',
  if(value == 'Book', 'http://www.example.com/Publication',
null)))




--
You received this message because you are subscribed to the Google Groups "OpenRefine" group.
To unsubscribe from this group and stop receiving emails from it, send an email to openrefine+...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/openrefine/cc573fe5-9b7b-44cc-949a-18dfda6faa9a%40googlegroups.com.

Go S

unread,
Dec 3, 2019, 6:15:59 AM12/3/19
to OpenRefine
Dear Thad,

Thank you so much. The nesting works perfectly.
Good that it is also already included in Wiki, which may be handy for some people.

Best,
Go
Reply all
Reply to author
Forward
0 new messages