database - Query family tree and marriage information in Neo4j -


i have family tree in neo4j database

db

how can query tree starting root node (126 in case) , husband, wife information of each node (similar image)?

i later need extract data in code in similar json format

root = {   name: "...",   children: [{     name: "...",     children: []   }, {     name: "...",     children: []   }],   marriage: [{     name: "first wife"   }, {     name: "second wife"   }] }; 

thanks

after researching more cypher, found solution answer own question

this cypher query. query root user id 682

match p=(root:person {user_id: 682})-[:father_child|mother_child *1..5]->       (child:person)<-[:father_child|mother_child]-(:person) nodes(p) all_nodes, relationships(p) all_relationships, p p return extract(n in all_nodes | n.user_id) `path`,        extract(r in all_relationships | type(r)) `relation`,        length(p) `length` order `length`; 

the sample result this

+-----------------------------------------------------------------------------+ | path              | relation                                       | length | +-----------------------------------------------------------------------------+ | [682,687,683]     | ["father_child","mother_child"]                | 2      | | [682,684,683]     | ["father_child","mother_child"]                | 2      | | [682,688,683]     | ["father_child","mother_child"]                | 2      | | [682,687,693,689] | ["father_child","father_child","mother_child"] | 3      | | [682,684,690,685] | ["father_child","father_child","mother_child"] | 3      | | [682,684,692,686] | ["father_child","father_child","mother_child"] | 3      | +-----------------------------------------------------------------------------+ 

the first column contains array. array except last value path root person child, last element other parent of child. reason have last element case when 1 person has many wives (or husbands).

the second column contains array. similarly, array relation corresponding path in first column.

from there, can construct data structure in favorite programming language


Comments

Popular posts from this blog

c# - Validate object ID from GET to POST -

node.js - Custom Model Validator SailsJS -

php - Find a regex to take part of Email -