Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.4k views
in Technique[技术] by (71.8m points)

neo4j - Merge Duplicate Paths

I am trying to compare and merge identical paths. I am following along with this example, but it is only comparing each element in a path to a constant.

My problem is as follows. Consider three graphs

a->b->c->d
b->c->d
a->b->c->e

Created by the query CREATE p = (:x {name: 'a'}) -[:next]-> (:y {name: 'b'})-[:next]-> (:x {name: 'c'})-[:next]-> (:y {name: 'd'}), q = (:y {name: 'b'})-[:next]-> (:x {name: 'c'})-[:next]-> (:y {name: 'd'}), r = (:x {name: 'a'}) -[:next]-> (:y {name: 'b'})-[:next]-> (:x {name: 'c'})-[:next]-> (:y {name: 'e'}) RETURN *

I want to find and then merge all equivalent paths so that I get:

a->b->c->d
      |
      v
      e

My current idea for an approach is using a query to collect all identical paths in lists and then merging the overlapping nodes and relationships in the paths. For example, I want a query to get

[ 
  [ [b-c-d, b-c-d], [a-b-c, a-b-c] ] // comparison of path 1 to paths 2 and 3
  [ [b-c, b-c] ] // comparison of paths 2 and 3
]

Then I want to extract all unique nodes and merge them using apoc.refactor.mergeNodes. Followed by apoc.refactor.mergeRelationships on relationships connecting the now identical nodes.

Is this the correct approach? How would I construct a query to obtain the overlapping paths?


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
等待大神答复

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...