0
我想沿着给定的边缘关系去除一组顶点及其所有后代。在我的情况,图中有一些顶点,其类型为会议,和其他类型为事件。从事件到会话的弧线有标签in_session。删除泰坦图中的后代
似乎有没有快速的方法在一个通做到这一点。这里是我使用的代码:
// First, select all event descendants of sessions with r < 700
GraphTraversal<Vertex, Vertex> t = g.V()
.has("type", "session")
.has("r", P.lt(700))
.in("in_session");
// And remove those events
while (t.hasNext())
t.next().remove();
// Then, using the first part of the query again,
// select the same sessions as before
t = g.V().has("type", "session").has("r", P.lt(700));
// And delete them as well
while (t.hasNext())
t.next().remove();
对我来说这似乎很笨拙。此外,如果我想删除低层次的后代,我必须写更多的重复步骤(一直到底部,然后删除,然后备份一个级别,然后删除,然后再次备份一个级别,等等。 ..)。另外我注意到TitanGraph中没有removeVertex方法。
我用GV()。具有( “类型”, “会话”)。具有( “R”,P.lt(700))。sideEffect(在( “in_session”)。降())。降( )但没有顶点被删除。另外drop()没有记录在thinkerpop javadoc中。 – Totem
第一个'drop()'是GraphTraversal类中的一个方法。请参阅http://tinkerpop.apache.org/docs/current/reference/#drop-step - 接下来你必须遍历你的遍历(控制台为你做),所以如果你正在用java写代码,你必须终止用'iterate()'遍历 - 见http://tinkerpop.apache.org/docs/current/tutorials/the-gremlin-console/#result-iteration –