2016-09-14 50 views
4

的值相同邊緣下面是一個例子圖如何選擇具有屬性

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」具有同等價值的邊緣。我無法找到一個合適的示例

這就是我已經達到的地方;而不是每個我想用一個過濾器來創建一個只有符合條件的邊的圖。我使用它自帶的泰坦(1.0.0-Hadoop的)Germlin殼

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

我能夠與網絡在Python做到這一點很容易;下面是該代碼,我想用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") 
+0

您有興趣尋找相匹配的屬性的任何邊緣繪製寬,或只有邊緣有一個共同頂點和匹配性的例子嗎? –

+0

基本上我想過濾掉不符合規則/匹配條件的邊 –

回答

2

簡單的回答是隻改變來實現你的eachfilter

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和它最好如果可能的話避免這些我不知道下面會與小鬼3.0.x的(這是泰坦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模式的一個例子。

UPDATE:穿越誘導值甚至在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()

0

在使用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 
相關問題