How Can we do this in cypher?
There are n parents p1, p2, p3.... pn and m children c1, c2,c3... cm.
Suppose c1 is derived from (child of) p1,p2 and p3 and also c2 is derived from (child of) p1, p2 and p3.
Given c1 can we find c2? (node derived from the same parents as c1)
A child can have 1...n parents.
I actually asked an extremely similar question here a few weeks ago, and the answer I got then will work for you too with just a bit of tweaking.
START c1=node(*), c2=node(*)
MATCH c1-[:ChildOf]->parent<-[:ChildOf]-c2
WITH c1, c2, count(parent) AS parentsFound
WHERE length(c1-[:ChildOf]->()) = parentsFound
AND length(c2-[:ChildOf]->()) = parentsFound
AND c1 <> c2
RETURN c1, c2
Note: presumably you will have a better way of picking your c1 and c2 than using node(*).
The logic of this query line by line:
c1 and c2,parents shared by c1 and c2 parents that were foundparents found matches the total number of parents that c1 has.parents found matches the total number of parents that c2 has.If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With