2017-04-26 44 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

相关问题