简体   繁体   English

neo4j条件关系

[英]neo4j conditional relationship

I am currently working on a program using graph db - neo4j and I need to realize the following function. 我目前正在使用图db-neo4j编写程序,需要实现以下功能。

在此处输入图片说明

  1. I have two types of nodes, type A means stage, type N means let the user do some selections. 我有两种类型的节点,类型A表示阶段,类型N表示让用户做一些选择。
  2. First we have node A1 , which has several (2-5) type N children, N1 , N2 , N3 , ... 首先,我们有节点A1 ,它有几个(2-5)类型的N个子节点N1N2N3 ...
  3. Nodes A1 also have child nodes A2 , A3 , ... 节点A1还具有子节点A2A3 ,...
  4. In java, after arriving at A1 , I will ask the users to do some selections according to Ni , then go to a type A child based on a function of the selections. 在java中,到达A1后 ,我将要求用户根据Ni进行一些选择,然后根据选择的功能转到类型A子级。 For example, if N1 =true, N2 =true, N3 =false, I go to A2 , otherwise, I goto A3 . 例如,如果N1 = true, N2 = true, N3 = false,则转到A2 ,否则转到A3

BTW, I will meet this situation many many times in my program. 顺便说一句,我将在程序中多次遇到这种情况。 Do you guys have any idea how to implement it efficiently. 你们有什么想法如何有效地实施它。

Thanks in advance. 提前致谢。

Suggestion for Setup 安装建议

(Ax)-[:TRUE ]->(Nx)-[:TRUE ]->(Ax+1)
(Ax)-[:FALSE]->(Nx)-[:FALSE]->(Ax+1)

Suggestion for Query 查询建议

 MATCH (a:A {id:1}),
       (a)-[:TRUE]-> (n)-[:FALSE]->(a2),
       (a)-[:FALSE]->(n2)-[:TRUE]->(a2),
       (a)-[:TRUE]-> (n)-[:FALSE]->(a2)
 RETURN a2;

Thanks to @Michael Hunger, I think I find an acceptable solution, although it seems a lot of work to do. 感谢@Michael Hunger,我认为我找到了一个可以接受的解决方案,尽管似乎还有很多工作要做。

Specifically, I expand all the pathes from A1 through Ni and link the only path when all Ni =true to A2* and all the other paths to A3 as the following graph: 具体来说,我将所有路径从A1扩展到Ni ,并将所有Ni = true时的唯一路径链接到A2 * ,将所有其他路径的所有链接链接到A3 ,如下图所示:

在此处输入图片说明

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

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