简体   繁体   English

使用gremlin-python过滤列表的边缘作为属性值

[英]Filter edges with a list as the property value using gremlin-python

I'm storing a list as the property value of some edges in my graph, similar to the question asked here . 我将一个列表存储为图形中某些边的属性值,类似于此处的问题。 The solution to that question was given in JavaScript, but I'm looking for a way to do the same thing in Python. 这个问题的解决方案是用JavaScript给出的,但是我正在寻找一种用Python做同样的事情的方法。

Also, note that Amazon Neptune doesn't support Lambda steps , so the solution can't use lambdas. 另外,请注意,Amazon Neptune不支持Lambda 步骤 ,因此该解决方案不能使用lambda。

I'm not sure if this is still an issue to you or not, but I wonder if this wouldn't work for you: 我不确定这是否仍然是您的问题,但我想知道这是否对您不起作用:

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]

Basically you could do a local() unfolding of your list property and then filter on that. 基本上,您可以对list属性进行local()展开,然后对其进行过滤。 Neptune likely won't optimize this filter (eg use an index) but if you aren't filtering a large number of edges it might be a sufficient workaround (if it works). Neptune可能不会优化此过滤器(例如使用索引),但是如果您不过滤大量边缘,则可能是一个足够的解决方法(如果可行)。

Note that I wrote the above in Groovy so as to test it easily. 请注意,我在Groovy中编写了以上内容,以便对其进行轻松测试。 In Python, you must pay attention to certain minor syntax modifications around naming conflicts. 在Python中,您必须注意围绕命名冲突的某些较小的语法修改。 Therefore, the last traversal there would be written like this in python (because is is a reserved word in python): 因此,最后穿越那里将用Python写的是这样的(因为is在Python保留字):

g.V().outE('self').filter(local(values('x').unfold().is_(2))).valueMap(true)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM