【发布时间】:2018-07-05 16:18:55
【问题描述】:
我将列表存储为图表中某些边的属性值,类似于问题asked here。这个问题的解决方案是在 JavaScript 中给出的,但我正在寻找一种在 Python 中做同样事情的方法。
另外,请注意 Amazon Neptune 不支持 Lambda steps,因此该解决方案不能使用 lambda。
【问题讨论】:
标签: python gremlin tinkerpop3 amazon-neptune
我将列表存储为图表中某些边的属性值,类似于问题asked here。这个问题的解决方案是在 JavaScript 中给出的,但我正在寻找一种在 Python 中做同样事情的方法。
另外,请注意 Amazon Neptune 不支持 Lambda steps,因此该解决方案不能使用 lambda。
【问题讨论】:
标签: python gremlin tinkerpop3 amazon-neptune
我不确定这对您来说是否仍然是一个问题,但我想知道这是否对您不起作用:
gremlin> g = TinkerGraph.open().traversal()
==>graphtraversalsource[tinkergraph[vertices:0 edges:0], standard]
gremlin> g.addV('person').as('a').addE('self').to('a').property('x',[1,2,3]).select('a').addE('self').to('a').property('x',[10,20,30]).iterate()
gremlin> g.E().valueMap(true)
==>[x:[1,2,3],id:3,label:self]
==>[x:[10,20,30],id:4,label:self]
gremlin> g.V().outE('self').filter(local(values('x').unfold().is(2))).valueMap(true)
==>[x:[1,2,3],id:3,label:self]
基本上,您可以对列表属性进行local() 展开,然后对其进行过滤。 Neptune 可能不会优化此过滤器(例如,使用索引),但如果您不过滤大量边缘,它可能是一个足够的解决方法(如果它有效)。
请注意,我在 Groovy 中编写了以上内容以便于测试。在 Python 中,您必须注意围绕命名冲突的某些小的语法修改。因此,最后一次遍历在python中会这样写(因为is是python中的保留字):
g.V().outE('self').filter(local(values('x').unfold().is_(2))).valueMap(true)
【讨论】: