gpt4 book ai didi

nosql - 获取沿路径具有特定属性、标签和 ID 的所有顶点

转载 作者:行者123 更新时间:2023-12-01 13:13:37 24 4
gpt4 key购买 nike

我在 Janusgraph 数据库中有以下结构:

gremlin> continent = g.addV("continent").property("name", "Europe").next()
gremlin> country = g.addV("country").property("name", "France").next()
gremlin> region = g.addV("region").property("name", "Ile-de-France").next()
gremlin> departement = g.addV("departement").property("name", "Hauts-de-Seine").next()
gremlin> city = g.addV("city").property("name", "Saint-Cloud").next()
gremlin> g.V(continent).addE('is_part_of').to(country).iterate()
gremlin> g.V(country).addE('is_part_of').to(region).iterate()
gremlin> g.V(region).addE('is_part_of').to(departement).iterate()
gremlin> g.V(departement).addE('is_part_of').to(city).iterate()

我确实从以下查询中获取了从 citycontinent 的所有顶点的属性 name:

gremlin> g.V(city).emit().repeat(inE("is_part_of").outV().simplePath()).path().unfold().dedup().values("name")
==>Saint-Cloud
==>Hauts-de-Seine
==>Ile-de-France
==>France
==>Europe

但我还想获得每个返回顶点的 idlabel。我尝试使用 valueMap(true) 而不是 values("name") 步骤来获取所有属性,包括 idlabel,但大部分顶点包含许多可能会影响性能水平的属性。是否可以从每个顶点获取这些值?

最佳答案

你可以只做 valueMap(true, 'name')

gremlin> g.V(city).emit().repeat(inE("is_part_of").outV().simplePath()).
......1> path().
......2> unfold().
......3> dedup().
......4> valueMap(true,'name')
==>[id:8,label:city,name:[Saint-Cloud]]
==>[id:13,label:is_part_of]
==>[id:6,label:departement,name:[Hauts-de-Seine]]
==>[id:12,label:is_part_of]
==>[id:4,label:region,name:[Ile-de-France]]
==>[id:11,label:is_part_of]
==>[id:2,label:country,name:[France]]
==>[id:10,label:is_part_of]
==>[id:0,label:continent,name:[Europe]]

关于nosql - 获取沿路径具有特定属性、标签和 ID 的所有顶点,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58080711/

24 4 0