如何使用Gremlin计算具有某个属性的顶点百分比

3
我试图使用单个Gremlin查询来确定满足某个条件的顶点的百分比,但我在存储和传播计算值时遇到了问题。
假设我想计算所有标记为"A"并具有标记为"B"的出边的顶点的百分比。我可以在同一个查询中打印出标记为"A"的顶点数量,以及具有标记为"B"的出边的顶点数量:
g.V().limit(1).project("total","withEdgeB")
 .by(g.V().hasLabel("A").count())
 .by(g.V().hasLabel("A").match(__.as("a").outE("B").inV()).dedup().count())

这给了我两个相关的值:totalwithEdgeB。如何使用这些值进行传播和计算?
理想情况下,我希望得到这样的结果:
g.V().limit(1).project("total","withEdgeB","percentage")
 .by(g.V().hasLabel("A").count().as("totalA"))
 .by(g.V().hasLabel("A").match(__.as("a").outE("B").inV()).dedup().count().as("totalWithEdgeB"))
 .by(totalWithEdgeB / totalA)

我的问题是,我如何在第三个by()语句中访问totalAtotalWithEdgeB的值?或者我做错了什么?

1个回答

1
我会使用一些简单的计算。使用现代图表,找到所有具有出站created边缘的person顶点:
gremlin> g.V().hasLabel('person').
           choose(outE('created'),
                    constant(1),
                    constant(0)).fold().
           project('total','withCreated','percentage').
             by(count(local)).
             by(sum(local)).
             by(mean(local))
==>[total:4,withCreated:3,percentage:0.75]

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接