2017-04-26 1 views
0

私は、次の基本的なユースケースのため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 

まず、私は、着信している、関連する関係を見てみたいです。

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 |

機能は、Java APIに存在する

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

+0

'n1.rels.mapを{見ます| n | 'は配列内に各関係オブジェクトを返します。それは働いているようです。ありがとう。 – Angela

関連する問題