TinkerPop:按边数过滤

时间:2018-04-30 10:14:32

标签: gremlin tinkerpop3

示例数据:TinkerPop Modern

总结:我想找到创建了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")

知道我做错了什么吗?

示例数据:

enter image description here

1 个答案:

答案 0 :(得分:1)

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

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

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

相关问题