Tinkerpop选择按顶点分组的多个邻居,它们是具有范围步长的邻居

问题描述

我想选择所有l个标记顶点以及按邻居分组的t,n个标记顶点。我也想对邻居的长度加以限制。对于ex为邻居限制= 2,应输出类似以下内容

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

对于ex对于邻居限制= 1,应该输出类似下面的内容

[
{"l1",{[n2]}}
]

关联链接https://gremlify.com/xun4v83y54/2

g.addV('Vertex').as('1').property(single,'name','l1').property(single,'label','l').
  addV('Vertex').as('2').property(single,'l2').property(single,'l').
  addV('Vertex').as('3').property(single,'l3').property(single,'l').
  addV('Tag').as('4').property(single,'t1').property(single,'t').
  addV('Tag').as('5').property(single,'t2').property(single,'t').
  addV('Tag').as('6').property(single,'t3').property(single,'t').
  addV('neighbour1').as('7').property(single,'n1').property(single,'n').
  addV('neighbour2').as('8').property(single,'n2').property(single,'n').
  addV('neighbour3').as('9').property(single,'n3').property(single,'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')

解决方法

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

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