简体   繁体   中英

neo4j conditional relationship

I am currently working on a program using graph db - neo4j and I need to realize the following function.

在此处输入图片说明

  1. I have two types of nodes, type A means stage, type N means let the user do some selections.
  2. First we have node A1 , which has several (2-5) type N children, N1 , N2 , N3 , ...
  3. Nodes A1 also have child nodes A2 , A3 , ...
  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. For example, if N1 =true, N2 =true, N3 =false, I go to A2 , otherwise, I goto 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.

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:

在此处输入图片说明

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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