Playing with Neo4j version 3.0
I’ve been playing again with Neo4j now that v3 is out. And hacking through some ruby scripts to load some interesting data I have laying around (e.g. the database for this website which I’m mainly modeling as “(posts)<-(tags); (posts:articles)<-(publisher)”).
For ruby hacking in the past I’ve used the Neology gem, but now I’m trying out the Neo4jrb set of gems. And though I think an OGM is where it’s at (next Rails app I build will no doubt be using some graph db), I’m starting with just neo4j-core to get a handle on graph concepts and Cypher.
One thing that stumped me for a bit is that with the latest version of these gems – maybe now that they support multiple Neo4j sessions – I found it helped to add a “default: true” parameter to the session “open” to keep everything down stream working at the neo4j-core level. Otherwise Node and other neo4j-core classes seemed to lose the current session and give a weird error (depending on scope?). Or maybe I just kept clobbering my session context somehow. Anyway doesn’t seem to hurt.
[pastacode lang=”ruby” manual=”require%20’neo4j-core’%0A%40_neo_session%20%3D%20nil%0Adef%20neo_session%0A%20%20%40_neo_session%20%7C%7C%3D%20Neo4j%3A%3ASession.open(%3Aserver_db%2C%0A%20%20%20%20’http%3A%2F%2Fuser%3Apassword%40localhost%3A7474’%2C%0A%20%20%20%20default%3A%20true)%0Aend%0A%23…%0Aneo_session%0ANeo4j%3A%3ANode.create(%7Btitle%3A%20%22title%22%7D%2C%20%3ABlog)%0A%23…” message=”Neo4j-core Session” highlight=”” provider=”manual”/]
The Neo4j v3 Mac OSX “desktop install” has removed terminal neo4j-shell access in favor of the updated slick browser interface. This updated browser interface is pretty good, but for some things I’d still really like to play with a terminal window command shell. Maybe I’m just getting old :)… If you still want the neo4j shell, apparently you can instead install the linux tarball version (but then you don’t get the browser client?). I’m not sure why product managers make either-or packaging decisions like this. It’s not as if the shell was deprecated (e.g. to save much dev, time or testing effort).
Anyway, things look pretty cool in the browser interface, and playing with Cypher is straightforward as you can change between table, text, and graph views of results with just a click.
I’ve also been wanting to play with Gephi more. So I’m exporting data from Neo (using .cvs files though as the Gephi community neo4j importer plugin isn’t yet updated to Gephi v0.9) using Cypher statements like these and the browser interface download button.
[pastacode lang=”sql” manual=”%23for%20the%20node%20table%20export%20-%3E%20Gephi%20import%0AMATCH%20(n)%20RETURN%20ID(n)%20AS%20Id%2C%20LABELS(n)%20AS%20Label%2C%20n.title%20As%20Title%2C%20n.url%20AS%20URL%2C%20toString(n.date)%20as%20Date%2C%20n.name%20AS%20Name%2C%20n.publisher%20AS%20Publisher%0A%0A%23for%20the%20edge%20table%20export%20-%3E%20Gephi%20import%0AMATCH%20(l)-%5Brel%5D-%3E(r)%20RETURN%20ID(rel)%20AS%20Id%2C%20TYPE(rel)%20AS%20Label%2C%20ID(l)%20AS%20Source%2C%20ID(r)%20AS%20Target” message=”Cypher Queries for Importing into Gephi” highlight=”” provider=”manual”/]