Head's Up! These forums are read-only. All users and content have migrated. Please join us at community.neo4j.com.
08-07-2022 01:46 AM
LOAD CSV WITH HEADERS FROM "file:///kandidatpilpres_tesis3.csv" as nodes
create (n {name: nodes.vertex, type: nodes.Rela})
MERGE (tgt10:Char0a {id: nodes.target})
MERGE (ver10:Char0a {id: nodes.vertex})
match (y {type:"Tweet"})
set y:Tweet
match (x {type:"Mentions"})
set x:Mentions
match (z {type:"Replies_to"})
set z:Replies_to
MERGE (tgt)-[:Mentions]->(x)
MERGE (tgt)-[:Tweet]->(y)
MERGE (tgt)-[:Replies_to]->(z)
RETURN *
Solved! Go to Solution.
08-07-2022 06:16 AM
You can try this if you want to use pure cypher:
load csv with headers from "file:///TargetVertexImport.csv" as row
merge(v:Vertx{name: row.vertex})
merge(t:Target{name: row.target})
with v, t, row
call{
with v, t, row
with v, t, row
where row.Rela1 = 'Mentions'
merge(t)-[:MENTIONS]->(v)
}
call{
with v, t, row
with v, t, row
where row.Rela1 = 'Replies_to'
merge(t)-[:REPLIES_TO]->(v)
}
Or try this, if you are ok with using the apoc library. The code is more compact and does not require a new call block for every different relationship type.
load csv with headers from "file:///TargetVertexImport.csv" as row
merge(v:Vertx{name: row.vertex})
merge(t:Target{name: row.target})
with t, v, row
call apoc.create.relationship(t, toUpper(row.Rela1), null, v) yield rel
return t.name, v.name, type(rel)
08-07-2022 04:17 AM - edited 08-07-2022 04:20 AM
I have three observations. One, you will need a ‘with’ statement when going from a ‘merge’ or ‘create’ to a ‘match’, and also when going from a ‘set’ to a ‘match’. Two, you are referencing variable ‘tgt’ in your final three ‘merge’ statements, but I done see ‘tgt’ being set. As a result, the merge will create a new node on the first ‘merge’, which will be used in the following two merges. Is this your intent, or did you want to reference ‘tgt10’ instead? Three, why are you matching and setting the label for the three nodes ‘Tweet’, ‘Mentions’, and ‘Replies_to’ in this import query? That should be done once outside this query if there was an error when those nodes where first created. You still need to match here for use in your final three ‘merges.’
You could fix it to execute by inserting ‘with *’ in each of the places I mentioned.
08-07-2022 04:42 AM
LOAD CSV WITH HEADERS FROM "file:///kandidatpilpres_tesis3.csv" as nodes
create (n {name: nodes.vertex, type: nodes.Rela})
MERGE (tgt:Char0a {id: nodes.target})
MERGE (ver:Char0a {id: nodes.vertex})
match (y {type:"Tweet"})
set y:Tweet
match (x {type:"Mentions"})
set x:Mentions
match (z {type:"Replies_to"})
set z:Replies_to
MERGE (tgt)-[:Mentions]->(x)
MERGE (tgt)-[:Tweet]->(y)
MERGE (tgt)-[:Replies_to]->(z)
RETURN *
==============
yes, really refers to tgt,
I will try the instructions
==============
08-07-2022 04:54 AM
I want to make target relation to vertex with relation according to Rela1
I'm having trouble making this
08-07-2022 06:16 AM
You can try this if you want to use pure cypher:
load csv with headers from "file:///TargetVertexImport.csv" as row
merge(v:Vertx{name: row.vertex})
merge(t:Target{name: row.target})
with v, t, row
call{
with v, t, row
with v, t, row
where row.Rela1 = 'Mentions'
merge(t)-[:MENTIONS]->(v)
}
call{
with v, t, row
with v, t, row
where row.Rela1 = 'Replies_to'
merge(t)-[:REPLIES_TO]->(v)
}
Or try this, if you are ok with using the apoc library. The code is more compact and does not require a new call block for every different relationship type.
load csv with headers from "file:///TargetVertexImport.csv" as row
merge(v:Vertx{name: row.vertex})
merge(t:Target{name: row.target})
with t, v, row
call apoc.create.relationship(t, toUpper(row.Rela1), null, v) yield rel
return t.name, v.name, type(rel)
08-07-2022 06:43 AM
thank you very much
can run
All the sessions of the conference are now available online