Calculates the Bacon Number based upon the Neo4j example data
Switch branches/tags
Nothing to show
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Type Name Latest commit message Commit time
Failed to load latest commit information.


Calculates the Bacon Number based upon the Neo4j example data


You'll need to have Neo4j running and populated with a data set about movies and actors. Neo4j comes with such a data set as an example. The essential relationship is (:Person)-[:ACTED_IN]->(:Movie)

On *NIX, you can install Neo4j as follows

wget -qO- | tar xzf -
cd neo4j-community-2.0.0-M06/
bin/neo4j start
# open http://localhost:7474/browser/
# stop with bin/neo4j stop

In this UI, type in :play movies and follow the instructions until the data in imported (which will take a couple of secs).

Then, to start the python app, you'll have to install flask and requests. Or you can just pip install -r requirements.txt in your favourite virtualenv.

Either way, start the app by


For more options, see python --help


The app has two endpoints:

  • /<actor>

    This will calculate the Bacon Number for the given author

  • /<actor>/<some_other_actor>

    This will calculate the distance between the two given authors. (some_other_author is treated as Kevin Bacon)

The output format is shamelessly ripped off of Google

The Query

The Cypher Query to retrieve the Bacon Number and its intermediate steps is

WHERE{kevin} AND{actor}
	length([m in nodes(p) WHERE m:Movie]) as BaconNumber,
	[m in nodes(p) WHERE m:Movie | m.title] as Movies,
	[a in nodes(p) WHERE a:Person |][1..-1] as KnowsActors

{kevin} and {actor} are substituted with the given actor names.