0

I am still rather new to Neo4j, Cypher and programming in general.

Is there a way to access the posted output below, i.e. access the "count" values for every "item“ (which has to be the pair), and also access the "item" values? I need the amount of how often a pair, i.e. specific neighboring nodes occur not only as information, but as values with which I can further work with in order to adjust my graph.

My last lines of code (in the preceding lines I just ordered the nodes sequentially):

...

WITH apoc.coll.pairs(a) as pairsOfa

WITH apoc.coll.frequencies(pairsOfa) AS giveBackFrequencyOfPairsOfa

UNWIND giveBackFrequencyOfPairsOfa AS x 

WITH DISTINCT x

RETURN x

Output from the Neo4j Browser that I need to work with:

"x"            


│{"count":1,"item":[{"aName“:"Rob","time":1},{"aName":"Edwin“,"time“:2}]},{„count“:4,“item":[{"aName":"Edwin","time":2},{"aName“:"Celesta","time":3}]} 

...
cybersam
  • 63,203
  • 6
  • 53
  • 76
CodeIsland
  • 61
  • 2
  • 10

1 Answers1

1

Based on your code, your result should contain multiple x records (not a single record, as implied by the "output" provided in your question). Here is an example of what I would expect:

╒══════════════════════════════════════════════════════════════════════╕
│"x"                                                                   │
╞══════════════════════════════════════════════════════════════════════╡
│{"count":1,"item":[{"aName":"Rob","time":1},{"aName":"Edwin","time":2}│
│]}                                                                    │
├──────────────────────────────────────────────────────────────────────┤
│{"count":1,"item":[{"aName":"Edwin","time":2},{"aName":"Celesta","time│
│":3}]}                                                                │
└──────────────────────────────────────────────────────────────────────┘ 

If that is true, then you can just access the count and item properties of each x directly via x.count and x.item. To get each value within an item, you could use x.item[0] and x.item[1].

Asides: you probably want to use apoc.coll.pairsMin instead of apoc.coll.pairs, to avoid the generation of a spurious "pair" (whose second element is null) when the number of values to be paired is odd. Also, you probably do not need the DISTINCT step.

cybersam
  • 63,203
  • 6
  • 53
  • 76
  • Thank you so very much! It is working. Such a simple solution that I just could not see yet. Now I can work from here :) – CodeIsland Jan 03 '19 at 09:07
  • Any chance you could help improve the OP's question? It's difficult to see this Q/A as very helpful to many others. – rickhg12hs Jan 03 '19 at 12:25
  • The question was really about the output - how to access "count" and "item" in the output; the output as was correctly given in cybersam's post. – CodeIsland Jan 03 '19 at 14:21