Please sir.. sometimes windows apps (word) inserts leading and trailing spaces into my dataset..
Using your code;
with row where row is not null with row, split(row,";") as items with row, head(items) as parent, tail(items) as children with row, split(parent,"|") as parentItems, [i in children | split(i,"|")] as childItems
*with *
row, head(parentItems) as parentLabel, *
apoc.map.fromPairs([i in tail(parentItems)|split(i,"-")]) as parentMap, *
childItems* call apoc.merge.node([parentLabel], parentMap) yield node with row, node as parentNode, childItems unwind childItems as child
*with *
row, parentNode,*
head(child) as childLabel, *
apoc.map.fromPairs([i in tail(child)|split(i,"-")]) as childMap* call apoc. merge.node([childLabel], childMap) yield node merge (parentNode)-[:HAS_CHILD]->(node) with parentNode match (n) return n
how do I introduce a trim(xxxx) into these data elements such as parentMap and childMap.. I can do a [trim(parentLabel)] for the label and that should work.. but.. tail(parentItems) and tail(child) ?? ah.. ?? does this question, make sense sir? Thanks Captain!
Try this. I updated four lines to apply "trim" an each label, key, and value extracted from 'row'.
with " ParentNodeLabel | ParntAttrName1 - ParntAttrValue1 | ParntAttrName2 -ParntAttrValue2 ;ChildNode1Label | AttrName1.1- AttrValue1.1|AttrName1.2 - AttrValue1.2 ;ChildNode2Label|AttrName2.1-AttrValue2.1 | AttrName2.2 - AttrValue2.2 | AttrName3.2 - AttrValue3.2 " as row
with split(row,";") as items
with head(items) as parent, tail(items) as children
with split(parent,"|") as parentItems, [i in children | split(i,"|")] as childItems
with
trim(head(parentItems)) as parentLabel,
apoc.map.fromPairs([j in [i in tail(parentItems)|split(i,"-")]|[k in j|trim(k)]]) as parentMap,
childItems
call apoc.create.node([parentLabel], parentMap) yield node
with node as parentNode, childItems
unwind childItems as child
with
parentNode,
trim(head(child)) as childLabel,
apoc.map.fromPairs([j in [i in tail(child)|split(i,"-")]|[k in j|trim(k)]]) as childMap
call apoc.create.node([childLabel], childMap) yield node
create(parentNode)-[r:HAS_CHILD]->(node)
return parentNode, r, node as childNodee
And because of your kindness and huge amount of help.. I will get some this weekend.. Thanks man.. even my dog will be happy.. Actually I am thinking, daring to think anyhow, of taking two hours of vacation today and not working the entire weekend.. so.. thanks man
you have a good weekend sir.. thanks man for helping me!