简体   繁体   English

Py2neo与Neo4j的关系

[英]Relation in Py2neo with Neo4j

How can i get the end node of the relation. 我如何获得关系的结束节点。 For example: 例如:

rels = graph_db.match(start_node=user, rel_type="is_post_owner")

So how can i get all the end nodes of the start node user. 因此,我如何获得起始节点用户的所有末端节点。

Regards, Samuel 问候,塞缪尔

Like this: 像这样:

rels = graph_db.match(start_node=user, rel_type="is_post_owner")
end_nodes = [rel.end_node for rel in rels]

Each relationship returned from the match method is a standard Relationship object and can be used as such. match方法返回的每个关系都是标准的Relationship对象,可以这样使用。

You could use cypher 你可以使用密码

START a=node(id) //replace with the id of the node you want to start 
MATCH p=a-[:is_post_owner*..]->x //get all the paths to all nodes with rel:is_post_owner
WHERE NOT(x-->()) //exclude nodes with Direction Out Relationships "end nodes"
RETURN x //get the end nodes

That way returned nodes are going to be leaf nodes of your graph, with no other relationship with direction out. 这样,返回的节点将成为图的叶节点,而与方向无关。

As Thomas stated, in which he is absolutely right, you should include the relationship type in the where clause.That way you are getting the end node of that relationship only and returned nodes can have other relationships with direction out (not leaf nodes) but they are the end nodes of the requested relationship 正如Thomas所说的那样,他绝对正确,您应该在where子句中包括关系类型,这样您就只能获得该关系的结束节点,而返回的节点可以具有其他具有方向输出的关系(不是叶节点),它们是所请求关系的末端节点

 START a=node(id) 
 MATCH p=a-[r:is_post_owner*..]->x 
 WHERE NOT(x-->(r)) 
 RETURN x 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM