Jul 8, 2018 - 2 minute read - Comments - recommendation

Tinkerpop Gremlin Aggregate


The aggregate()-step (sideEffect) is used to aggregate all the objects at a particular point of traversal into a Collection. The step uses eager evaluation in that no objects continue on until all previous objects have been fully aggregated (as opposed to store()which lazily fills a collection). The eager evaluation nature is crucial in situations where everything at a particular point is required for future computation. An example is provided below.

aggregate() - step(sideEffect) は、特定のトラバーサルポイントにあるすべてのオブジェクトをCollectionに集約するために使用されます。 このステップでは、すべての以前のオブジェクトが完全に集約されるまでオブジェクトが継続しないという熱心な評価が使用されます(store() とは対照的に、コレクションを遅延して埋め込みます)。 熱心な評価の性質は、特定のポイントのすべてが将来の計算に必要とされる状況では重要です。 以下に例を示します。

    gremlin> g.V(1).out('created') //1\
    gremlin> g.V(1).out('created').aggregate('x') //2\
    gremlin> g.V(1).out('created').aggregate('x').in('created') //3\
    gremlin> g.V(1).out('created').aggregate('x').in('created').out('created') //4\
    gremlin> g.V(1).out('created').aggregate('x').in('created').out('created').
                    where(without('x')).values('name') //5\
  1. What has marko created?
  2. Aggregate all his creations.
  3. Who are marko’s collaborators?
  4. What have marko’s collaborators created?
  5. What have marko’s collaborators created that he hasn’t created?

In recommendation systems, the above pattern is used:

“What has userA liked? Who else has liked those things? What have they liked that userA hasn’t already liked?”


Finally, aggregate()-step can be modulated via by()-projection.

最後に、aggregate() - stepはby() - 投影によって調整することができます。

    gremlin> g.V().out('knows').aggregate('x').cap('x')
    gremlin> g.V().out('knows').aggregate('x').by('name').cap('x')

Your Account Has Been Flagged Recommendation

comments powered by Disqus