gpt4 book ai didi

python - 顶点列表中的边 - gremlin python

转载 作者:太空宇宙 更新时间:2023-11-04 00:18:50 24 4
gpt4 key购买 nike

我有一个顶点 ID 列表。我想获得它们之间所有可能的边缘。

我理解像 filter/where 这样的方法在这里会有帮助,但由于我使用的是 gremlin-python,它们的实现必须不同。

我试过了:

a = [0,2,4,6,8,10]

g.V(a).outE().inV().hasId(a).toList()
# This gives me []

g.V(a).bothE().filter(otherV().hasId(a)).toSet()
# Traceback otherV is not defined

g.V(a).bothE().otherV().hasId(a).toList()
# This gives me []

# Some information on edges :
g.E().toList()
# [e[16][0-Likes->8], e[17][8-Likes->0], e[18][4-Likes->8], e[19][2-Likes->6], e[20][6-Likes->2], e[21][12-Likes->10], e[22][10-Likes->12], e[23][10-Likes->14], e[24][14-Likes->8], e[25][6-Likes->4]]

我怎样才能做到这一点?这似乎是一个简单的问题,但我仍然坚持不懈。

最佳答案

有多种方法可以做到这一点 - 这个怎么样?

gremlin> a = ['marko','josh','lop']
==>marko
==>josh
==>lop
gremlin> g.V().has('name',within(a)).
......1> aggregate('a').
......2> outE().
......3> filter(inV().where(within('a')))
==>e[9][1-created->3]
==>e[8][1-knows->4]
==>e[11][4-created->3]

这使用了 modern以 TinkerPop 玩具图为例。首先,我们找到那些起始顶点并将它们聚合到一个名为“a”的列表副作用中。然后,我们遍历每个出边并过滤它们以匹配“a”中的那些顶点。

关于python - 顶点列表中的边 - gremlin python,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49897933/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com