Head's Up! These forums are read-only. All users and content have migrated. Please join us at community.neo4j.com.
10-05-2021 12:40 AM
I have a text property and some have an "-->" in it. I want to replace this arrow with a Cause relation and split this one node in two nodes and delete the original one afterwards. Here you can see the query:
</ ```
MATCH (n:FMEA) WHERE n.text='Voids in Poly-S and therefore uncontrollable shape of field plate --> Yb loss' and n.nickname='PLASMA ETCH TRENCH' and n.technology='SMART6_80V_8' and n.cell='Effect' and n.PID='1572 (measure 1963)'
create (firstNode:FMEA {nickname:n.nickname,PID:n.PID,technology:n.technology,text:'Voids in Poly-S and therefore uncontrollable shape of field plate',clean_text:'',cell:n.cell, label:'FMEA'})-[:CAUSES{nickname:n.nickname,PID:n.PID,technology:n.technology}]-> (lastnod:FMEA {nickname:n.nickname,PID:n.PID,technology:n.technology,text:'Yb loss',clean_text:'',cell:n.cell, label:'FMEA'})
with n,firstNode,lastnod
match (head)-[:CAUSES]->(n)
with n,firstNode,lastnod,head
unwind [head] as h
create (h)-[:CAUSES{nickname:n.nickname,PID:n.PID,technology:n.technology}]->(firstNode)
with n,firstNode,lastnod,head
match (n)-
[:CAUSES]->(tail)
with n,firstNode,lastnod,head,tail
unwind [tail] as t
create (lastnod)-[:CAUSES{nickname:n.nickname,PID:n.PID,technology:n.technology}]->(t)
with n,firstNode,lastnod,head,tail
DETACH DELETE n
The query gives me following output: Added 2 labels, created 2 nodes, set 20 properties, created 2 relationships, completed after 579 ms
Thanks in advance!
10-14-2021 08:41 AM
If I understand correctly, let's suppose you have a simple dataset like this:
CREATE (:Node {text: 'foo-->bar', otherProp: 'other'})
CREATE (:Node {text: 'aaaaa-->eeeee', otherProp: 'iii'})
you can split this nodes in 2 nodes (in this example StartNode
and EndNode
) in this way, using the split function:
MATCH (n:Node)
WHERE n.text contains "-->"
WITH n
WITH split(n.text, "-->") as splits, n
CREATE (start:StartNode {text : splits[0]})-[:CAUSE]->(end:EndNode {text : splits[1]})
//set start += properties(n), end += properties(n)
//with start, end
//remove start.text, end.text
DELETE n
Note that the commented rows add all original properties except for text
property of (:Node)
into StartNode
and EndNode
. I don't know if is it is necessary in your case.
With the last row, I remove original nodes.
So, in this case, I receive 4 nodes and 2 rels, that is:
(:StartNode {text: 'foo'})-[:CAUSE]->(:EndNode {text: 'bar'})
(:StartNode {text: 'aaaaa'})-[:CAUSE]->(:EndNode {text: 'eeeee'})
All the sessions of the conference are now available online