How to group counts for ends of a graph

What I want to do is hard to explain
I am trying to sum the count of edges on a node in the middle of a graph but to have the aggregate for unique sets of end points.
Here is a query

  g(func: type(Theme)){


That returns

  "data": {
    "g": [
        "": "test theme",
        "search": [
            "querystring": "improving",
            "result": [
                "count(result.context)": 1,
                "document": [
                    "": 2443317

What I want to do is add up the number count(result.context) for each theme and doc, so a theme has 3 searches that all point to the same doc I want the total result.context for that theme on that doc.

Hope that makes sense. Any ideas?

I wrote a function to "normalize deep nested objects like this…

So you did it in the app rather than through the query? That is my backup plan. But If there is a way I can do it just with the query that would be super cool.

Thanks for the idea though.

my plan to use this is currently in progress, but it will be client side with a thought about maybe putting it in a lambda function.