That is a brilliant solution (and way above my level of (in)competence)!
One last question.
You have labelled the relationships 'vRel'. I want to rename them, based on a property of the real relationship(s).
This worked in the initial version:
apoc.create.vRelationship(n, CASE r5.Type WHEN "child" THEN 'CHILD' WHEN "spouse" THEN 'SPOUSE' ELSE " " END, {}, m)
but the r5 throws a Type Mismatch error (after having added it to every WITH-line).
Is there a way to fix/around this?
I did label that in the code, but I did it after a captured the graph. I remember that you had change one of my bad queries to add the relationship type, so I added it. I used the relationship between the producer and the family node. If you want it uppercases, the following should do so:
MATCH (n:Name)
WHERE n.NameID = "N111"
MATCH (n)<-[:HAS_NAME_VARIANT {qualification: "preferred"}]-(p)-[:IS_RELATED_TO]->(f:Family)
MATCH (f)<-[:IS_RELATED_TO]-(p4)
MATCH p1=(p4)-[:IS_RELATED_TO*]-()-[:HAS_NAME_VARIANT {qualification: "preferred"}]->(:Name)
WITH apoc.coll.toSet(reduce(s=[], path in collect(p1) | s+nodes(path))) as all_nodes
WITH all_nodes, [p in all_nodes where 'Producer' in labels(p)] as producers
UNWIND producers as producer
MATCH (n:Family)<-[r:IS_RELATED_TO]-(producer)-[:HAS_NAME_VARIANT {qualification: "preferred"}]->(m:Name)
WHERE n in all_nodes and m in all_nodes
RETURN n, m, apoc.create.vRelationship(n, toUpper(r.Type), {}, m) as vrel
If you only want the values of child and spouse, you can replace ‘r.type’ with your case statement using r.type as the variable.