简体   繁体   中英

How to exclude some paths in Neo4j Cypher

I have 2 sets of paths

Collection 1

  1. A->B->C->D
  2. A->E->F->D
  3. A->G->J->H
  4. I->B->C->D

Collection 2

  1. E->D
  2. I->D

The Cypher query output should be paths of Collection 1 where nodes combination of 2nd collection does not exist. In above example, nodes E,D of Collection 2, 1st element exist in 2nd path of Collection 1, so the 2nd should be dropped. similarly, nodes I,D of collection 2, 2nd element exist in 4th path of Collection 1, so the 4th should also be dropped.

Then the output should be Collection 3

  1. A->B->C->D
  2. A->G->J->H

Through Cypher, I'm able to find out paths of collection 1 in which nodes of collection 2 paths exist but I'm not able to do a 'minus' operation among collections.

How to get the cypher query to achieve above?

Thanks in advance

Rasyq

Without your Cypher queries it's not easy to answer. But in general you can get the nodes from a path with nodes(your_path) and check if all of those nodes are included in another path with the all() predicate.

MATCH p1 = (your first paths), p2 = (the paths you check against)
// filter paths where NOT all nodes of p2 are in p1
WHERE NOT all(node2 IN nodes(p2) WHERE node2 IN p1)
RETURN p1

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