简体   繁体   English

Neo4J / Cypher:可变长度的路径模式

[英]Neo4J/Cypher : variable length of path pattern

I model a genealogy on a graph in Neo4J inspired by GEDCOM file. 我在受GEDCOM文件启发的Neo4J中的图形上对家谱建模。

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?) (以其他方式,如何在每个级别上重复个人之间的模式或将相同的模式应用于个人?)

You can use this query 您可以使用此查询

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

to create ancestor tree or the arrow pointing opposite for descendants. 创建后代的祖先树或相反的箭头。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM