2016-10-30 17 views
0

私はGremlinを使用してTitan Graphを処理しています。 そして、私は非常に特定の関係を得る方法を見つけようとしています。Gremlin特定の開始ノードと終了ノードを持つエッジを取得

ラベル、プロパティ、および可能な開始ノードと終了ノードのリストがあります。

そして、私はこれに一致するすべての関係が欲しいです。

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()); 
       } 
      } 

しかし、私は特定の開始とエンドノードでそれを取得する方法を見つけることができませんでした:

私は、これはすでにすべての関係の一致するラベルや財産を取得する必要があります。 私は2つのノードの間に複数のエッジを取得したくありません。 私は、特定の頂点で1つの辺のみを必要とします。

答えて

3

Between Verticesのレシピを参照してください。たとえば、2つの頂点の間にids 1と2を持つ辺を見つけたいとしましょう。さらに、 "weight"プロパティが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] 
+0

このようなものがありますか? ArrayList nodeStartList = getVertexList(relationshipStorage.getStartNode()、g); ArrayList nodeEndList = getVertexList(relationshipStorage.getEndNode()、g); GraphTraversal tempOutput = g.V(nodeStartList).bothE()。ここで(g.V(nodeEndList))。hasLabel(relationshipStorage.getId()); – user2524707

+1

確かに - そのレシピにモデルがあります。答えを少し更新しました... –

+0

ありがとう、どのようにしてinVを取得し、java内でですか? – user2524707

関連する問題