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.

UNWIND a string(in form of list) and create nodes

Hi all, I am loading a csv which looks like this:
3X_b_2_b22cde96d3be3ffa49b3a66d254238007c6f4aaa.png

When loaded in graph, the 'OTHER_MEDS' column has a datatype of string ofcourse (but in form of a list ie: it looks like a list). I now want that each 'VAERS_ID' node should be mapped to the nodes which are all present in the corresponding 'OTHER_MEDS' column.

For eg:
the node '916623' (of label person) should be mapped to 'wellbutrin', 'vitamin d3', 'zinc sulphate', 'collagen' where all these are 4 different nodes of label medicine. I tried using UNWIND and FOREACH, but was unsuccesful.
Thank you in advance!

1 ACCEPTED SOLUTION

Hi @Benoit_d , I was able to create the nodes and relationships using these queries:

LOAD CSV WITH HEADERS FROM 'link' AS line
MATCH(adverse_event:Adverse_Event{name:line.VAERS_ID,AE_started_after:toInteger(line.NUMDAYS)})
WITH line.OTHER_MEDS as meds, adverse_event
WITH split(replace(replace(replace(meds,"', '",","),"['",''),"']",''),',') as meds1,adverse_event
UNWIND meds1 as x
MERGE(a:Other_Product{name:x})
CREATE (adverse_event)-[:previous]->(a)

Thank you for your help!

View solution in original post

3 REPLIES 3

Benoit_d
Graph Buddy

Hi Abhisshek,

You have to eliminate the brakets and the apostrophe using regreplace. Then you can use split.
As there is a space between comma and next entry, you might need to remove this space first

with "('levothyroxine', 'phentermine', 'lithium', 'abilify lamictal')" as a
with apoc.text.split(
    apoc.text.regreplace (
        apoc.text.replace(a, "', '", "','"), 
        "[()\']",
        ""), 
    ",") as c
return c

c is then a list.

Hi Benoit, thank you for your answer! After obtaining the list, how can I create the nodes from that list? And also, how can I link 'VAERS_ID' to the nodes created through the list?

For the reference, it should look like this:
(will be doing this for every 'VAERS_ID)

Hi @Benoit_d , I was able to create the nodes and relationships using these queries:

LOAD CSV WITH HEADERS FROM 'link' AS line
MATCH(adverse_event:Adverse_Event{name:line.VAERS_ID,AE_started_after:toInteger(line.NUMDAYS)})
WITH line.OTHER_MEDS as meds, adverse_event
WITH split(replace(replace(replace(meds,"', '",","),"['",''),"']",''),',') as meds1,adverse_event
UNWIND meds1 as x
MERGE(a:Other_Product{name:x})
CREATE (adverse_event)-[:previous]->(a)

Thank you for your help!