遍历时修改顶点属性

Modifying vertex properties while traversing

我想在 JanusGraph 中使用 Gremlin some 属性 修改 JanusGraph 中通过边连接的所有顶点 some label =21=]。我尝试了以下方法:

public void setAllProperties(JanusGraphTransaction janusGraphTransaction) {
    GraphTraversal<Vertex, Vertex> traversal = janusGraphTransaction.traversal().V();
    traversal.has("SomeLabel", "SomeProperty", 0)
            .repeat(out("SomeEdgeLabel"))
            .property("SomeProperty", true)
            .until(outE("SomeEdgeLabel").count().is(0));
}

但是没有修改任何顶点。我尝试使用谷歌搜索修改属性,同时使用 repeat... until 但没有成功。有什么建议吗?

首先,我认为您需要 iterate() 您的遍历 - 请参阅 tutorial - 因此:

public void setAllProperties(JanusGraphTransaction janusGraphTransaction) {
    GraphTraversal<Vertex, Vertex> traversal = janusGraphTransaction.traversal().V();
    traversal.has("SomeLabel", "SomeProperty", 0)
            .repeat(out("SomeEdgeLabel"))
            .property("SomeProperty", true)
            .until(outE("SomeEdgeLabel").count().is(0)).iterate();
}

然后,将property()移到repeat():

public void setAllProperties(JanusGraphTransaction janusGraphTransaction) {
    GraphTraversal<Vertex, Vertex> traversal = janusGraphTransaction.traversal().V();
    traversal.has("SomeLabel", "SomeProperty", 0)
            .repeat(out("SomeEdgeLabel").property("SomeProperty", true))
            .until(outE("SomeEdgeLabel").count().is(0)).iterate();
}

property() 不是 Map 步骤的一种类型 - 它只是通过 Vertex,因此您的遍历继续工作。