Graph Can';t遍历到Gremlin中具有唯一属性的顶点

Graph Can';t遍历到Gremlin中具有唯一属性的顶点,graph,gremlin,tinkerpop,Graph,Gremlin,Tinkerpop,我正在寻找从一个顶点到另一个顶点的路径,避免在该路径上已经匹配属性的顶点 考虑这个例子: Graph graph = TinkerGraph.open(); GraphTraversalSource t = graph.traversal(); Vertex A = t.addV().property("age", 19).next(); Vertex B = t.addV().property("age", 21).next(); Vertex C

我正在寻找从一个顶点到另一个顶点的路径,避免在该路径上已经匹配属性的顶点

考虑这个例子:

    Graph graph = TinkerGraph.open();

    GraphTraversalSource t = graph.traversal();

    Vertex A = t.addV().property("age", 19).next();
    Vertex B = t.addV().property("age", 21).next();
    Vertex C = t.addV().property("age", 20).next();
    Vertex D = t.addV().property("age", 21).next();
    Vertex E = t.addV().property("age", 22).next();

    t.V(A).addE("knows").to(B).iterate();
    t.V(B).addE("knows").to(C).iterate();
    t.V(C).addE("knows").to(D).iterate();
    t.V(D).addE("knows").to(E).iterate();
    t.V(C).addE("knows").to(E).iterate();

    List<Path> paths = t.V(A)
            .repeat(
                    out()
            ).times(5).emit()
            .has("age", 22).path().toList();

    Assert.assertEquals(1, paths.size());
Graph-Graph=TinkerGraph.open();
GraphTraversalSource t=graph.traversal();
顶点A=t.addV().property(“age”,19).next();
顶点B=t.addV().property(“age”,21).next();
顶点C=t.addV().property(“age”,20).next();
顶点D=t.addV().property(“age”,21).next();
顶点E=t.addV().property(“age”,22).next();
t、 V(A)在(B)中添加(“知道”)。迭代();
t、 V(B)在(C)中添加(“知道”)。迭代();
t、 V(C).在(D)中添加(“知道”)。迭代();
t、 V(D).在(E)中添加(“知道”)。迭代();
t、 V(C).在(E).迭代()中添加(“知道”);
列表路径=t.V(A)
.重复(
out()
).times(5).emit()
.has(“age”,22).path().toList();
Assert.assertEquals(1,path.size());
我正在寻找从A到E的方法。有两条路径:

A->B->C->D->E A->B->C->E

我要找的只是第二条,因为在第一条路径中,B和D的年龄相同

我尝试使用as和by进行过滤,但未能将其扩展到整个路径。例如,我可以通过执行以下操作来检查顶点是否与第一个顶点的属性不匹配:

    List<Path> paths = t.V(A).as("first")
            .repeat(
                    out()
                    .where(P.neq("first")).by("age")
            ).times(5).emit()
            .has("age", 22).path().toList();

    Assert.assertEquals(1, paths.size());
List path=t.V(A).as(“第一个”)
.重复(
out()
其中(P.neq(“第一”)。按(“年龄”)
).times(5).emit()
.has(“age”,22).path().toList();
Assert.assertEquals(1,path.size());

但是,你可以想象,它不会过滤路径中间的碰撞。我觉得应该有一个更简单的方法来做这件事,我错过了。是否有类似于as()的语句,但它不是替换上一个赋值,而是将它们保留在数组或其他内容中?我怎样才能做到这一点


谢谢

您需要将当前的
年龄
与之前看到的
年龄
进行比较。如果存在任何匹配项,则让遍历器死亡:

t.V(A).as("a").
  repeat(filter(loops().is(lt(5))).out().
         not(values("age").as("current").         /* current age   */
               select(all, "a").unfold().         /* previous ages */
               values("age").
                 where(eq("current"))).as("a")).  /* not() negates the match */
    until(has("age", 22)).
  path()