my csv file has one header and data line in it;
Interfaces,Pathways
RootNode,Element1;Element2;Element3;Element4;
i need to build a root node that points to Element1, Element1->Element2, Element2->Element3, etc.. all the way down the list of elements..
the forEach (path in pathwayItem | section is what I am stuck on.. I know it is easy, when you know how. sigh.
Any chance of me, begging a few moments.. Thanks Guys for Helping me!
load csv with headers from "file:///Pathways.csv" as pathwayRow
with pathwayRow
ForEach(_ In Case When (pathwayRow.Interfaces Is not Null) Then [1] Else End|
merge (inter:Interface{type:"Interface", interface:pathwayRow.Interfaces, nType:trim("State")})
ForEach(_ In Case When (pathwayRow.Pathways Is not Null) Then [1] Else End|
ForEach(pathwayItem in split(pathwayRow.Pathways, ';') |
ForEach(_ IN CASE WHEN pathwayItem <> '' Then [1] Else End|
merge (pItem:PathItem{type:"PathItem", name:pathwayItem, nType:trim("State")})
forEach (path in pathwayItem |
merge (p:PathItem{name: path })
merge (pItem)-[:leadsTo]->(p)
)
)
)
)
)
Not knowing your exact data model and data, I made something up that shows you one technique for linking nodes. The core of the technique is to unwind a range of indexes so they you can access and link the nodes in the list in pairs.
load csv with headers from "file:///Book1.csv" as row
merge(rootNode:Node{name:row.node})
with rootNode, row
unwind split(row.element,";") as elementName
merge(element:Node{name:elementName})
with [rootNode] + collect(element) as nodesToLink
unwind range(0, size(nodesToLink)-2) as index
with nodesToLink[index] as a, nodesToLink[index+1] as b
merge(a)-[:LINKED_TO]->(b)
rats... something went wrong.. any idea?
I have the same csv contents, just had a different file name (Pathways.csv)...
but.. getting an error.. I am running desktop 1.5.7 and database is version 5.4.0..
Maybe that is the problem.. ?? Dont think so.. sorry man..
I believe at some point implicit aggregation was removed. I am using v4.4.17. I assume you are using a newer version that does not allow this.
This should fix that:
load csv with headers from "file:///Book1.csv" as row
merge(rootNode:Node{name:row.node})
with rootNode, row
unwind split(row.element,";") as elementName
merge(element:Node{name:elementName})
with rootNode, collect(element) as elements
with [rootNode] + elements as nodesToLink
unwind range(0, size(nodesToLink)-2) as index
with nodesToLink[index] as a, nodesToLink[index+1] as b
merge(a)-[:LINKED_TO]->(b)
for the fun of it.. lets say that element was a multiField.. you know something like... Element1-value1;Element2-value2 etc.. normally you would do a split on the '-' and create either another node, or some attribute in the Element node.. but how do you do something like that in this Syntax... you cant really do a merge (e1:Element{name:trim(split(x,'-')[0]), value:trim((split(x,'-')[1])}) see what I am asking.. ah.. any ideas? thanks And LAST QUESTION,you already have a been a Huge Help on Some Core Projects..
...
Sure, you can do exactly what you suggested. I just would not split the value twice, but perform it a 'with', so it can be used after.
load csv with headers from "file:///Book1.csv" as row
merge(rootNode:Node{name:row.node})
with rootNode, row
unwind split(row.element,";") as x
with rootNode, split(x,'-') as elementAttributes
merge(element:Node{name:elementAttributes[0], value:elementAttributes[1]})
with rootNode, collect(element) as elements
with [rootNode] + elements as nodesToLink
unwind range(0, size(nodesToLink)-2) as index
with nodesToLink[index] as a, nodesToLink[index+1] as b
merge(a)-[:LINKED_TO]->(b)
ah.. oh course.. sigh.. why didnt i see this.. sigh.. to many things on my plate.. sigh.. thanks man.. okay.. i think I have all the pieces now to built out this solution. Thanks Man!..
works GREAT!.. oh man.. thanks.. you have no idea how many research efforts at the national level you just helped out! you just made a real difference in .. a LOT of Efforts as I can use this mechanism on multiple fronts.. thanks man