以下是用节点和边表示的复杂族成员关系。
-
代表为
person
节点
-
这个
marriage
节点代表两个人的婚姻
人
-
son_of
和
daughter_of
把某人和某人联系起来
结婚
节点。
-
root_person
-
john
和
Brenda
-
mark
是第三代
-
mary
是第四代
-
厕所
有前妻和妻子
-
还有他的前妻
mark_ex_wife
他们是表亲。这是因为
作记号
的父亲和
马克的前妻
他的母亲是兄弟姐妹。
我的要求是以层次树格式获取所有节点。从
,他的儿子
还有他的妻子和女儿
brenda
“她的丈夫也应该回来。然后是下一代等等。。。
key
和
value
g.V().drop()
g.E().drop()
g.addV('person').property(id, 'root_person').property('name', 'Root Person').property('title', 'male')
g.addV('person').property(id, 'root_person_wife').property('name', 'root_person_wife').property('title', 'female')
g.addV('person').property(id, 'john').property('name', 'john').property('title', 'male')
g.addV('person').property(id, 'john_wife').property('name', 'john_wife').property('title', 'female')
g.addV('person').property(id, 'john_ex_wife').property('name', 'john_ex_wife').property('title', 'female')
g.addV('person').property(id, 'brenda').property('name', 'brenda').property('title', 'female')
g.addV('person').property(id, 'brenda_husband').property('name', 'brenda_husband').property('title', 'male')
g.addV('person').property(id, 'mark').property('name', 'mark').property('title', 'male')
g.addV('person').property(id, 'mark_ex_wife').property('name', 'mark_ex_wife').property('title', 'female')
g.addV('person').property(id, 'mark_wife').property('name', 'mark_wife').property('title', 'female')
g.addV('person').property(id, 'mary').property('name', 'mary').property('title', 'female')
g.addV('person').property(id, 'mary_husband').property('name', 'mary Husband').property('title', 'male')
g.addV('marriage').property(id, 'root_person-root_person_wife').property('marriage_name', 'root_person-root_person_wife')
g.addV('marriage').property(id, 'john-john_wife').property('marriage_name', 'john-john_wife')
g.addV('marriage').property(id, 'john-john_ex_wife').property('marriage_name', 'john-john_ex_wife')
g.addV('marriage').property(id, 'brenda-brenda_husband').property('marriage_name', 'brenda-brenda_husband')
g.addV('marriage').property(id, 'mark-mark_ex_wife').property('marriage_name', 'mark-mark_ex_wife')
g.addV('marriage').property(id, 'mark-mark_wife').property('marriage_name', 'mark-mark_wife')
g.addV('marriage').property(id, 'mary-mary_husband').property('marriage_name', 'mary-mary_husband')
g.V('root_person').addE('married_in').to(g.V('root_person-root_person_wife'))
g.V('root_person_wife').addE('married_in').to(g.V('root_person-root_person_wife'))
g.V('john').addE('married_in').to(g.V('john-john_wife'))
g.V('john_wife').addE('married_in').to(g.V('john-john_wife'))
g.V('john').addE('married_in').to(g.V('john-john_ex_wife'))
g.V('john_ex_wife').addE('married_in').to(g.V('john-john_ex_wife'))
g.V('brenda').addE('married_in').to(g.V('brenda-brenda_husband'))
g.V('brenda_husband').addE('married_in').to(g.V('brenda-brenda_husband'))
g.V('mark').addE('married_in').to(g.V('mark_#mark_wife'))
g.V('mark_wife').addE('married_in').to(g.V('mark-mark_wife'))
g.V('mark').addE('married_in').to(g.V('mark-mark_ex_wife'))
g.V('mark_ex_wife').addE('married_in').to(g.V('mark-mark_ex_wife'))
g.V('mary').addE('married_in').to(g.V('mary-mary_husband'))
g.V('mary_husband').addE('married_in').to(g.V('mary-mary_husband'))
g.V('john').addE('son_of').to(g.V('root_person-root_person_wife')).property('son_of', 'john--root_person-root_person_wife')
g.V('brenda').addE('daughter_of').to(g.V('root_person-root_person_wife')).property('daugter_of', 'brenda--root_person-root_person_wife')
g.V('mark').addE('son_of').to(g.V('john-john_wife')).property('son_of', 'mark--john-john_wife')
g.V('mark_ex_wife').addE('daughter_of').to(g.V('brenda-brenda_husband')).property('daugter_of', 'mark_ex_wife--brenda-brenda_husband')
g.V('mary').addE('daughter_of').to(g.V('mark-mark_wife')).property('daugter_of', 'mary--mark-mark_wife') }
更新:
cosmosdb
查询资源管理器,但它不会引入所有节点。
g.V('root_person').repeat(out('married_in')).emit().repeat(__.in('son_of', 'daughter_of')).emit().tree()
查询生成了以下json。你会注意到它在第二代就停止了。
[
{
"root_person": {
"key": {
"id": "root_person",
"label": "person",
"type": "vertex",
"properties": {
"name": [
{
"id": "f1e8327e-add4-454b-bbb2-6f076a29ea49",
"value": "Root Person"
}
],
"title": [
{
"id": "42fc9c2b-b613-4011-9a0a-183d907a96ac",
"value": "male"
}
]
}
},
"value": {
"root_person-root_person_wife": {
"key": {
"id": "root_person-root_person_wife",
"label": "marriage",
"type": "vertex",
"properties": {
"marriage_name": [
{
"id": "30f428a9-e657-4284-b59a-b836d9f04887",
"value": "root_person-root_person_wife"
}
]
}
},
"value": {
"john": {
"key": {
"id": "john",
"label": "person",
"type": "vertex",
"properties": {
"name": [
{
"id": "64e4653d-6298-479d-ba0f-eb3a9ede2383",
"value": "john"
}
],
"title": [
{
"id": "b99dacb3-e38d-4da8-b087-42860d2b28c0",
"value": "male"
}
]
}
},
"value": {}
},
"brenda": {
"key": {
"id": "brenda",
"label": "person",
"type": "vertex",
"properties": {
"name": [
{
"id": "1d88e8a5-7340-4b6d-a2b9-8b3c325e7bf6",
"value": "brenda"
}
],
"title": [
{
"id": "9b856caa-0b84-413c-8229-8e2c1e0cb0d3",
"value": "female"
}
]
}
},
"value": {}
}
}
}
}
}
}
]