Gremlin 3在指定深度停止重复(java)

Bre*_*den 1 java gremlin tinkerpop

我想要一个在某个边缘类型上向下遍历的查询,直到它到达具有给定属性的顶点或者它到达起始顶点的给定距离.

当它碰到某个顶点类型时,我可以让这个遍历停止,但我不能让它停在给定的深度/距离.我使用"simplePath"和"count"步骤的方式一定有问题,但我不确定它是什么.

这是Java代码:

GraphTraversal<Vertex, TinkerGraph> traversal = g.V(start)
    .repeat(__.outE("type").subgraph("subGraph").inV())
    .until(
            __.or(
                //this line works just fine
                __.has("type", "one"),   
                //this line doesn't seem to do what I expect,
                //stop when the size of the path from "start" gets too long
                __.simplePath().count().is(P.gt(3))
            )
    )
    .cap("subGraph");
Run Code Online (Sandbox Code Playgroud)

那么当从"开始"顶点到当前顶点的路径大小大于3时,我需要做些什么来使这个遍历停止?

Dan*_*itz 6

如果您使用的是最新版本,则可以执行以下操作:

g.V(start).repeat(...)
          .until(has("type", "one").or().loops().is(gt(3)))
          .cap("subGraph")
Run Code Online (Sandbox Code Playgroud)

例子:

gremlin> g = TinkerFactory.createModern().traversal()
==>graphtraversalsource[tinkergraph[vertices:6 edges:6], standard]
gremlin> g.V(1).repeat(both().simplePath()).until(has("name","peter").or().loops().is(1)).path().by("name")
==>[marko, lop]
==>[marko, vadas]
==>[marko, josh]
gremlin> g.V(1).repeat(both().simplePath()).until(has("name","peter").or().loops().is(2)).path().by("name")
==>[marko, lop, josh]
==>[marko, lop, peter]
==>[marko, josh, ripple]
==>[marko, josh, lop]
gremlin> g.V(1).repeat(both().simplePath()).until(has("name","peter").or().loops().is(3)).path().by("name")
==>[marko, lop, peter]
==>[marko, lop, josh, ripple]
==>[marko, josh, lop, peter]
Run Code Online (Sandbox Code Playgroud)