Final Project #3 – Tutorial

I started my work on the final project by following a tutorial – FUN with FACEBOOK in NEO4J wrote by Rik Van Bruggen. I followed the article as well as video. As I have quickly realised, the author took some of the steps for granted and didn’t include them in the tutorial.

In this post I’ll re-write it and make sure that anyone (even less technical people) can follow the simple instructions.

On top of that, I’ll have to update a few things, as the old method doesn’t work with the newest release of the Neo4j.

Step 1 – Give me my data

The first step is to get data from Facebook. I’ve used the tool Give Me My Data (described in more details in the previous post), but if you’re a software developer, you can use Facebook API directly.

After downloading the tool and linking it to your Facebook account, you have to download a particular set of data, which in our case is:

Data: Mutual Friends Network Graph

Format: CSV

It should look like this:



Step 2 – Copy and paste results into a text file

I have downloaded a tool used by Rik in his tutorial – Sublime Text 2. This is the output:

Screen Shot 2014-12-14 at 11.29.23

Now, save the file, MAKING SURE it’s a .txt file (so for example name if: FacebookData.txt, and click SAVE).

Step 3 – Uploading data into Google spreadsheets

Now that your .txt file is ready, you need to upload it into Google Spreadsheet.

Here are all the steps:

– Click on File –> Import…

– Upload the FacebookData.txt you’ve just created, choosing the following settings:



And is the final output:


Step 4 – Preparing data for creating cyphers

In order to upload data into Neo4j, we need to convert it into cyphers.

The first formula will eliminate all the dupes. Name your column D “No dupes in uid1 or uid2”, and use this formula:


*the second value (A5240) should be the last cell of your column A and it’ll depend on how much data/Facebook friends you have.

The second formula in column E will “Combine uid1 and uid2”, and it looks like this:


*the second value (D654) should be the last cell of your column D and it’ll depend on how much data/Facebook friends you have.

Step 5 –  Creating cyphers

Now we’re ready to create the cyphers. After struggling with uploading data into Neo4j for a few days, I have realised the old cyphers (from the original tutorial) are outdated and won’t work…

Fortunately, finally I have found a solution to the problem, and so now I can give you the RIGHT formulas.

5.1. Cypher statements for nodes

Use column G and the following formula:

="create (n:Facebook {name:'"&E2&"'});" 

Then paste it into the whole column.

5.2. Cypher statements for relationships

Use column I and the following formula:

="match (n1:Facebook {name:'"&A2&"'}),(n2:Facebook {name:'"&B2&"'}) create n1-[:IS_A_FRIEND_OF]->n2;"

Then paste it into the whole column.

This is the output you should have (ignore columns F and H and leave them empty):

Screen Shot 2014-12-14 at 12.24.48


Step 6 – Downloading and installing Java and Neo4j

Before you download Neo4j, you need to make sure that you have Java installed on your computer. If not (as it was in my case), you can download it from here. They have all the instructions, but it’s not complicated.

When it comes to installing Neo4j, it turns out to be NOT so easy if you’ve never done a similar thing before. I struggled fo a bit, but then found a very useful YouTube tutorial – Install Neo4j Mac or Unix. If you’re using Windows, take a look at Install Neo4j Windows instead.

Step 7 – Creating the index for property name based on label Facebook:

Before you begin adding data, open Neo4j and go to Console (shell environment), which looks like this:

Screen Shot 2014-12-14 at 12.31.29

And type in:

CREATE INDEX ON :Facebook(name)

It’ll create the index for property “name” based on label “Facebook”. Without this step, the next ones won’t work.

Step 8 – Uploading cyphers into Neo4j

You can upload your cyphers either into web based Neo4j console (the ones used before) or your own computer console (on Mac it’s called Terminal).

Using terminal may work better, but first you need to remember to open the shell-like environment using a command:


It should look like this:

Screen Shot 2014-12-14 at 12.57.41

Now, all you need to do (in theory) is wrap your cypher statements for node into “begin” and “commit” (to start end end the transaction), and paste them into one of the consoles.

Unfortunately, at least in my case, neither of the consoles would read cyphers as separate transactions, and so I had had to add “begin” and “commit” before EVERY SINGLE CYPHER. Fortunately you don’t have to do it manually.

If you look back here…

Screen Shot 2014-12-14 at 12.24.48

… you can see that I added columns F with “begin” and H with “commit”. Copy and paste all three columns into a Word document.

(Paste special –> Unformatted text will get read of the table)




You’ll get this result:

Screen Shot 2014-12-14 at 13.05.27

But what we need is:

Screen Shot 2014-12-14 at 13.07.41

To move “begin” and “commit” into separate lines, you can use a Word “Replace” formula (see where to find it below) and replace some of the text with a “Manual Line Break”, which will automatically insert new lines with text you specify (e.g. “begin”).

Screen Shot 2014-12-14 at 13.08.52


When ready, paste everything into the console, and it’ll upload all your nodes.

Prepare the “Cypher statements for relationships” in the same way (adding “begin” and “commit”) and uploaded them into Neo4j as well.

In the console, it’ll look like this:


(*This photo is taken fro the original tutorial, and so your cyphers inside should look differently)

Now, you should see both nodes and relationship ready, like here:

Screen Shot 2014-12-14 at 13.15.22


Step 9 –  Exploring your data

The last step is to go to “Data browser” (in Neo4j) and type:

match (n) return (n)

It’ll give you a list of all the nodes like this:

Screen Shot 2014-12-14 at 13.29.51


Now, open any of them, and click on the “Switch view mode” (top right corner):

Screen Shot 2014-12-14 at 13.30.52


You should now, finally, see your graph:

Screen Shot 2014-12-14 at 13.32.15



Step 10 – Start exploring your graph database!

That’s it, you’ve uploaded data into Neo4j and it’s ready for you to explore! You can change the design in the Neo4j Browser (see the tutorial on How to style the Neo4j-Browser visualization?). There’s more (usually more advanced) techniques described here.
Creative Commons License
This work is licensed under a Creative Commons Attribution 4.0 International License.


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s