gpt4 book ai didi

gremlin - 如何从传递边构建子图?

转载 作者:行者123 更新时间:2023-12-02 16:26:07 24 4
gpt4 key购买 nike

我有一个具有具体关系的图,其中包含有用的信息,但出于可视化目的,我需要创建一个没有这些中间节点的子图。

示例:

[A:Person] <--AFFILIATE-- [B:Affiliation] --COMPANY--> [C:Org]

我想生成一个像这样的子图:

[A:Person] --AFFILIATED_TO--> [C:Org]

有什么简单的方法可以用 Gremlin 实现这一点吗?

最佳答案

我认为您最好的选择可能是使用 subgraph()像平常一样提取边缘引起的子图,然后在该子图上执行一些 Gremlin 以引入可视化边缘并删除您不想要的内容。

我可以用 TinkerPop 打包的现代玩具图来演示:

gremlin> graph = TinkerFactory.createModern()
==>tinkergraph[vertices:6 edges:6]
gremlin> g = graph.traversal()
==>graphtraversalsource[tinkergraph[vertices:6 edges:6], standard]
gremlin> sg = g.V().outE('created').subgraph('sg').cap('sg').next() // subgraph creation
==>tinkergraph[vertices:5 edges:4]
gremlin> g = sg.traversal()
==>graphtraversalsource[tinkergraph[vertices:5 edges:4], standard]
gremlin> g.V().as('a'). // add special subgraph edge
......1> out('created').as('software').
......2> in('created').where(neq('a')).
......3> addE('co-developer').from('a').
......4> property('project',select('software').by('name'))
==>e[0][1-co-developer->4]
==>e[1][1-co-developer->6]
==>e[2][4-co-developer->1]
==>e[3][4-co-developer->6]
==>e[4][6-co-developer->1]
==>e[5][6-co-developer->4]
gremlin> g.V().hasLabel('software').drop() //remove junk from subgraph
gremlin> g.E()
==>e[0][1-co-developer->4]
==>e[1][1-co-developer->6]
==>e[2][4-co-developer->1]
==>e[3][4-co-developer->6]
==>e[4][6-co-developer->1]
==>e[5][6-co-developer->4]
gremlin> g.V().has('name','marko').outE('co-developer').valueMap(true)
==>[label:co-developer,project:lop,id:0]
==>[label:co-developer,project:lop,id:1]

关于gremlin - 如何从传递边构建子图?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46950031/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com