[英]How to find all paths up to specific length among pairs contained in a set of N vertices with Gremlin
我想將N個頂點作為輸入,然后我想返回那些N個頂點中所有對之間的特定長度的所有路徑。 怎么能在Gremlin做到這一點?
一些解釋 - 有這個圖(在路徑中表示):
(n)-[r1]-(n1)-[r2]-(n2)-[r3]-(m)-[r5]-(n3)
(y)-[r4]-(n1)-[r2]-(n2)-[r3]-(m)-[r6]-(n4)
() node
-[]- relation
例如,這些應該是(n,m,y)中長度為3的路徑
(n)-[r1]-(n1)-[r2]-(n2)-[r3]-(m)
(y)-[r4]-(n1)-[r2]-(n2)-[r3]-(m)
(n)-[r1]-(n1)-[r2]-(n1)-[r4]-(y)
這是我的2個頂點的Gremlin示例:
g = new OrientGraph("remote:localhost/graphdb")
v = g.v('#12:110')
y = g.v('#12:109')
hops = 3
v
.as('looop')
.inE.has('label','EdgeClass')
.outV.has('@class','NodeClass')
.outE.has('label','EdgeClass')
.inV.except([v]).dedup()
.loop('looop'){it.loops<hops}{it.object.rid==y.rid}.path
謝謝
這是使用Tinkergraph玩具圖的示例:
gremlin> vertices = g.v(2,3,5).toSet()
==>v[2]
==>v[3]
==>v[5]
gremlin> vertices._().as("x").bothE().bothV().simplePath().loop("x") {it.loops <= 3} {it.object in vertices}.simplePath().path() {it} {it.label}
==>[v[2], knows, v[1], created, v[3]]
==>[v[2], knows, v[1], knows, v[4], created, v[3]]
==>[v[2], knows, v[1], knows, v[4], created, v[5]]
==>[v[3], created, v[4], created, v[5]]
==>[v[3], created, v[1], knows, v[2]]
==>[v[3], created, v[4], knows, v[1], knows, v[2]]
==>[v[3], created, v[1], knows, v[4], created, v[5]]
==>[v[5], created, v[4], created, v[3]]
==>[v[5], created, v[4], knows, v[1], created, v[3]]
==>[v[5], created, v[4], knows, v[1], knows, v[2]]
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.