This issue is directly related to the previous post:
How to calculate rank for float values in Neo4j?
I am trying to merge the "rank" and "weight" values with origin and path. I could successfully do this for origin:
CALL
apoc.load.json("file:///.../input.json") YIELD value
UNWIND value.origin AS orig
MATCH(origin:concept{name:orig.label}) WITH value, collect(origin) as
origins
UNWIND value.target AS tar MATCH(target:concept{name:tar.label})
UNWIND origins AS origin WITH origin, target
CALL apoc.algo.dijkstra(origin, target, 'link', 'Weight') yield path as
path, weight as weight
WITH origin, path, weight ORDER BY weight ASC WITH {origin: origin, weight:
collect(weight)} AS SuggestionForOrigin UNWIND [r in range(1,
SIZE(SuggestionForOrigin.weight)) | {origin: SuggestionForOrigin.origin,
rank:r, weight: SuggestionForOrigin.weight[r-1]}] AS suggestion RETURN
suggestion
Then I get the following result (which is satisfying for me):
{"origin": {"name": "A","type": "string"},"rank": 1,"weight": 0.0}
{"origin": {"name": "A","type": "string"},"rank": 2,"weight":
0.6180339887498948}
{"origin": {"name": "P1","type": "string"},"rank": 1,"weight":
0.6180339887498948}
{"origin": {"name": "P1","type": "string"},"rank": 2,"weight":
1.2360679774997896}
But when I am trying to merge "path" parameter, I am getting into trouble. I think, I overcompensate the things. Something what I would like to achieve is (not exactly, but to be able to combine "path" with appropriate "weight"):
{"origin": {....}, "path": {...}, "rank": 1,"weight": 0.0}
And this need to be related to a particular origin node, if I have 3 paths suggestions for the first origin, they need to be combined together. What I#ve tried, but it doesn't work as I want is:
...
CALL apoc.algo.dijkstra(origin, target, 'link', 'Weight') yield path as
path, weight
WITH {origin: origin, path: collect(path), weight: collect(weight)} AS
SuggestionForOrigin
UNWIND [r in range(1, SIZE(SuggestionForOrigin.weight)) | {rank:r, weight:
SuggestionForOrigin.weight[r-1], path: SuggestionForOrigin}] AS suggestion
WITH {origin: SuggestionForOrigin.origin, suggestions: collect(suggestion)
[0..3]} AS output
RETURN output
I would appreciate, if you could help.