格雷姆林>递归查找由边类型连接的节点 [英] Gremlin > recursively find nodes connected by an edge type

查看:60
本文介绍了格雷姆林>递归查找由边类型连接的节点的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

只需使用 TinkerGraph ,然后尝试递归地找到节点通过特定的边缘标签(在本例中为 created )连接.

Just working with the TinkerGraph, and attempting to recursively find nodes connected by a specific edge label (in this case created).

  1. 有没有一种方法可以递归(/循环)遍历节点?在下面的示例中,我想循环播放,直到不再有匹配的边(而不是硬编码的 3 值)为止.
  2. 在给定图形的情况下,是否仍然可以找到并分组连接的顶点?

对节点进行重复数据删除和处理节点循环的额外荣誉.

Extra kudos for deduplicating nodes, and handling node loops.

compile("com.thinkaurelius.titan:titan-berkeleyje:0.5.4")
compile('com.tinkerpop:gremlin-groovy:2.6.0')

代码(手动递归3次:()

Gremlin.load()
def g = TinkerGraphFactory.createTinkerGraph()
println g.v(5).as('x')
    .both('created')
    .dedup
    .loop(2){it.loops <= 3}
    .path
    .toList().flatten() as Set // groovy code to flatten & dedup

给我:(正确)

[v[5], v[4], v[3], v[1], v[6]]

谢谢!

推荐答案

您不需要任何Groovy代码,只需使用Gremlin即可完成:

You don't need any Groovy code, it can be done by only using Gremlin:

gremlin> g.v(5).as('x').both('created').dedup()
gremlin>     .loop('x') {true} {true}.dedup()
==>v[4]
==>v[3]
==>v[5]
==>v[6]
==>v[1]

这篇关于格雷姆林&gt;递归查找由边类型连接的节点的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆