Gremlin使用特定的开始和结束节点获取Edge

时间:2016-10-30 13:59:37

标签: java titan gremlin

我正在使用Gremlin来处理Titan Graph。 我正试图找到一种方式来建立一种非常具体的关系。

我有标签,属性以及可能的start和endNodes列表。

我希望所有的关系与此相匹配。

我已经有了这个以获得与标签和属性相匹配的所有关系:

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。 我不想在两个节点之间获得多个边缘。 我只想要一个具有特定顶点的边缘。

1 个答案:

答案 0 :(得分:4)

参见Between Vertices食谱,然后从那里延伸。例如,让我们说你想找到两个带有id 1和2的顶点之间的边。让我们进一步假设你只想要&#34;知道&#34;边缘有一个&#34;重量&#34;属性大于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]