The Gephi Toolkit let you call all the Gephi Core features from languages running inside the Java Virtual Machine (JVM).
Such languages include Java of course, but also scripting, functional and/or dynamic languages like Groovy, Scala, Clojure, Jython or JRuby.
However, be aware that some of these languages relies on homemade standard libraries (Jython, by example, is "battery included")
so generated bytecode (.class) might need to be bundled with such library (by example, jythonlib.jar, 17Mb), adding some weight to the final package.
Also, for languages like Jython or JRuby, you cannot directly call original Python or Ruby extensions written in native code, because well, they are for the native Python/Ruby virtual machines (maybe a sick JNA/JNI expert hack some tricks, but we love Java portability, don't we).
If all these constrains don't stop you here are some tips for the languages I gave a try:
The best option so far for develoment only, is to use Netbeans IDE 6.9, and install the Python/Jython plugin. This is the most easy. You will have only to add the gephi-tookit.jar to the Java Class Path (I'll update this post to add some screenshots tonight).
Another good option for development without Netbeans, and the best for production, is to install Jython on your system.
It seems to be installed by default on some systems like Ubuntu, at version 2.2.x.
This correspond to Python 2.2x API. This may be enough for you, but I still recommend to use the most recent stable version (eg. 2.5.x) if possible (for speed, memory, stability fixes).
An option which should work in theory, would be to package the jython library (JAR) with your script, and run it with java -jar jythonlib.jar myscript.py --args.
I tried to do this, basic jython scripts work with this technique, but in my case it cannot find the Gephi Toolkit for an obscure reason (even when I add it to the class path using --classpath XYZ or -J -cp XYZ).
Here is a template for Netbeans-based Jython projects:
- Code: Select all
# -*- coding: utf-8 -*-
# note: this is a simple example. a real jython script should handle args,
__date__ ="$Aug 4, 2010 12:20:31 AM$"
# all the major API are exposed under the "gephi" module
# plus the major Controller (more to come soon, see the gephi..py module!)
from gephi import ProjectController
pc = ProjectController()
print "creating a new project.."
print "getting current workspace"
workspace = pc.getCurrentWorkspace()
As you can see, this can actually be very concise since a lot of the work is done at run time, and type conversion is done automagically by Jython (you didn't imported or declared workspace here, don't you?)
For this small script which don't do a lot for the moment, I wrote a small gephi.py wrapper around the gephi toolkit for my own purposes, but you could extend it with more pythonic features, lambdas, introspections and so on.
I invite you to try on your preferred JVM scripting language, if you have some tips I will add them to the list