2017-10-26 16 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

가장자리 패턴에서 "별칭"을 선언하고 그 위에 부분 그래프를 매핑 할 수 있습니다. –