Head's Up! These forums are read-only. All users and content have migrated. Please join us at community.neo4j.com.
06-28-2022 04:45 AM - last edited on 07-25-2022 09:08 AM by TrevorS
Hello,
I have a CSV file as below:
node01,relationship,node02
A_01,B_dependency,B_01
A_02,B_dependency,B_02
A_03,A_dependency,A_01
A_03,A_dependency,A_02
A_04,B_dependency,B_04
I hope the graphe like below:
My cypher code :
:auto USING PERIODIC COMMIT
LOAD CSV WITH HEADERS FROM
'file:///test.csv' AS line
MERGE (n1:node01{name: line.node01})
WITH line,n1
MERGE (n2:node02{name: line.node02})
WITH line,n1,n2
create (n1) -[:relate {relate: line.relationship}]-> (n2)
But, I get this graphe...
How should I go about doing this ?thanks !
Solved! Go to Solution.
06-28-2022 12:36 PM
Try this. First create all nodes.
LOAD CSV WITH HEADERS FROM "file:/chiang.csv" AS row
with row, left(row.node01, 1) as s1, left(row.node02, 1) as s2
FOREACH(ignoreMe IN CASE WHEN s1 = "A" THEN [1] ELSE [] END|
MERGE (n1:node01{name: row.node01})
)
FOREACH(ignoreMe IN CASE WHEN s2 = "A" THEN [1] ELSE [] END|
MERGE (n1:node01{name: row.node02})
)
FOREACH(ignoreMe IN CASE WHEN s1 = "B" THEN [1] ELSE [] END|
MERGE (n2:node02{name: row.node01})
)
FOREACH(ignoreMe IN CASE WHEN s2 = "B" THEN [1] ELSE [] END|
MERGE (n2:node02{name: row.node02})
)
Next create relationships;
LOAD CSV WITH HEADERS FROM "file:/chiang.csv" AS row
match (n1) where n1.name = row.node01
match (n2) where n2.name = row.node02
with n1, n2, row
MERGE (n1) -[:relate {relate: row.relationship}]-> (n2)
Result:
06-28-2022 12:36 PM
Try this. First create all nodes.
LOAD CSV WITH HEADERS FROM "file:/chiang.csv" AS row
with row, left(row.node01, 1) as s1, left(row.node02, 1) as s2
FOREACH(ignoreMe IN CASE WHEN s1 = "A" THEN [1] ELSE [] END|
MERGE (n1:node01{name: row.node01})
)
FOREACH(ignoreMe IN CASE WHEN s2 = "A" THEN [1] ELSE [] END|
MERGE (n1:node01{name: row.node02})
)
FOREACH(ignoreMe IN CASE WHEN s1 = "B" THEN [1] ELSE [] END|
MERGE (n2:node02{name: row.node01})
)
FOREACH(ignoreMe IN CASE WHEN s2 = "B" THEN [1] ELSE [] END|
MERGE (n2:node02{name: row.node02})
)
Next create relationships;
LOAD CSV WITH HEADERS FROM "file:/chiang.csv" AS row
match (n1) where n1.name = row.node01
match (n2) where n2.name = row.node02
with n1, n2, row
MERGE (n1) -[:relate {relate: row.relationship}]-> (n2)
Result:
All the sessions of the conference are now available online