2

我是 dse 图中的新手,我想创建 gremlin 查询,它为我提供从指定顶点链接的所有顶点的列表,但我想从这个列表中删除那些链接循环的列表。

e.g.

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

如果我有上述关系,那么我想要下面的顶点列表作为结果

[C,D]

B 和 A 不应该在上面的列表中,因为它有循环关系

我有以下两个单独的查询来查找所有链接的顶点并找到循环顶点

g.V().has('id','id').as('mainV').outE('Prerequisite').inV();

g.V().has('id','id').as('mainV').out().out().cyclicPath().path().unfold().dedup();

你能帮我找到准确的查询来满足我的要求吗?

4

2 回答 2

0

听起来您想使用 SimplePath。请参阅此处获取文档 - http://tinkerpop.apache.org/docs/current/reference/#simplepath-step

于 2016-12-22T15:08:02.013 回答
0

因此,您基本上想要过滤掉与特定顶点in具有边和边的顶点。out

这是您的示例图:

gremlin> g = TinkerGraph.open().traversal()
==>graphtraversalsource[tinkergraph[vertices:0 edges:0], standard]
gremlin> g.addV().property(id, "A").as("a").
......1>   addV().property(id, "B").as("b").
......2>   addV().property(id, "C").as("c").
......3>   addV().property(id, "D").as("d").
......4>   addE("link").from("a").to("b").
......5>   addE("link").from("a").to("c").
......6>   addE("link").from("a").to("d").
......7>   addE("link").from("b").to("a").iterate()

这是您正在寻找的遍历:

gremlin> g.V().as("a").not(out().out().where(eq("a"))).not(__.in().in().where(eq("a")))
==>v[C]
==>v[D]
于 2016-12-26T11:44:53.327 回答