首页 > 解决方案 > TinkerPop:按边缘计数过滤

问题描述

样本数据:TinkerPop 现代

摘要:我想找到创建了 2 个软件的人。

我从基础开始,并正确计算

g.V().hasLabel("Person").as("from" ,"to1" )
.repeat(bothE().as("e1").otherV().as("to1").dedup("from", "to1")).times(1)
.emit(filter(hasLabel("Software"))).hasLabel("Software")
.group().by(select("from").by("name")).by(count()).as("c")

结果:

>> {'Marko': 1, 'Peter': 1, 'Josh': 2}

所以我尝试应用过滤器但它不起作用(即结果不正确),我尝试了什么:

g.V().hasLabel("Person").as("from")
.repeat(bothE().as("e1").otherV().as("to1").dedup("from", "to1")).times(1)
.filter(bothE().otherV().hasLabel("Software").count(local).is(eq(1)))
.dedup()
.values("name")

知道我在做什么错吗?


样本数据:

在此处输入图像描述

标签: gremlintinkerpop3

解决方案


如果您只需要按边数计算“人”顶点,我真的不明白为什么您需要所有这些repeat()基础设施。只是:

gremlin> g.V().hasLabel('person').
......1>   filter(outE('created').limit(2).count().is(2))
==>v[4]

您只需要计算出边,因为架构是这样的,“创建”标签仅连接到“软件”,因此您不需要检查“软件”顶点标签。您limit(2)要尽快退出边缘迭代,但不要在您尝试计算 2 条边缘之前退出。


推荐阅读