Question

I am trying to run JUNGs PageRank algorithm onto my existing neo4j graph database and save a node's score as a property for future reference.

So I created the following groovy file:

import edu.uci.ics.jung.algorithms.scoring.PageRank

g  = new Neo4jGraph('/path/to/graph.db')
j = new GraphJung(g)

pr = new PageRank<Vertex,Edge>(j, 0.15d)
pr.evaluate()
g.V.sideEffect{it.pagerank=pr.getVertexScore(it)}

and run it through gremlin.

It runs smoothly and if I were to check the property via g.v(2381).map() I get what I'd expect.

However, when I leave gremlin and start up my neo4j server, these modifications are non-existant.

Can anyone explain why and how to fix this?

My hunch is that it has something to do with my graph in gremlin being embedded:

gremlin> g
==>neo4jgraph[EmbeddedGraphDatabase [/path/to/graph.db]]

Any ideas?

Was it helpful?

Solution

You will need a g.shutdown() at the end of your groovy script. Without a g.shutdown() all changes to the graph are most likely to stay in memory. Re-initializing the graph from disk (/path/to/graph.db in your case), will lose the changes which were still in memory. g.shutdown() will flush the current transaction from memory to disk. This will make sure your changes persist and will be retrieved when you try to access the database again.

Hope this helps.

Note: You are correct on the hunch for embedded database. This issue will not occur if you use Neo4j's REST interface because every REST API request is treated as a single transaction.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top