获取特定标签的子节点列表,深度为n级。

huangapple go评论53阅读模式
英文:

Gremlin: get a list of child nodes of a certain label n-levels deep

问题

我正在努力找出正确的命令。

从给定的节点开始,我想要获取特定标签的所有子节点,深度为n级。

例如:

假设我们从标签为'A'的节点开始。

A有类型为B或C的子节点(深度为1级)。

这些子节点B或C可以有类型为D或E的子节点(深度为2级)。

这些子节点可能再次有相同类型的子节点D或E,依此类推(深度为3+级)。

我想提取所有类型为E的节点,这些节点距离A为2级深度,即不考虑它们的子节点,这些子节点可能也是类型为E的(深度为3+级)。

感谢任何帮助!

我猜命令的起始部分将是 g.V('A')

编辑:请查看Kelvin的解决方案-对我来说很有效。

英文:

i'm struggling to figure out the correct command here.

Starting from a given node I would like to get all child nodes of a certain label n-levels deep

e.g.

imagine we start at a node with label 'A'.

A has child nodes of type B or C (1 level deep)

These child nodes B or C can have children of type D or E (2 levels deep)

These child nodes can again have further child nodes of the same type D or E and so on (3+ levels deep)

I would like to extract all nodes of type E that are 2 levels deep from A i.e., not look at their children that are 3+ levels deep that could also be of type E

Thanks for any help!

I guess the starting part of the command would be g.V('A')

Edit: See Kelvin's solution - that did the trick for me.

答案1

得分: 0

在其最简单的形式下,查找距离给定起始节点 2 跳的所有节点,这些节点具有特定标签,就像这样简单:

g.V('A').repeat(out()).times(2).hasLabel('E')
英文:

In its simplest form, finding all nodes, 2 hops away from a given start, that have a specific label is as simple as:

g.V('A').repeat(out()).times(2).hasLabel('E')

huangapple
  • 本文由 发表于 2023年6月19日 20:14:16
  • 转载请务必保留本文链接:https://go.coder-hub.com/76506520.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定