cancel
Showing results for 
Search instead for 
Did you mean: 

Head's Up! Site migration is underway. Expect disruption to service on Thursday, Feb. 9!

Delete some nodes in the path

ruanlovelin
Node Clone

I want to use neo4j to handle such a scenario: for example, I have a set of interrelated nodes,These nodes form a tree structure. These nodes have two types of labels A and B. How can I achieve that A labeled nodes can only appear at the end of the path, but not in the path. The node with label B can appear anywhere in the path.

Thank you very much!

8 REPLIES 8

ruanlovelin
Node Clone

In other words, this is a loop traversal problem. The breadth traversal algorithm is used. When a node with a specified label is encountered, it skips over without traversing.

glilienfield
Ninja
Ninja

I am sorry I am having difficulties understanding what you need. Can you explain what your question better? 

I am Sorry, my English is very poor.  There is a graph containing multiple association relationships. I want to do sub graph mining. Assume that the relationship is r1, r2, r3. I only focus on r1 and r2, not on r3. However, there may be such situations, such as nodes A, B, C, D, and E, where A and B are r1, B and E are r3, A and C are r3, and C and D are r2. In this case, I need to preserve only the subgraphs of nodes A, B, C, and D.2e43eb4303330c82247afb9736c4331.jpg

What is special about node E that determines you want to delete the r3?  Why not the r3 relationship between nodes A and C?  Is this because mode E is a terminal node?  

hiw does this relate to your original post about nodes labeled A or B, and A labeled nodes can only be a terminal node of a tree?  

First of all, thank you very much for your reply.

1. My goal is to mine subgraphs, not delete any relationships.

2. The initial post was that I did not express clearly, and the following statement shall prevail.

3. In the example,

The sub graph I want finally only contains nodes A, B, C and D, not E,

Because the relationship between E and B is r3, and E is the terminal node of a tree.

Thank you very much!

Add and correct one point. In the following diagram,

Nodes A, C, and E are all nodes labeled A at the beginning,

B. D is the node labeled B at the beginning.

In fact, this may require deep traversal of all paths first,

If a path starts from a node and then does not contain the relationship I am concerned about,

Then this node is the terminal node of this path.

So, is this more of an issue of figuring out how to traverse paths in a graph to find subgraphs with certain constraints, versus understanding how to delete specific relationships?  It now seems like you are looking for help with the former.  Cypher is not very good for this purpose. You may want to look at the APOC path procedures. Specifically, apoc.path.expandConfig may help. You can specify constraints on the types of nodes and relationships you want/don't want. 

https://neo4j.com/labs/apoc/4.4/overview/apoc.path/

Is this what you are looking for? 

Thank you very much!

I did use apoc.path.expandConfig for this project.

However,It seems that we haven't found how to set parameters to meet the requirements.