Jython Functions

53 views
Skip to first unread message

mj.ke...@gmail.com

unread,
Aug 14, 2018, 12:21:35 PM8/14/18
to OpenRefine
Hello,

Is there a way to define a bunch of custom Jython functions that could be used in my transformations rather than having to write the same code repeatedly in my transformations?

Thanks,

--mjk

John Little

unread,
Aug 14, 2018, 2:35:34 PM8/14/18
to openr...@googlegroups.com
You can look in the "History" Tab.  Inside the expression box, you should find previous jython expressions that you've written.  Then click 'reuse'.  Or, you can star the expression and retrieve starred expressions from the "Starred" tab.

image.png

--
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.
For more options, visit https://groups.google.com/d/optout.

Ettore Rizza

unread,
Aug 14, 2018, 3:10:23 PM8/14/18
to OpenRefine
Hi,

You can define a series of functions in a .py file, then use the sys module to add to the path the folder where your file is located. Here is an example with a file named myFunctions.py containing the addOne() function and stored on my desktop. 

screenshot-127.0.0.1-3333-2018.08.14-21-03-24.png



I've proposed to find a simpler system, for example making OpenRefine automatically import the path of a folder where Python modules could be stored, but the proposal was classified as "priority Low". You can support it if you wish.

Ettore

Ettore Rizza

unread,
Aug 19, 2018, 3:14:09 AM8/19/18
to OpenRefine
Erratum: I had completely forgotten that Thad had provided an answer to this question. In fact, just store the file containing your functions in the folder .\openrefine-3.0-rc.1\webapp\extensions\jython\module\MOD-INF\lib.

Sans titre 1.jpg



After that, you can import the file as a module. 

screenshot-127.0.0.1-3333-2018.08.19-09-13-08.png

mj.ke...@gmail.com

unread,
Aug 30, 2018, 10:38:09 AM8/30/18
to OpenRefine
We are still using 2.8.  Does this work in 2.8:  webapp/extensions/jython/module/MOD-INF/lib?


Couple more questions:

> If I add modules to the directory at runtime, that is AFTER the instance has started up, will OR pick up on the newly added Python libs?
> I can add *.py files to this directory?  Or do they need to be compiled and packaged as a JAR file?

Thanks.

mj.ke...@gmail.com

unread,
Aug 30, 2018, 10:48:15 AM8/30/18
to OpenRefine
Looks like answer is yes to all.  I just checked locally.

--mjk

Ettore Rizza

unread,
Aug 30, 2018, 10:49:30 AM8/30/18
to OpenRefine
Hi,

I've not tested with 2.8, but I do not see why the trick would not work. Nothing has changed on that side. The best is to test yourself with a small function like the one I used. This is a simple text file with a .py extension.

However, you need to restart OpenRefine if you add new functions to the folder when OR is running.
Reply all
Reply to author
Forward
0 new messages