tinkerpop - Gremlin > recursively find nodes connected by an edge type -
just working tinkergraph, , attempting recursively find nodes connected specific edge label (in case created
).
- is there way can recursively(/loop) traverse nodes? in example below, want loop until there no more matching edges (instead of hardcoded
3
value). - is there anyway find , group connected vertices, given graph?
extra kudos deduplicating nodes, , handling node loops.
dependencies
compile("com.thinkaurelius.titan:titan-berkeleyje:0.5.4") compile('com.tinkerpop:gremlin-groovy:2.6.0')
code (manually recurse 3 times :( )
gremlin.load() def g = tinkergraphfactory.createtinkergraph() println g.v(5).as('x') .both('created') .dedup .loop(2){it.loops <= 3} .path .tolist().flatten() set // groovy code flatten & dedup
gives me: (correct)
[v[5], v[4], v[3], v[1], v[6]]
thanks!
you don't need groovy code, can done 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]
Comments
Post a Comment