graph-databases – 如何选择具有相同属性值的边

这是一个示例图

gremlin> v1 = graph.addVertex(id, 1, label,"cell_1")
gremlin> v2 = graph.addVertex(id, 2, label,"cell_2")
gremlin> v1.addEdge("test",v2,id,3,"srving_rsrp",20,"nbr_rsrp",30)
gremlin> v1.addEdge("test",v2,id,4,"srving_rsrp",30,"nbr_rsrp",30)
gremlin> v1.addEdge("test",v2,id,5,"srving_rsrp",10,"nbr_rsrp",40)

我需要获得“srving_rsrp”和“nbr_rsrp”具有相同值的优势.我无法找到适合它的好例子

这是我到达的地方;而不是每个我想使用过滤器来创建只有符合条件的边的图形.我正在使用Titan附带的Germlin shell(1.0.0-hadoop)

g.V(1).outE('test').each{  it.property('srving_rsrp').value == it.property('nbr_rsrp').value}

我可以用Python中的NetworK轻松完成这项工作;这是我想用Germlin实现的代码

G = nx.MultiDiGraph()  # Create a network Graph

G.add_edge(2,3, time=10,srvingcell=20,neighbourcell=50)
G.add_edge(2,3, time=20,srvingcell=30,neighbourcell=30)
G.add_edge(2,3, time=30,srvingcell=28,neighbourcell=40)
G.add_edge(2,3, time=5,srvingcell=27,neighbourcell=85)
G.edges(data=True)

cutoff = 25

SG=nx.Graph( [ (u,v,d) for u,v,d in G.edges(data=True) if d['srvingcell'] == d['neighbourcell']] )

SG.edges(data=True)

nx.write_gml(SG, "test.gml")

最佳答案 一个简单的答案就是改变你的每一个来过滤:

gremlin> g.V(1).outE('test').filter{  it.get().property('srving_rsrp').value == it.get().property('nbr_rsrp').value}
==>e[4][1-test->2]

但是使用lambda,如果可能的话最好避免使用lambda.我不确定以下是否适用于Gremlin 3.0.x(这是Titan 1.0.0所基于的),但你可以用这个去掉labmda:

gremlin> g.V(1).outE('test').as('x','y').
                filter(select('x','y').
                         by('srving_rsrp').by('nbr_rsrp').
                       where('x',eq('y')))
==>e[4][1-test->2]

您基本上向边缘提供两个标签“x”和“y”,然后应用过滤器.在过滤器中,选择“x”和“y”标签,对于“x”,您可以获取“srving_rsrp”属性值,对于“y”,您可以获取“nbr_rsrp”属性值并过滤那些它们是eq(等于).

这是TinkerPop食谱中讨论的Traversal Induced Values模式的一个例子.

更新:遍历诱导值在3.2.3中更加出色(截至本文撰写时尚未发布):

gremlin> g.V(1).outE('test').as('x','y').
                where('x',eq('y')).
                  by('srving_rsrp').by('nbr_rsrp')
==>e[4][1-test->2]

没有更讨厌的select().

点赞