Does Bulbs allow the use of Graph Algorithms ? #26

Closed
EugeneLiang opened this Issue Feb 25, 2012 · 2 comments

2 participants

@EugeneLiang

Hi!

I am super excited about this project!

I was wondering if Bulbs support the use of Graph Algorithms ?

Such as the graph algorithms built-in for Neo4j ? Or https://github.com/tinkerpop/furnace/wiki that is used in Blueprint?

If so, is there a simple example to get me started ?

Thanks!

@espeed
Owner

Hi Eugene -

Yes, you can use any Neo4j or Tinkerpop/Blueprints algorithm.

Neo4j Server and Rexster support server-side scripting through the Gremlin (https://github.com/tinkerpop/gremlin/wiki) plugin/extension:

Gremlin comes in several variants. There is Gremlin-Java, Gremlin-Scala, and the original Gremlin-Groovy. Gremlin-JavaScript is in the works, and Gremlin-Jython is on deck.

The Neo4j Server and Rexster plugin/extension use the original Gremlin-Groovy, and a Gremlin-JavaScript plugin (https://github.com/neo4j/javascript-plugin) is ready for when Gremlin-JavaScript is completed.

If you look at the Bulbs source, you will see several gremlin.groovy files:

These are the Gremlin scripts that Bulbs uses for certain operations.

The top-level https://github.com/espeed/bulbs/blob/master/bulbs/gremlin.groovy are Gremlin methods that are generic and can be used on any Gremlin-enabled server.

The server-specific files are specific to each server and can override anything in the top-level file:

You can create your own custom Gremlin library, and Bulbs will parse the Groovy file and store each method in a dict, keyed by the Groovy method names.

You can add your custom Gremlin library to Bulbs like this:

>>> from bulbs.neo4jserver import Graph
>>> g = Graph()
>>> g.scripts.update(scripts_file_path)

You can then execute your custom Groovy scripts from Python like this:

>>> script = g.scripts.get('your_custom_query')
>>> params = dict(_id=3)
>>> elements = g.gremlin.query(script, params)
>>> element = elements.next()

>>> script = g.scripts.get('your_custom_command')
>>> params = dict(_id=5)
>>> resp = g.gremlin.command(script, params)

This executes the script on the server.

Use gremlin.query() when you want to return a list of initialized elements. Use gremlin.command() when you want to return non-element results (it returns the raw Response object).

If you are in the Python REPL and you update your Gremlin-Groovy library, you can refresh the scripts in the Python object like this:

>>> g.scripts.refresh()

Bulbs 0.3 is in GitHub master and is mostly commented. I am working on updating the docs on http://bulbflow.com right now, which are currently for 0.2.

@EugeneLiang

wow thanks for the detailed response.

I'll check it out and get back to u.

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment