这个问题涉及 Gremlin 3.0.2(我必须回答这个问题,因为 Titan 还没有超越 1.0.0)。
我正在尝试在没有(已知)关系且其 ID(即“键”?)事先未知的两个顶点之间远程添加边。 而在 Gremlin 3.2 中,只需这样做
:> g.V().has('propertykey', 'value1').as('o').V().has('propertykey','value2').addE('edgelabel').to('o')
这让我陷入了 Gremlin 3.0.2 的困境。到目前为止我尝试过的(:
:> g.V().has('propertykey', 'value1').next().addOutE('edgelabel', g.V().has('propertykey', 'value2').next())
失败并显示消息
No signature of method: com.thinkaurelius.titan.graphdb.vertices.CacheVertex.addOutE() is applicable for argument types: (java.lang.String, com.thinkaurelius.titan.graphdb.vertices.CacheVertex, java.lang.String, java.lang.String) values: [edgelabel, v[24776]]
如果将addOutE
的第二个参数更改为g.V(24776).next()
,也会出现相同的错误消息。查看 AddEdge 的方法签名,可以发现它需要一个字符串作为第二个顶点的键,但是
> g.V().has('fbid', 'fbid_13').next().addOutE('edgelabel', '24776')
也失败了,说明
No signature of method: com.thinkaurelius.titan.graphdb.vertices.CacheVertex.addOutE() is applicable for argument types: (java.lang.String, java.lang.String, java.lang.String, java.lang.String) values: [edgelabel, 24776]
那么如何使用 Gremlin 3.0.2 实现这一目标呢?
最佳答案
使用 TinkerPop v3.0.1(与 Titan v1.0.0 捆绑)时,需要使用 withSideEffect
步骤。
:> g.withSideEffect('x', g.V().has('propertykey', 'value1')).V().has('propertykey', 'value2').addOutE('edgeLabel', 'x')
您可以自由使用除 x
之外的任何步骤标签。
关于graph - 在两个不相关的顶点之间添加边,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37408196/