Trying to re-write the Neo4J browser in pygame with py2neo

This blog post is an exercise in articulating something so that maybe,  just maybe one person, or maybe two can understand me. Screen Shot 2014-06-06 at 14.53.21 (2)     So. I’ve written some code that takes the details the delegates gave us about themselves for our upcoming conference. It includes Twitter accounts and a few questions etc. I then semantify ( extract the basic concepts from this ) this data and pile it into a Neo4J database. I’m trying to visualise this data using pygame. The reason I chose pygame were  a. It’s python,  b. I know python. I did try another million angles.

My aim was to simply pile in the data and get “nice” graphs out of the other end. I was wasn’t looking for insight or meaning or valuable data. All I wanted was some “people based” data that connected to relevant random things…. and see where that took me. So. I wrote some code to get me a random person. Then I added some cypher to grab me some connections on from that person to other people. Like this…

MATCH (person:Person {name:"Mally Mclane"}),(them:Person)
 MATCH p=shortestPath((person)-[r*]-(them))
 WHERE length(p) > 3
 RETURN nodes(p),length(p)
 Limit 5

This does most of what I want, in that it makes “pretty graphs” quite reliably. My problem is this. If you look at the  two visualisations above, once running in the Neo4J browser and the other in my (rather hopeless ) pygame code you can see that although they have the same “blobs”, that the Technology_Internet blob in Neo4J is connected to 6 items but my pygame version is only connected to two ( Alex Goffe and the question in green ). I think I know why this is. In python when I get the results back I get 5 items  (see the “LIMIT 5”)  see below… Screen Shot 2014-06-06 at 15.13.16 (2) … and in each of those results, it’s values are nodes. Now… when I try to unpack these results into pygame… because each result returns a “path” of nodes, I am simply getting…

1. shoulder bone  node-> arm bone node > elbow bone node > wrist  bone  node
 2. arse bone node > knee bone node> shin bone node> ankle bone node > foot bone node

And there’s the problem. Because shortestPath returns a list of nodes,  a path, and not collections of nodes and relationships… I would have to, with each bone node, go and individually look up the relationships to each of  the other bone nodes. Am I right? Is that what the neo4J browser does? How does the neo4j browser know that ( in my case ) elbow bone node is connected to my arse bone node.

Leave a Reply

Your email address will not be published. Required fields are marked *