【问题标题】:Gremlin query to find k distance verticesGremlin 查询以查找 k 个距离顶点
【发布时间】:2018-03-20 06:47:06
【问题描述】:

我试图运行一个 gremlin 查询以从给定顶点 v 中找到 k 个距离顶点,并省略与 v 直接连接的顶点。

我正在使用 Gremlin 3.2.6。

所以,对于 k 距离(朋友的朋友)来说,这样的事情不能正常工作

g.V(v).both().as(“x”).repeat(both()).times(k).where(neq("x")).dedup()

上面应该省略“x”中的顶点,但事实并非如此。 我的图是有向的,一对顶点之间可能有两个方向的边。

另外,我如何使用循环(很难使用它)对给定距离小于一些 k 进行通用化,并且有什么方法可以将距离与顶点列表一起打印。谢谢。

【问题讨论】:

    标签: gremlin breadth-first-search tinkerpop3 janusgraph


    【解决方案1】:

    x 实际上应该是所有相邻顶点的聚合,而不仅仅是对当前路径上相邻顶点的引用。

    gremlin> g = TinkerFactory.createModern().traversal()
    ==>graphtraversalsource[tinkergraph[vertices:6 edges:6], standard]
    gremlin> g.V(1).both().aggregate("x").
               repeat(both().dedup()).
                 times(5).
                 emit().
               where(without("x"))
    ==>v[1]
    ==>v[6]
    ==>v[5]
    

    如果您还想排除起始顶点,只需将其添加到集合中:

    gremlin> g.V(1).store("x").
               both().aggregate("x").
               repeat(both().dedup()).
                 times(5).
                 emit().
               where(without("x"))
    ==>v[6]
    ==>v[5]
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2019-06-02
      • 2012-10-31
      • 2020-08-13
      • 1970-01-01
      • 2015-07-06
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多