foreach - Neo4j: Split string and get position -


i need split field in different values , store each value in different node. each created node want store position. example:

sentence             words car red        my;car;is;red 

using:

foreach (w in split(line.twords, ";") |  merge (wd:word {word: w}) 

i can split field , store different words, i'd store position on relationship.

my car red  -[has_word {position:1}]-> my car red  -[has_word {position:2}]-> car car red  -[has_word {position:3}]-> car red  -[has_word {position:4}]-> red 

how can this?

solution

using periodic commit load csv headers  'file:///output_2016-05-06_0203_neo4jimport.csv' line fieldterminator "\t"  merge (s:segment{text: line.source}) merge (ta:segment{text: line.target})  split(line.swords, ";") swords, line, s, ta unwind range(0, size(swords)-1)     merge (s)-[r:has_word {position:i+1}]->(w:word {word: swords[i]})  split(line.twords, ";") twords, line, ta unwind range(0, size(twords)-1)     merge (ta)-[r:has_word {position:i+1}]->(w:word {word: twords[i]}) 

be sure fist with has variable references necessary in second with: with split(line.swords, ";") swords, line, s, ta

you can use range based on size of split, assuming node containing sentence identified sentence :

with split(line.twords, ';') splitted unwind range(0, size(splitted) -1) merge (w:word {word: splitted[i]}) merge (sentence)-[:has_word {position: i}]->(w) 

update

using periodic commit load csv headers  'file:///output_2016-05-06_0203_neo4jimport.csv'  line fieldterminator "\t"  merge (s:segment{text: line.source})  split(line.swords, ";") swords, line  unwind range(0, size(swords)-1)  merge (s)-[r:has_word {position:i+1}]->(w:word {word: swords[i]})  

Comments

Popular posts from this blog

javascript - Laravel datatable invalid JSON response -

java - Exception in thread "main" org.springframework.context.ApplicationContextException: Unable to start embedded container; -

sql server 2008 - My Sql Code Get An Error Of Msg 245, Level 16, State 1, Line 1 Conversion failed when converting the varchar value '8:45 AM' to data type int -