Neo4j is a popular graph database which provides an easy way to import text files using the Cypher query language and a LOAD CSV
clause. LOAD CSV
by default expects files to be delimited by commas. In order to specify another field delimiter, add FIELDTERMINATOR
to the LOAD CSV
clause. For example:
USING PERIODIC COMMIT
LOAD CSV WITH HEADERS FROM "file:///twitter_relationships_top_100.txt" AS line
FIELDTERMINATOR '\t'
CREATE (u:User {username: line.username});
The statement above loads the tab separated twitter_relationships_top_100.txt
file (with headers) into the database, creating User
labels/nodes with a username
property for each record. A small sample of this file can be seen below:
username followers followed_by
charliesheen 11593973 shaq
charliesheen 11593973 wizkhalifa
charliesheen 11593973 pharrell
charliesheen 11593973 kevinhart4real
charliesheen 11593973 pitbull
charliesheen 11593973 johncena
charliesheen 11593973 ludacris
charliesheen 11593973 niallofficial
charliesheen 11593973 rickygervais
For a more detailed description of the LOAD CSV clause, please refer to the Neo4j documentation at the Neo4j LOAD CSV page.