forked from resource-watch/graph
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathImportDBCypher.txt
79 lines (68 loc) · 2.58 KB
/
ImportDBCypher.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
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, default_parent: CASE line[3] WHEN null THEN '' else line[3] END})
LOAD CSV FROM 'file:///nodes.csv'
AS line
WITH line
MATCH (c:CONCEPT { id: line[0]})
FOREACH(ignoreMe IN CASE WHEN line[4] = 'TOPIC' THEN [1] ELSE [] END | SET c:TOPIC)
FOREACH(ignoreMe IN CASE WHEN line[4] = 'GEOGRAPHY' THEN [1] ELSE [] END | SET c:GEOGRAPHY)
FOREACH(ignoreMe IN CASE WHEN line[4] = 'DATA_TYPE' THEN [1] ELSE [] END | SET c:DATA_TYPE)
FOREACH(ignoreMe IN CASE WHEN line[4] = 'FREQUENCY' THEN [1] ELSE [] END | SET c:FREQUENCY)
FOREACH(ignoreMe IN CASE WHEN line[4] = 'TIME_PERIOD' THEN [1] ELSE [] END | SET c:TIME_PERIOD)
// 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)
// 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)
//================CREATE CONSTRAINTS==================
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;