【问题标题】:Tinkerpop Select multiple neighbours grouped by the vertex they are neighbour with range stepTinkerpop 选择按顶点分组的多个邻居,它们是具有范围步长的邻居
【发布时间】:2020-08-28 08:25:44
【问题描述】:

我想选择所有 l 个标记的顶点以及它们的 t,n 个标记的顶点,这些顶点按它们的邻居分组。我还想对邻居的长度施加限制。对于 ex for neighbor limit = 2,应该输出类似下面的内容。

[
{"l1",{[t1,t2]}, {}},
{"l2",{[t3]}, {[n1]}},
{"l3",{[]}, {[n2,n3]}}
]

对于 ex for neighbor limit = 1,应该输出类似下面的内容。

[
{"l1",{[t1,t2]}, {}},
{"l2",{[t3]}, {[n1]}},
{"l3",{[]}, {[n2]}}
]

grelify 链接https://gremlify.com/xun4v83y54/2

g.addV('Vertex').as('1').property(single, 'name', 'l1').property(single, 'label', 'l').
  addV('Vertex').as('2').property(single, 'name', 'l2').property(single, 'label', 'l').
  addV('Vertex').as('3').property(single, 'name', 'l3').property(single, 'label', 'l').
  addV('Tag').as('4').property(single, 'name', 't1').property(single, 'label', 't').
  addV('Tag').as('5').property(single, 'name', 't2').property(single, 'label', 't').
  addV('Tag').as('6').property(single, 'name', 't3').property(single, 'label', 't').
  addV('neighbour1').as('7').property(single, 'name', 'n1').property(single, 'label', 'n').
  addV('neighbour2').as('8').property(single, 'name', 'n2').property(single, 'label', 'n').
  addV('neighbour3').as('9').property(single, 'name', 'n3').property(single, 'label', 'n').
  addE('connected').from('1').to('4').
  addE('connected').from('1').to('5').
  addE('connected').from('2').to('6').
  addE('connected').from('2').to('7').
  addE('connected').from('3').to('8')
  addE('connected').from('3').to('9')

【问题讨论】:

    标签: gremlin tinkerpop tinkerpop3 gremlin-server tinkergraph


    【解决方案1】:

    对于此输出,您可以尝试执行以下操作:

    g.V().hasLabel('l').
      group().by('name').
        by(out('connected').fold()
          project('t', 'n').
            by(unfold().hasLabel('t').limit(1).values('name').fold()).
            by(unfold().hasLabel('n').limit(1).values('name').fold())
            .unfold().select(values).fold())
    

    您可以将限制更改为您希望每种类型的最大邻居数。

    示例:https://gremlify.com/ecw6j2ajh5p

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-01-29
      • 2019-10-20
      • 2021-12-30
      相关资源
      最近更新 更多