2017-04-26 42 views
0

我一直在嘗試使用neography以下基本的使用情況,但似乎無法得到它的工作:如何使用neography查找給定節點的關係類型和節點?

  1. 對於給定的節點,告訴我該節點的關聯關係。
  2. 對於給定的節點和特定的關係,返回該關係中的一個或多個節點?

我跟着從這裏的例子:https://maxdemarzi.com/2012/01/04/getting-started-with-ruby-and-neo4j/

我嘗試下面的代碼:

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 

首先,我想看看相關的關係,這是對進入。我的期望是看到與:friends類型的關係:

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

我試圖relationships

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

我的預期是看到"type"=>":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。

的功能Java API中的存在,看到https://neo4j.com/docs/java-reference/current/javadocs/org/neo4j/graphdb/Node.html#getRelationshipTypes--

+0

'n1.rels.map {| N | n |'返回一個數組中的每個關係對象。所以這似乎工作。謝謝。 – Angela

相關問題