遍历时修改顶点属性

时间:2018-08-02 14:12:43

标签: gremlin tinkerpop janusgraph

我想使用Java中的Gremlin修改JanusGraph中通过具有 some label 的边连接的所有顶点的 some property 。我尝试了以下方法:

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 ...直到遍历时使用谷歌搜索来修改属性,但没有成功。有什么建议吗?

1 个答案:

答案 0 :(得分:1)

首先,我认为您需要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传递给您,因此遍历仍然有效。

相关问题