【问题标题】:Modifying vertex properties while traversing遍历时修改顶点属性
【发布时间】:2018-08-02 14:12:43
【问题描述】:

我想使用 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... until 但没有任何成功。有什么建议吗?

【问题讨论】:

    标签: gremlin tinkerpop janusgraph


    【解决方案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,因此您的遍历继续工作。

    【讨论】:

    • 如果我发出顶点然后在流/列表中修改它们,它会起作用,但顶点的数量会非常大 - 它们不适合内存。这就是我需要在遍历时编辑它们的方式。
    • 根据您的评论更新了答案。我想这就是你想要的。我认为在这种情况下你也可以放弃until()
    猜你喜欢
    • 1970-01-01
    • 2018-04-03
    • 2010-10-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-05-12
    • 1970-01-01
    相关资源
    最近更新 更多