cancel
Showing results for 
Search instead for 
Did you mean: 

Head's Up! These forums are read-only. All users and content have migrated. Please join us at community.neo4j.com.

how to make the syntax below correctly, I'm still having trouble making the proper syntax and correc

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 *

1 ACCEPTED SOLUTION

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)
}

Screen Shot 2022-08-07 at 9.04.30 AM.png 

Screen Shot 2022-08-07 at 9.04.36 AM.png

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)

Screen Shot 2022-08-07 at 9.14.42 AM.png

View solution in original post

5 REPLIES 5

glilienfield
Ninja
Ninja

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. 

 

https://neo4j.com/docs/cypher-manual/current/clauses/with/

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

==============

I want to make target relation to vertex with relation according to Rela1

IchsanALi_0-1659873184509.png

I'm having trouble making this

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)
}

Screen Shot 2022-08-07 at 9.04.30 AM.png 

Screen Shot 2022-08-07 at 9.04.36 AM.png

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)

Screen Shot 2022-08-07 at 9.14.42 AM.png

thank you very much

IchsanALi_0-1659879787447.png

can run