[英]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
. markoRelations
和joshRelations
只是列表的列表,其中内部列表基本上是您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.