Skip to content

Instantly share code, notes, and snippets.

@jvilledieu
Last active August 14, 2017 05:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save jvilledieu/ecbd1e503b9b8b84cab6 to your computer and use it in GitHub Desktop.
Save jvilledieu/ecbd1e503b9b8b84cab6 to your computer and use it in GitHub Desktop.
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