【问题标题】:Edges among a list of vertices - gremlin python顶点列表中的边 - gremlin python
【发布时间】:2018-04-18 10:54:42
【问题描述】:

我有一个顶点 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]]

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

【问题讨论】:

    标签: python gremlin tinkerpop gremlin-server gremlinpython


    【解决方案1】:

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

    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”中的那些顶点。

    【讨论】:

    • 因为我使用的是 gremlin-python。此语句中有一个错误:NameError: name 'inV' is not defined(在 ..3> 行中)同样,within 未定义
    • Gremlin 就是 Gremlin。除了特定的语言语法差异外,您使用的语言无关紧要(例如,python 将 in 视为保留字,因此对于 Gremlin 而言,它是 in_)。在您的情况下,我认为您只需要获得正确的进口 - 请参阅此处列出的进口:tinkerpop.apache.org/docs/current/reference/#gremlin-python
    • 更具体一点,inV() 只是 __.inV() 的缩写,within() 只是 P.within() 的缩写。对于python,如果您想使用与我上面相同的语法,您只需将它们分配给inV = __.inV之类的函数
    • __.inV() 有效,但 withinP.within__.within 无效
    • 您是说您仍然收到“未定义内部”的错误吗?还是其他错误?如果您仍然遇到“未定义”问题,我不确定可能出了什么问题:github.com/apache/tinkerpop/blob/3.3.2/gremlin-python/src/main/…
    猜你喜欢
    • 1970-01-01
    • 2021-04-20
    • 1970-01-01
    • 2023-03-26
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-11-24
    相关资源
    最近更新 更多