646
edits
No edit summary |
|||
Line 30: | Line 30: | ||
=Scripting= | =Scripting= | ||
OpenRefine enables a variety of options for using scripting to extend the functionally of its graphical user interface. The main scripting languages used are General Refine Expression Language (GREL), which is similar to Excel string formulas, and Python. It can also be helpful to familiarize yourself with JavaScript Object Notation (JSON), which is a common data-interchange format. | |||
==Handy GREL scripts== | |||
value. | * To trim leading and trailing whitespace, navigate to ''Edit cells > Transform'' and use the following code: | ||
:<code>value.trim()</code> | |||
:This functionality can also be accomplished without scripting by navigating to ''Edit cells > Common transforms > Trim leading and trailing whitespace''. | |||
value. | * To collapse whitespace, e.g. a double space or a return carriage, navigate to ''Edit cells > Transform'' and use the following code: | ||
:<code>value.replace(/\s+/,' ')</code> | |||
:This functionality can also be accomplished without scripting by navigating to ''Edit cells > Common transforms > Collapse consecutive whitespace''. | |||
* To add the same text to every selected row in a column with existing values, navigate to ''Edit cells > Transform'' and use the following code: | |||
:<code>"'''NEW-TEXT'''" + value</code> | |||
cells | * To replace text in a column, navigate to ''Edit cells > Transform'' and use the following code: | ||
:<code>value.replace("'''EXISTING-VALUE'''","'''NEW-VALUE'''")</code> | |||
:This functionality can also be accomplished without scripting by navigating to ''Edit cells > Replace''. | |||
* To concatenate values from multiple columns, from the first column navigate to ''Edit cells > Transform'' and use the following code: | |||
:<code>value + cells["'''SECOND-COLUMN'''"].value + cells["'''THIRD-COLUMN'''"].value</code> | |||
:You can combine this feature with the ability to add text, e.g. <code>"'''NEW-TEXT'''" + value + cells["'''SECOND-COLUMN'''"].value</code>, and this functionality can also be accomplished without scripting by navigating to ''Edit column > Join columns...'' | |||
* To convert data in date format into a simplified text format, navigate to ''Edit cells > Transform'' and use the following code: | |||
:<code>value.toDate().toString('YYYY-MM-dd')</code> | |||
* To bring data from one OpenRefine project into a second OpenRefine project, from the second project navigate to ''Edit column > Add column based on this column'' and use the following code: | |||
:<code>cell.cross("'''NAME-OF-PROJECT-1'''", "'''PROJECT-1-COLUMN-TO-MATCH-ON'''")[0].cells["'''PROJECT-1-COLUMN-TO-GET-VALUE-FROM'''"].value</code> | |||
* To add a facet based on whether or not the values in a row match between two columns, navigate to ''Facet > Custom text facet'' and use the following code: | |||
:<code>cells["'''COLUMN-1'''"].value[0] == cells["'''COLUMN-2'''"].value[0]</code> | |||
=Join the community= | =Join the community= | ||
There are many audiences for OpenRefine, and the best community to join is one that aligns with your usage context and skill level. The [https://bit.ly/3kqiGIR OpenRefine Google Group] is maintained by OpenRefine, and most messages posted are more technical. | There are many audiences for OpenRefine, and the best community to join is one that aligns with your usage context and skill level. The [https://bit.ly/3kqiGIR OpenRefine Google Group] is maintained by OpenRefine, and most messages posted are more technical. |
edits