Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
Import friends list scrapped from Facebook into Neo4j.
//-----------------------
//Import people
//-----------------------
CREATE CONSTRAINT ON (a:PEOPLE) ASSERT a.id IS UNIQUE;
USING PERIODIC COMMIT 2000
LOAD CSV WITH HEADERS FROM "file:c:/my-facebook-network.csv" AS line
FIELDTERMINATOR ','
WITH line
WHERE line.File = "common-friends.csv"
MERGE (a:PEOPLE {id: line.Target});
USING PERIODIC COMMIT 2000
LOAD CSV WITH HEADERS FROM "file:c:/my-facebook-network.csv" AS line
FIELDTERMINATOR ','
WITH line
WHERE line.File = "friends.csv"
MERGE (a:PEOPLE {id: line.Source});
//-----------------------
//Relationships between people
//-----------------------
USING PERIODIC COMMIT 2000
LOAD CSV WITH HEADERS FROM "file:c:/my-facebook-network.csv" AS line
FIELDTERMINATOR ','
MATCH (b:PEOPLE {id: line.Source})
MATCH (a:PEOPLE {id: line.Target})
MERGE (a)-[r:IS_FRIEND_WITH]->(b);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment