For what it's worth, this question was discussed/answered in the gremlin-users group here:
https://groups.google.com/forum/?fromgroups=&hl=en#!topic/gremlin-users/N9NYG-aBrvw
سؤال
I have a graph with dependencies:
dep1 -> dep2 -> ... -> dep3 -> ...
| ^
+-> dep4 |
| |
+-------------------+
I'm looking for unnecessary dependencies, which are those where a direct link exists, but also a link through a sub-dependency. In the above example, the link "dep1 -> dep3" is unnecessary.
The cypher statement to find those would be:
start n = node(*)
match n -[:dependency]-> n2,
n -[:dependency*2..]-> n2
with n, n2
return distinct id(n), n.name, id(n2), n2.name
I tried to solve this issue with a single gremlin statement (with the "table"-step), but I just couldn't make it work. Is this even possible or do I have to solve this with multiple statements?
Any hints, tips, ideas would be appreciated.
Thanks in advance
المحلول
For what it's worth, this question was discussed/answered in the gremlin-users group here:
https://groups.google.com/forum/?fromgroups=&hl=en#!topic/gremlin-users/N9NYG-aBrvw
نصائح أخرى
Thanks to Marko and Stephen we came up with this solution:
g.V.transform{
s-> singleStep = [];
s.as('origin')
.out('dependency').aggregate(singleStep)
.out('dependency')
.loop(1){ true }{ true }
.retain(singleStep).as('redundant')
.dedup()
.table(new Table(), ['origin', 'redundant']){ it.name + '(' + it.id + ')' }
.cap().next()
}.filter{ it.size() > 0 }