v2 =...">

How to select edges with the same attribute value

Here is an example graph

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)

I need to get an edge where "srving_rsrp" and "nbr_rsrp" have the same value. I can not find a good example that suits him

I got here; Instead of each of them, I would like to use a filter to create a graph with only edges that match the criteria. I use the Germlin shell that comes with Titan (1.0.0-hadoop)

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

I can do this easily with NetworK in Python; Here is the code for this that I want to achieve with 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")
+4
source share
2 answers

A simple answer would be to simply change yours eachto filter:

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

, , . , 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 ().

Traversal Induced Values ​​, TinkerPop Recipes.

: , , 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().

+2

Scala , Groovy ;

val v0 = graph + "cell_1"
val v2 = graph + "cell_2"
val v3 = graph + "cell_3"

val srving_rsrp = Key[Int]("srving_rsrp")
val nbr_rsrp = Key[Int]("nbr_rsrp")

//v0.addEdge("test",v2,T.id,3,"srving_rsrp",20,"nbr_rsrp",30)
//v0.addEdge("test",v2,T.id,4,"srving_rsrp",30,"nbr_rsrp",30)
//v0.addEdge("test",v2,T.id,5,"srving_rsrp",10,"nbr_rsrp",40)

// create edge with typed properties
v0 ---("test", srving_rsrp → 20, nbr_rsrp → 30) --> v2
v0 ---("test", srving_rsrp → 30, nbr_rsrp → 30) --> v2
v0 ---("test", srving_rsrp → 10, nbr_rsrp → 40) --> v2

//v2.addEdge("test",v3,T.id,6,"srving_rsrp",40,"nbr_rsrp",40)
//v2.addEdge("test",v3,T.id,7,"srving_rsrp",15,"nbr_rsrp",45)

v2 ---("test", srving_rsrp → 40, nbr_rsrp → 40) --> v3
v2 ---("test", srving_rsrp → 15, nbr_rsrp → 45) --> v3

//v3.addEdge("test",v2,T.id,8,"srving_rsrp",15,"nbr_rsrp",15)

v3 ---("test", srving_rsrp → 15, nbr_rsrp → 15) --> v2

val g = graph.traversal()
println(v0.outE("test").value(nbr_rsrp).head)
val r = graph.V.outE.filter { it: Edge =>
  (it.property(nbr_rsrp).value() == it.property(srving_rsrp).value())
}
println("value= " + r.count().head()) --> result is 3
0

Source: https://habr.com/ru/post/1654553/


All Articles