在neo4j中查询特定于案例的节点 [英] Query case-specific nodes in neo4j

查看:269
本文介绍了在neo4j中查询特定于案例的节点的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个类似附件的设置. 橙色节点表示案例蓝色节点表示该案例中各种活动的表演者.

I have a setup like the attached image. Orange nodes denotes the cases and the Blue nodes denotes the Performers of various activities within that case.

我想依次查询每种情况.在每种情况下,我都需要添加关系

I would like to query each case in turn. Within each case, I need to add relationship

[:RELATED {value: 1}] 

node i node k ,对于位于其之间的所有k(其ID落入的节点在i和j之间)那对Performer节点( node i node j ),使得:

名称(节点 i ) == 名称(节点 j )



| ID(node i )-ID(node j )| > = 2

from nodei to nodek , for all k that lies in between(nodes whose ID fall between i and j) those pair of Performer nodes (nodei,nodej) such that :

Name(nodei) == Name( nodej )

and

| ID(nodei) - ID(nodej) | >= 2





[示例和预期输出]:

  1. 在案例1中,由于ID为:1和ID:4的Performer节点满足条件,因此之间添加了关系:

  1. In Case1, since Performer nodes with ID:1 and ID:4 satisfy the criteria, so relationships are added between:

       Node(ID:1) to Node(ID:2)

       Node(ID:1) to Node(ID:3)


  1. 在Case2中,具有ID:2和ID:4的Performer节点满足条件,因此在以下各项之间添加了关系:

  1. In Case2, Performer nodes with ID:2 and ID:4 satisfy the criteria, so relationships are added between:

       Node(ID:2) to Node(ID:3)


  1. 在Case3中,有两组满足条件的节点,

  1. In Case3, there are two sets of nodes satisfying the criteria,

a.对于Node(ID:1)和Node(ID:4),添加关系来自

a. For Node(ID:1) and Node(ID:4) add relationships from

       Node(ID:1) to Node(ID:2)

       Node(ID:1) to Node(ID:3)

b.对于Node(ID:3)和Node(ID:5),从添加关系

b. For Node(ID:3) and Node(ID:5), add relationship from

       Node(ID:3) to Node(ID:4)

针对上述情况,在制定CYPHER查询时需要提示.

Hint needed in formulating CYPHER queries for the above case.

谢谢.

推荐答案

如问题注释中所述,您的计算应取反:

As mentionned in the question comment, your calculation should be reversed :

node j - node i >= 2

对于情况3,还有一点,按照您的解释,节点2和3之间应该存在第三种关系.

One point more, for case 3, Following your explanations there should be a third relationship between node 2 and 3

这是我进行的查询,您可以在此neo4j控制台中对其进行测试: http://console. neo4j.org/r/gpfesu

Here is a query I made, you can test it in this neo4j console : http://console.neo4j.org/r/gpfesu

MATCH (n:Case) 
MATCH path=(pe)<--(n)-->(pe2)
WHERE pe.name = pe2.name
AND pe2.id - pe.id >= 2
WITH path,n, (pe2.id - pe.id) as length
WITH range(head(nodes(path)).id+1, last(nodes(path)).id-1) as ids,
     n, 
     head(nodes(path)).id as starter,
     length
UNWIND ids as x
MATCH (perf:Performer {id:starter})<--(n)-->(perf2:Performer {id:x})
MERGE (perf)-[:RELATES_TO {value:1, length:length}]->(perf2)

这篇关于在neo4j中查询特定于案例的节点的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆