在两个不相关的顶点之间添加边

时间:2016-05-24 08:29:36

标签: graph titan gremlin

这个问题涉及Gremlin 3.0.2(由于Titan还没有超越1.0.0,我已经接受了这个问题。)

我试图在没有(已知)关系且其Ids(即"键"?)事先未知的两个顶点之间远程添加边缘。 在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实现这一目标呢?

1 个答案:

答案 0 :(得分:3)

使用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以外的任何步骤标签。

参考:TinkerPop v3.0.1 AddEdge step

相关问题