我们有下面的图表。
gremlin> a = graph.addVertex("name", "alice")
==>v[4208]
gremlin> b = graph.addVertex("name", "bobby")
==>v[40968424]
gremlin> c = graph.addVertex("name", "cindy")
==>v[4192]
gremlin> d = graph.addVertex("name", "david")
==>v[40972520]
gremlin> e = graph.addVertex("name", "eliza")
==>v[40964272]
gremlin> a.addEdge("rates",b,"tag","ruby","value",9)
==>e[2ry-38w-azv9-oe3fs][4208-rates->40968424]
gremlin> b.addEdge("rates",c,"tag","ruby","value",8)
==>e[odzq5-oe3fs-azv9-38g][40968424-rates->4192]
gremlin> c.addEdge("rates",d,"tag","ruby","value",7)
==>e[170-38g-azv9-oe6lk][4192-rates->40972520]
gremlin> d.addEdge("rates",e,"tag","ruby","value",6)
==>e[oe04d-oe6lk-azv9-oe08g][40972520-rates->40964272]
gremlin> a.addEdge("rates",e,"tag","java","value",9)
==>e[366-38w-azv9-oe08g][4208-rates->40964272]
gremlin> g.E().values("tag")
==>ruby
==>ruby
==>ruby
==>ruby
==>java
gremlin> graph.tx().commit()
在脚本下面,我们可以获得所有路径的权重。
gremlin>g.V().has('name','alice').repeat(outE().has('tag','ruby').inV()).times(3).emit().group().by('name').by(path().unfold().has('value').values('value').fold()).next()
==>bobby=[9]
==>cindy=[8, 9, 8]
==>david=[8, 7, 9, 8, 7]
下面我们可以总结所有路径的权重。
gremlin>g.V().has('name','alice').repeat(outE().has('tag','ruby').inV()).times(3).emit().group().by('name').by(path().unfold().has('value').values('value').sum()).next()
==>bobby=9 sum[9]
==>cindy=25 sum[8, 9, 8]
==>david=39 sum[8, 7, 9, 8, 7]
我的问题是如何将权重与系数相加?像下面
==>bobby=[9] = 9*1
==>cindy=[8, 9, 8] = 8*1 + 9*0.5 + 8*0.25
==>david=[8, 7, 9, 8, 7] = 8*1 + 7*0.5 + 9*0.25 + 8*0.125 + 7*0.0625
另一个要求是系数是否来自边缘属性 co?
非常感谢您的帮助!