【问题标题】:Gremlin - find subgraph from specific starting pointsGremlin - 从特定起点查找子图
【发布时间】:2022-12-10 07:41:08
【问题描述】:

我在创建一个非常简单的查询时遇到问题:

让我们假设一个图,其中的节点代表人,边缘类型为“有孩子”。

我以一部分人为起点,我需要找到所有后代(递归)。更具体地说,我只对边缘感兴趣:

例子:

a -> b -> c
d -> b
(starting points = [c]) => []
(starting points = [b]) => [b->c]
(starting points = [a,b,c]) => [a->b, b->c]
(starting points = [d]) => [d->b, b->c]

到目前为止,我得到了这个查询:

g.V().has('name', 'something'). // this line gets replaced by various filters
repeat(outE('child').dedup().inV()).
until(
    outE('child').count().is(eq(0))
).
path(). // get all paths
unfold(). // flatten the list of lists
filter(hasLabel('child')). // filter out only edges
dedup()

但是,如果我们在同一路径上选择更多起点(例如可以通过执行 g.V().... 选择所有顶点),则此查询无法正常工作。

【问题讨论】:

  • 因此,为了澄清一下,您想取回在到达叶节点之前在起始顶点之间交叉的所有边的去重列表吗?
  • 我根据该假设添加了一个答案。

标签: database graph gremlin tinkerpop


【解决方案1】:

假设您想要取回起始顶点之间交叉的所有边的去重列表,直到到达叶节点,这样的查询将起作用:

g.V('start-id').
  repeat(outE().store('edges').inV()).
  until(not(out())).
  cap('edges').
  unfold().
  dedup()

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-12-20
    • 2014-05-15
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多