Head's Up! These forums are read-only. All users and content have migrated. Please join us at community.neo4j.com.
12-12-2020 07:37 AM
My graph is a simple tree structure that has a root node (inode:0) and then has various branches off the tree. Some of these are 1000 levels deep. My graph shows "CALLS" as well as "RUNS" but we only need to worry about "RUNS" ( Calls drop off much faster)
I have been using the number parameter on the match [*3] but when we run larger programs, it gets slower and slower. Not to mention that the UI folks get a bit annoying when you start at a node in level 3 and need to see 3-5.
I have written a python to a) get the longest chain. b) work up from the bottom to the top and assign that a level.
But that seems terribly clumsy. Fortunately, the graph is relatively static in terms of structure. Attributes change but not structure.
Is there a clever way to do this within Cypher ? Assign each node a level based on the distance from 0 ?
12-15-2020 06:23 AM
Some followup information as requested.
Thanks - Any help would be good.
12-18-2020 07:23 AM
Any thoughts ? Thanks
12-18-2020 09:03 AM
Assign each node a level based on the distance from 0 ?
Sounds good to me, if the distance to the root is pretty static.
Do the work once on insertion instead of on every MATCH.
12-18-2020 10:35 AM
I can't do it on insertion. They come from different sources so literally as each file processes it only knows its parent and its child. So doing it up front is not practical. My current approach sets them all to the max, and then does a count down **200, **199, **198 etc etc which is wickedly in efficient.
My alternative was to go path by path and update the nodes in succession but that doesn't work well either.
I'm looking for a more neo4j ish approach. Thanks
12-18-2020 11:27 AM
I see. But are the insertions completely arbitrary (meaning the node and its parent node possibly float around in isolation), or is the node a new node connects to already connected to the root node (through others)?
In which case a new node could inherit the level of its parent node and increment it.
12-19-2020 01:02 AM
Hi Bill,
Interesting problem I have a question. How do you decide a level associated with a node? This is a bit ambiguous to me as two nodes can either be at same level or different levels, how do you decide which node should be placed at what level ? Thanks in advance.
12-19-2020 06:16 AM
We have one “tree” that is balanced ( one parent to one child ) fairly well. The “RUNS” relationship is very structured. Other relationships are less balanced and that’s ok - this is the only one we need.
We are following the direction -> always
Thanks
12-19-2020 09:52 PM
Bill,
So one node can only have a maximum of two children connected by :RUNS relationship?
12-20-2020 06:42 AM
Sorry - I said that badly
It can have lots of Children but one parent. And siblings are unconnected
12-20-2020 03:52 PM
Hi Bill,
This link by @mark.needham can help you in solving the problem.
Link: https://markhneedham.com/blog/2014/04/19/neo4j-cypher-creating-a-time-tree-down-to-the-day/
Cheers
12-21-2020 07:35 AM
Thanks - I don’t see the relevance and that’s quite possibly because the design is so different. Can you help me understand how they connect ? Thanks
All the sessions of the conference are now available online