Skip to content

Instantly share code, notes, and snippets.

@widged
Forked from jexp/csv_import_neo4j.adoc
Last active October 14, 2015 10:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save widged/057cb9dbc193c47e8d4d to your computer and use it in GitHub Desktop.
Save widged/057cb9dbc193c47e8d4d to your computer and use it in GitHub Desktop.

Importing the csv file from data.govt.nz. The header row is "Title","Url","DatasetType","Agency","AgencyContact","AgencyContactEmail","AgencyContactPhone","Description","Format","UpdateFrequency","Cost","CostInformation","SubmissionSource","Licence","LicenceURL","Date listed","Date last updated","DatasetLastUpdated","DatasetCreation","Guid"

USING PERIODIC COMMIT 100
LOAD CSV WITH HEADERS FROM "https://data.govt.nz/search/csv/?q=&CategoryID=0"
  AS line
WITH line LIMIT 500
CREATE (t:Title {name:line.Title})
CREATE (e:Description {name:line.Description})
MERGE (u:Url {name:line.Url})
CREATE (t)-[r1:PUBLISHED_AT]->(u)
MERGE (a:Agency {name:line.Agency})
CREATE (t)-[r2:PUBLISHED_BY]->(a)
MERGE (d:Type {name:line.DatasetType})
CREATE (t)-[r3:TYPE]->(d)
MERGE (l:Licence {name:line.Licence})
CREATE (t)-[r4:DESCRIPTION]->(e)
FOREACH (fmt IN split(line.Format, ",")| MERGE (f:Format { name: lower(fmt) })
         CREATE (t)-[r5:FORMAT]->(f))
CREATE (t)-[r6:LICENCE]->(l)
RETURN a.name AS Agency, d.name AS Type, l.name AS Licence;

Licences in use and which agencies favour them

MATCH (l:Licence)<--(t:Title)-->(a:Agency)
RETURN l.name AS Licence, collect(DISTINCT a.name)

Formats in use and which agencies favour them

MATCH (f:Format)<--(t:Title)-->(a:Agency)
RETURN f.name AS Format, collect(DISTINCT a.name)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment