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

标签 graph titan gremlin

这个问题涉及 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 之外的任何步骤标签。

引用:TinkerPop v3.0.1 AddEdge step

关于graph - 在两个不相关的顶点之间添加边,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37408196/

相关文章:

python - Matplotlib 绘制数百个矩形轮廓

java - Titan Graph 数据迁移

java - 泰坦警告 : Query requires iterating over all vertices [(name <> null)]

python - gremlin-python : what is a valid vertex custom id?

gremlin - 使用 Gremlin 选择不同的节点?

gremlin - AWS Neptune 事务支持

java - 如何在graphview中的X轴上设置固定水平标签(Android Studio)

android - 使用 GraphView 库的 BarChartGraph 中的空白区域

python - RexProScriptException 事务未在带有 Titan(图形数据库)的 Django 中打开

java - Java 中用于显示数据的简单可视化库