2017-10-26 4 views
2

私は有益な情報を保持する関係式を持つグラフを持っていますが、可視化のためにこれらの中間ノードを持たないサブグラフを作成する必要があります。トランジションエッジからサブグラフを作成するにはどうすればよいですか?

例:

[A:Person] <--AFFILIATE-- [B:Affiliation] --COMPANY--> [C:Org] 

そして、私はこのような部分グラフを生成します:

[A:Person] --AFFILIATED_TO--> [C:Org] 

がグレムリンとのことを取得する任意の簡単な方法はありますか?

答えて

5

通常、エッジ誘導サブグラフを抽出し、そのサブグラフのGremlinを実行して可視化エッジを導入し、不要なものを取り除くために、通常はsubgraph()ステップを使用することをお勧めします。

私はTinkerPopとともにパッケージ近代的なおもちゃのグラフで示すことができます:答えのための

gremlin> graph = TinkerFactory.createModern() 
==>tinkergraph[vertices:6 edges:6] 
gremlin> g = graph.traversal() 
==>graphtraversalsource[tinkergraph[vertices:6 edges:6], standard] 
gremlin> sg = g.V().outE('created').subgraph('sg').cap('sg').next() // subgraph creation 
==>tinkergraph[vertices:5 edges:4] 
gremlin> g = sg.traversal() 
==>graphtraversalsource[tinkergraph[vertices:5 edges:4], standard] 
gremlin> g.V().as('a').          // add special subgraph edge 
......1> out('created').as('software'). 
......2> in('created').where(neq('a')). 
......3> addE('co-developer').from('a'). 
......4>  property('project',select('software').by('name')) 
==>e[0][1-co-developer->4] 
==>e[1][1-co-developer->6] 
==>e[2][4-co-developer->1] 
==>e[3][4-co-developer->6] 
==>e[4][6-co-developer->1] 
==>e[5][6-co-developer->4] 
gremlin> g.V().hasLabel('software').drop() //remove junk from subgraph 
gremlin> g.E() 
==>e[0][1-co-developer->4] 
==>e[1][1-co-developer->6] 
==>e[2][4-co-developer->1] 
==>e[3][4-co-developer->6] 
==>e[4][6-co-developer->1] 
==>e[5][6-co-developer->4] 
gremlin> g.V().has('name','marko').outE('co-developer').valueMap(true) 
==>[label:co-developer,project:lop,id:0] 
==>[label:co-developer,project:lop,id:1] 
+0

感謝を。私はそれを試してみましょう。それは私が期待していたより少し簡単ではないが、確かにうまくいくだろう。 –

+0

私は、現在のようにもっと良い方法を考えることはできませんが、もっと簡単な方法があればうまくいくでしょう。これは一般的な使用例だと私は思います。私はもう少しそれについて考えるでしょう。 –

+0

エッジパターンに "エイリアス"を宣言し、エッジグラフ上にサブグラフをマップできるようにするのはすばらしいことです。 –

関連する問題