Marc Pou
Marc Pou

Reputation: 649

How convert an embedded Neo4j graph db to GraphML with Python?

I want to store my embedded Neo4j Graph db to GraphML to draw it with a tool like yEd.

I'm managing the graph db with python27.

Does any body knows a way to do that?

Upvotes: 3

Views: 1881

Answers (2)

Pridkett
Pridkett

Reputation: 5503

If you can afford to do it outside of the process -- which means you'll need to shut down your existing process working on the embedded database and restart when finished with the export-- you can use Gremlin to do it. Here's the commands you'll need:

g = new Neo4jGraph("/YOUR/GRAPH/DIRECTORY")
writer = new GraphMLWriter(g)
out = new FileOutputStream("/YOUR/GRAPHML/file.graphml")
writer.outputGraph(out)
writer.setNormalize(true)
out.close()

This will create a nice pretty graphml file that is suitable for reading into a tool like Gephi or Cytoscape.

If you need to export the graph in-process you'll need to use something like jython to run your python scripts and then use the above commands by importing the objects from com.tinkerpop.blueprints.

Upvotes: 1

hymloth
hymloth

Reputation: 7035

If neo4j.py does not support exporting to GraphML format, or for any reason you cannot do that with Neo4j + Java, you'll have to write a custom exporter.

With some simple hacks you can accomplish that with NetworkX, which supports importing from/exporting to GraphML. Just figure a way to import your Neo4j graph into NetworkX and then export it directly to GraphML.

Upvotes: 0

Related Questions