我正在使用Gremlin处理Titan Graph。而且我正在设法找到一种非常具体的关系。
我有标签,属性以及可能的start和endNode列表。
我希望所有关系都与此相匹配。
我已经有了这个来获取所有匹配标签和属性的关系:
GraphTraversal<Edge, Edge> tempOutput = g.E().hasLabel(relationshipStorage.getId());
if(relationshipStorage.getProperties() != null)
{
for (Map.Entry<String, Object> entry : relationshipStorage.getProperties().entrySet())
{
if (tempOutput == null)
{
break;
}
tempOutput = tempOutput.has(entry.getKey(), entry.getValue());
}
}
但是我没有找到使用特定的start和endNode来获得它的方法。我不想在两个节点之间有多个边缘。我只想要具有特定顶点的一条边。
请参见“顶点间”配方,然后从那里开始进行扩展。例如,假设您要查找ID为1和2的两个顶点之间的边。进一步假设您只想“权重”属性大于0.0的“知道”边。
gremlin> graph = TinkerFactory.createModern()
==>tinkergraph[vertices:6 edges:6]
gremlin> g = graph.traversal()
==>graphtraversalsource[tinkergraph[vertices:6 edges:6], standard]
gremlin> g.V(1).bothE().where(otherV().hasId(2)).hasLabel('knows').has('weight',gt(0.0))
==>e[7][1-knows->2]
gremlin> g.V(1,2).bothE().where(inV().has(id, within(2,3))).hasLabel('created')
==>e[9][1-created->3]
gremlin> vStarts = g.V(1,2).toList().toArray()
==>v[1]
==>v[2]
gremlin> vEnds = g.V(2,3).toList().toArray()
==>v[2]
==>v[3]
gremlin> g.V(vStarts).bothE().where(inV().is(within(vEnds))).hasLabel('created')
==>e[9][1-created->3]
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句