Graph 如何用小精灵脚本替换边缘

Graph 如何用小精灵脚本替换边缘,graph,gremlin,titan,Graph,Gremlin,Titan,我想寻找一个顶点,获取一条边“视图”,删除它,并在相同顶点之间替换为一条新边 g.V('uuid','bf4dcbd24e9944319954dec5ad60c658') .inE('views') .sideEffect{g.addEdge(it.outV.next(),it.inV.next(),'likes')} .sideEffect{g.removeEdge(it)} 这是可行的,但这是最好的方法吗?重命名边缘是一个选项?修复了queston eddit之前的第一个错误 完成

我想寻找一个顶点,获取一条边“视图”,删除它,并在相同顶点之间替换为一条新边

g.V('uuid','bf4dcbd24e9944319954dec5ad60c658')  
.inE('views')
.sideEffect{g.addEdge(it.outV.next(),it.inV.next(),'likes')}
.sideEffect{g.removeEdge(it)}

这是可行的,但这是最好的方法吗?重命名边缘是一个选项?

修复了queston eddit之前的第一个错误


完成

g.V('uuid','bf4dcbd24e9944319954dec5ad60c658') 
.inE('views')
.sideEffect{g.addEdge(it.outV.next(),it.inV.next(),'likes')}

.next()修复了脚本。

您可以像以前一样使用副作用。这种方法具有直截了当和易于理解的积极方面。然而,我个人对“生产”Gremlin代码的偏好是在可用时使用显式Gremlin函数。在这种情况下,我看到了使用“链接”和“步骤闭包”()的机会:


在上面,我将g.v(1)的所有“已知”边“重命名”为“swonk”

考虑使用“链接”而不是副作用:我编辑了问题和问题,你介意看一下吗?谢谢
gremlin> g = TinkerGraphFactory.createTinkerGraph()
==>tinkergraph[vertices:6 edges:6]
gremlin> g.E
==>e[10][4-created->5]
==>e[7][1-knows->2]
==>e[9][1-created->3]
==>e[8][1-knows->4]
==>e[11][4-created->3]
==>e[12][6-created->3]
gremlin> g.v(1).as('x').outE('knows').as('toRemove').inV.except('x').linkIn('swonk','x').sideEffect{v,m->g.removeEdge(m.toRemove)} 
==>v[2]
==>v[4]
gremlin> g.E
==>e[1][1-swonk->4]
==>e[10][4-created->5]
==>e[0][1-swonk->2]
==>e[9][1-created->3]
==>e[11][4-created->3]
==>e[12][6-created->3]