简体   繁体   English

如何在单个遍历中从一个顶点创建多个边

[英]How to create multiple edges from one vertex in single traversal

I've got function which has this signature: 我有具有此签名的功能:

public void doTheJob(String from, Collection<Pair<String, String>> relations)

where: 哪里:

from is a unique value the graph should be asked about from是图表应询问的唯一值

relations is a collection of pair, where first element from pair is edge label and the second is similar to from but it designates the second side of the relation. relations是一对,其中一对从第一元件是边缘的集合label和所述第二类似from但它表示的关系的第二侧。 Eg ( assuming that andy, dog are unique ): 例如(假设安迪,狗是唯一的):

"andy" ["has,dog", "has,cat", "is,person"]

I would like to add these edges between these vertices ( they are already existing in graph, i would like to query them and create edges between them ). 我想在这些顶点之间添加这些边(它们已经存在于图形中,我想查询它们并在它们之间创建边)。 The requirement I've got is to prepare this in one traversal. 我的要求是一次遍历。

Thanks! 谢谢!

Here is one way to do it: 这是一种实现方法:

gremlin> g = TinkerFactory.createModern().traversal()
==>graphtraversalsource[tinkergraph[vertices:6 edges:6], standard]
gremlin> g.addV().property('name','cat').
......1>   addV().property('name','dog').
......2>   addV().property('name','person').iterate()
gremlin> markoRelations = [['has','dog'],['has','cat'],['is','person']];[]
gremlin> joshRelations = [['has','dog'],['is','person']];[]
gremlin> t = g.V().has('name','marko').as('from');[]
gremlin> markoRelations.each { t = t.V().has('name',it[1]).
......1>                             addE(it[0]).from('from') };[]
gremlin> t.iterate()
gremlin> t = g.V().has('name','josh').as('from');[]
gremlin> joshRelations.each { t = t.V().has('name',it[1]).
......1>                            addE(it[0]).from('from') };[]
gremlin> t.iterate()
gremlin> g.E().hasLabel('is','has')
==>e[19][1-has->15]
==>e[20][1-has->13]
==>e[21][1-is->17]
==>e[22][4-has->15]
==>e[23][4-is->17]

Don't be distracted by the Groovy syntax too much and just focus on on the Gremlin and structure. 不要太受Groovy语法的干扰,而只专注于Gremlin和结构。 markoRelations and joshRelations are just lists of list where the inner list is basically you Pair . markoRelationsjoshRelations只是列表的列表,其中内部列表基本上是您Pair The ;[] you see at the end of lines is not relevant to the answer - it just helps control the output that the Gremlin Console will show. 您在行尾看到的;[]与答案无关-它仅有助于控制Gremlin控制台将显示的输出。

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

相关问题 如何创建具有相同权重和相同源顶点的多个边? - How can I create multiple edges with the same weight and same source vertex? 如何在Graph中创建相对于距离从单个节点传播的边 - How to create edges propagating from a single node with respect to distance in a Graph 从数据库加载顶点和边时,Vertex Painter遇到错误 - Vertex painter encounter error when loading vertex and edges from database 如何找到入射到特定顶点的边列表 - How to find the list of edges incident to a particular vertex 如何在单个仓库中为多个实体和多个@query创建一个crudrepository - How to create one crudrepository for multiple entity and multiple @query in single repo 如何从多个程序包创建一个jar? - How to create a single jar from multiple packages? 如何使用有序边从顶点遍历并保持有序走两步 - How to traverse from a vertex using ordered edges and sustain ordering for two steps away 基于顶点标签的遍历 - Vertex label based traversal 使用一个队列遍历二叉树 - traversal of binary tree using one single queue 有什么方法可以从mxgraph更改顶点或边缘样式吗? - Is there any way to change the vertex or the edges style from mxgraph?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM