1
votes

I model a genealogy on a graph in Neo4J inspired by GEDCOM file.

My nodes and relations are :

Individual <-[CHILD]- Family
Family -[HUSBAND]-> Individual
Family -[WIFE]-> Individual

I don't model the family as a relation because i can have multiple event attached to it (Engagement,Marriage,Annulment,Divorce,...) :

Family -[OCCUR]-> FamilyEvent{type,subtype,date,place,note}

I can get the father and mother of a person with this cypher query :

MATCH (i:Individual {nickname:'Louis XVI'})
        <-[r:CHILD]-
    (m:Family)
        -[r2:HUSBAND|WIFE]->
    (h:Individual) 
    return i,r,m,r2,h

Or the child of a person :

MATCH (i:Individual {nickname:'le Pieux ou le Débonnaire'})
        <-[r:HUSBAND]-
    (m:Family)
        -[r2:CHILD]->
    (h:Individual) 
    return i,r,m,r2,h

But how can i get all the ascendants or descendants of a person ?
(In other way, how can i repeat the pattern between individual or apply the same pattern to individual i get on each level?)

1

1 Answers

0
votes

You can use this query

    match (n:individual{id:###})<-[:child*..9]-(m) return n,m

to create ancestor tree or the arrow pointing opposite for descendants.