I have a simple csv, with 4 lines, that looks like this:
+------------+-------------+------------+-------------+
| ID | Name | FatherID | MotherID |
+------------+-------------+------------+-------------+
| 1 | Mom Doe | | |
| 2 | Dad Doe | | |
| 3 | Big Sis | 2 | 1 |
| 4 | Lil Bro | 2 | 1 |
+------------+-------------+------------+-------------+
I am trying to make a family tree, which looks like this:
The trick here is that I have to create these relationships based on only two things: the FatherID
and the MotherID
. Which is doeable. But it requires applying a relationship in some conditional way.
Here's what I tried, which didn't work:
LOAD CSV WITH HEADERS FROM
'file:///Users/.../import_for_Neo4j.csv' AS line
WITH line
CREATE (person:Person {id:line.ID})
SET person.Name=line.Name,
person.MotherID=line.MotherID,
person.FatherID=line.FatherID
WITH person
CREATE (a:Person {Name:'Mom Doe'})-[:SPOUSE]->(b:Person {Name:'Dad Doe'})
RETURN a
But then I realized, that even if this did actually work, what would be the point? I'd have to go in an hand-type the names for every family member, which would negate the whole point of loading a csv in the first place. If that was the case, I may as well just type everything up in Sublime by hand and skip reading a csv.
One idea I had was to take anyone who has a NULL for FatherID
and MotherID
become related as SPOUSE, but that wouldn't work if the family tree had grandparents.
A solution seems really tricky -- maybe first create all the nodes and create the SIBLING
relationships. Then iterate over the csv and produce the CHILD
relationships?
Is there any way I can generally slurp up a csv and create this simple graph?
Thanks for reading this.