如何使用 Gremlin 在一组 N 个顶点中包含的对中找到所有路径达到特定长度

How to find all paths up to specific length among pairs contained in a set of N vertices with Gremlin

我想将 N 个顶点作为输入,然后我想 return 在这 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]]