2017-04-26 2 views
0

나는 다음과 같은 기본 사용 사례에 대한 neography를 사용하는 것을 시도하고있다,하지만 그것을 얻이 수없는 것 :neography를 사용하여 주어진 노드의 관계 유형과 노드를 찾는 방법은 무엇입니까?

주어진 노드에 대해
  1. 는 나에게 해당 노드에 대한 모든 연관 관계를 말한다.
  2. 주어진 노드와 특정 관계에 대해 해당 관계에있는 노드를 반환 하시겠습니까? 내가 들어오는있는 관련 관계를보고 싶어,

    def create_person(name) 
        Neography::Node.create("name" => name) 
    end 
    
    johnathan = create_person('Johnathan') 
    mark  = create_person('Mark') 
    phil  = create_person('Phil') 
    mary  = create_person('Mary') 
    luke  = create_person('Luke') 
    
    johnathan.both(:friends) << mark 
    

    첫째 :

    https://maxdemarzi.com/2012/01/04/getting-started-with-ruby-and-neo4j/ 나는 다음 코드를 시도 :

는 여기에서 예를 따랐다.

2.2.1 :060 > johnathan.incoming.relationships 
=> [{"type"=>"", "direction"=>"in"}] 

내 기대 "type"=>":friends"을 볼 수있을 것입니다하지만 난 그렇게하지 : 나는 relationships을 시도

johnathan.incoming 
=> #<Neography::NodeTraverser:0x0000000133f1c0 @from=#<Neography::Node name="Johnathan">, @order="depth first", @uniqueness="none", @relationships=[{"type"=>"", "direction"=>"in"}]> 

: 내 기대는 유형 :friends과의 관계를 보는 것입니다. 나는 다음을하려고 할 때이 관계가 무엇인지 사전에 알지 못하고 무엇인지 알고 싶어하기 때문에

하지만, 내가 할,하지만 내 사용 사례에 대해 작동하지 않습니다

2.2.1 :061 > johnathan.incoming(:friends).relationships 
=> [{"type"=>"friends", "direction"=>"in"}] 

두 번째 유스 케이스는 실제로 작동하는 노드를 검색하는 것입니다.

질문 : 주어진 노드와 관련된 관계 유형을 어떻게 얻을 수 있습니까?

나는 내가 그것을 알아내는 가까이라고 생각 :

johnathan.rels.map{|n| n}.first.rel_type 
=> "friends" 

답변

0

당신은 거의 오른쪽입니다. 이에 대한 문서는 기본적으로 https://github.com/maxdemarzi/neography/wiki/Phase-2-Node-relationships#retrieval-by-type의 바닥 만에있다 : 내가 아는 나에게 연결된 모든 관계 유형이 무엇인지 바로 얻을 수있는 방법은 없습니다

n1 = johnathan 

n1.rels       # Get node relationships 
n1.rels(:friends)     # Get friends relationships 
n1.rels(:friends).outgoing   # Get outgoing friends relationships 
n1.rels(:friends).incoming   # Get incoming friends relationships 
n1.rels(:friends, :work)   # Get friends and work relationships 
n1.rels(:friends, :work).outgoing # Get outgoing friends and work relationships 

,하지만 그건에 좋은 개선 될 것 Neo4j REST API N |

하는 기능은 자바 API에 존재

, https://neo4j.com/docs/java-reference/current/javadocs/org/neo4j/graphdb/Node.html#getRelationshipTypes--

+0

'n1.rels.map를 {참조 | n |'은 각 관계 오브젝트를 배열로 리턴합니다. 그래서 그것은 효과가있는 것처럼 보입니다. 감사. – Angela

관련 문제