Head's Up! These forums are read-only. All users and content have migrated. Please join us at community.neo4j.com.
08-26-2022 04:13 AM
(new on graphs)
What is the best strategy finding all paths but if node with name BXX_1 in in the path only paths with node BXX_2 are valid paths. ( B13_1 then B13_2 needs to be in the path,..... )
The nodes are not neighbours.
And which strategy has the highest performance.
- do I tag a node B13_1 with property : NodeDepency : B13_2 and how to take this in account
- do I make a relationship between Node B13_1 and B13_2 and how to take this in account
Solved! Go to Solution.
08-26-2022 08:06 AM
I guess you could filter out the paths that don't meet your dependency criteria. Assuming you have a list of dependent node name, such as [["B13_1", "B13_2"], ["B12_1", "B12_2"]], then the following is an example of a predicate you can use to filter only the paths that meet your dependency criteria. PathNodesData is test data that represents the node names for two paths.
with [["a", "b"],["B13_1", "B13_2", "a", "c"]] as PathNodesData,
[["B13_1", "B13_2"], ["B12_1", "B12_2"]] as dependencies
unwind PathNodesData as PathNodes
with PathNodes, dependencies
where all(x in dependencies where ((not x[0] in PathNodes) OR ((x[0] in PathNodes) AND (x[1] in PathNodes))))
return PathNodes
Understanding that the OR operation is executed left-to-right and that the expression will stop evaluating if the first operand is true, the predicate can be safely sampled to:
where all(x in dependencies where ((not x[0] in PathNodes) OR (x[1] in PathNodes)))
You will have to investigate the performance if you require this over a large number of paths or a large number of dependencies.
08-26-2022 04:30 AM
08-26-2022 08:06 AM
I guess you could filter out the paths that don't meet your dependency criteria. Assuming you have a list of dependent node name, such as [["B13_1", "B13_2"], ["B12_1", "B12_2"]], then the following is an example of a predicate you can use to filter only the paths that meet your dependency criteria. PathNodesData is test data that represents the node names for two paths.
with [["a", "b"],["B13_1", "B13_2", "a", "c"]] as PathNodesData,
[["B13_1", "B13_2"], ["B12_1", "B12_2"]] as dependencies
unwind PathNodesData as PathNodes
with PathNodes, dependencies
where all(x in dependencies where ((not x[0] in PathNodes) OR ((x[0] in PathNodes) AND (x[1] in PathNodes))))
return PathNodes
Understanding that the OR operation is executed left-to-right and that the expression will stop evaluating if the first operand is true, the predicate can be safely sampled to:
where all(x in dependencies where ((not x[0] in PathNodes) OR (x[1] in PathNodes)))
You will have to investigate the performance if you require this over a large number of paths or a large number of dependencies.
08-28-2022 11:15 PM
08-28-2022 11:37 PM
Works perfectly
All the sessions of the conference are now available online