resource-watch/graph-client

View on GitHub
import.txt

Summary

Maintainability
Test Coverage
// IMPORT NODES

LOAD CSV FROM 'file:///nodes.csv'
AS line
WITH line
MERGE (c:CONCEPT { id: line[0], label: line[1], synonyms: CASE line[2] WHEN null THEN '' ELSE split(line[2],'|') END })

// AFFECTS relationships
LOAD CSV FROM 'file:///affects.csv'
AS line
WITH line
MATCH (c1:CONCEPT { id: line[0]}), (c2:CONCEPT { id: line[1]})
MERGE (c1)-[:AFFECTS]->(c2)

// CAN_AFFECT relationships
LOAD CSV FROM 'file:///can_affect.csv'
AS line
WITH line
MATCH (c1:CONCEPT { id: line[0]}), (c2:CONCEPT { id: line[1]})
MERGE (c1)-[:CAN_AFFECT]->(c2)

// IS_A relationships
LOAD CSV FROM 'file:///is_a.csv'
AS line
WITH line
MATCH (c1:CONCEPT { id: line[0]}), (c2:CONCEPT { id: line[1]})
MERGE (c1)-[:IS_A]->(c2)

// IS_INVOLVED_IN relationships
LOAD CSV FROM 'file:///is_involved_in.csv'
AS line
WITH line
MATCH (c1:CONCEPT { id: line[0]}), (c2:CONCEPT { id: line[1]})
MERGE (c1)-[:IS_INVOLVED_IN]->(c2)

// LOCATED_AT relationships
LOAD CSV FROM 'file:///located_at.csv'
AS line
WITH line
MATCH (c1:CONCEPT { id: line[0]}), (c2:CONCEPT { id: line[1]})
MERGE (c1)-[:LOCATED_AT]->(c2)

// IS_SIMILAR_TO relationships
LOAD CSV FROM 'file:///is_similar_to.csv'
AS line
WITH line
MATCH (c1:CONCEPT { id: line[0]}), (c2:CONCEPT { id: line[1]})
MERGE (c1)-[:IS_SIMILAR_TO]->(c2)

// PART_OF relationships
LOAD CSV FROM 'file:///part_of.csv'
AS line
WITH line
MATCH (c1:CONCEPT { id: line[0]}), (c2:CONCEPT { id: line[1]})
MERGE (c1)-[:PART_OF]->(c2)

// QUALITY_OF relationships
LOAD CSV FROM 'file:///quality_of.csv'
AS line
WITH line
MATCH (c1:CONCEPT { id: line[0]}), (c2:CONCEPT { id: line[1]})
MERGE (c1)-[:QUALITY_OF]->(c2)

// RELATED_TO relationships
LOAD CSV FROM 'file:///related_to.csv'
AS line
WITH line
MATCH (c1:CONCEPT { id: line[0]}), (c2:CONCEPT { id: line[1]})
MERGE (c1)-[:RELATED_TO]->(c2)

// TYPE_OF relationships
LOAD CSV FROM 'file:///type_of.csv'
AS line
WITH line
MATCH (c1:CONCEPT { id: line[0]}), (c2:CONCEPT { id: line[1]})
MERGE (c1)-[:TYPE_OF]->(c2)

//===============CREATE INDICES=======================
CREATE INDEX ON :CONCEPT(id);
CREATE INDEX ON :DATASET(id);
CREATE INDEX ON :WIDGET(id);
CREATE INDEX ON :LAYER(id);
CREATE INDEX ON :USER(id);

DROP INDEX ON :CONCEPT(id);
DROP INDEX ON :DATASET(id);
DROP INDEX ON :WIDGET(id);
DROP INDEX ON :LAYER(id);


CREATE CONSTRAINT ON (dataset:DATASET) ASSERT dataset.id IS UNIQUE;
CREATE CONSTRAINT ON (widget:WIDGET) ASSERT widget.id IS UNIQUE;
CREATE CONSTRAINT ON (layer:LAYER) ASSERT layer.id IS UNIQUE;
CREATE CONSTRAINT ON (metadata:METADATA) ASSERT metadata.id IS UNIQUE;
CREATE CONSTRAINT ON (user:USER) ASSERT user.id IS UNIQUE;
CREATE CONSTRAINT ON (concept:CONCEPT) ASSERT concept.id IS UNIQUE;