图表如下:
gremlin> a = graph.addVertex("name", "alice")
gremlin> b = graph.addVertex("name", "bobby")
gremlin> c = graph.addVertex("name", "cindy")
gremlin> d = graph.addVertex("name", "david")
gremlin> e = graph.addVertex("name", "eliza")
gremlin> a.addEdge("rates",b,"tag","ruby","value",9)
gremlin> b.addEdge("rates",c,"tag","ruby","value",8)
gremlin> c.addEdge("rates",d,"tag","ruby","value",7)
gremlin> d.addEdge("rates",e,"tag","ruby","value",6)
gremlin> e.addEdge("rates",a,"tag","java","value",10)
我有以下 3 个脚本:
脚本 #1
gremlin> g.V().has('name','alice').
repeat(out()).
until(has('name','alice')).
cyclicPath().
path().by('name')`
==>[alice,bobby,cindy,david,eliza,alice]
脚本 #2
gremlin> g.V().has('name','alice').
repeat(outE().inV()).
until(has('name','alice')).
cyclicPath().
group().
by('name').
by(path().unfold().has('value').values('value').fold()).
next()
==>alice=[9, 8, 7, 6, 10]
脚本 #3
gremlin> g.V().has('name','alice').
repeat(outE().inV()).
until(has('name','alice')).
cyclicPath().
group().
by('name').
by(path().unfold().has('value').values('value').fold()).
next().collect { k, v ->
k + '=' + v.withIndex().collect { Integer it, Integer idx ->
return it * (1/(idx + 1))
}.inject(0.0) { acc,i -> acc + i }
}
==>alice=18.8333333331
我的问题是,我怎样才能得到下面列出的结果?只需结合 3
alice=[alice,bobby,cindy,david,eliza,alice]=[9, 8, 7, 6, 10]=18.8333333331