[英]How to get all vertices of all outgoing edges from a vertex scala gremlin
I need to get all list of vertices label of all outgoing egdes from a vertex using scala gremlin.我需要使用 scala gremlin 从一个顶点获取所有传出 egdes 的所有顶点标签列表。
My code looks like below,我的代码如下所示,
val names :ListBuffer[String] = ListBuffer()
val toList: List[Vertex] = graph.V().hasLabel(100).outE().outV().toList()
for(vertex <- toList){
names += vertex.label()
}
Its returning the same label name for all vertex Eg : Vertex A is having outE to B,C,D .它为所有顶点返回相同的标签名称,例如:顶点 A 有 outE 到 B,C,D 。 It returns the label of A. Output:它返回 A 的标签。输出:
ListBuffer(100, 100, 100)
Anything am i missing?我错过了什么吗?
I believe you asking for the wrong vertex in the end.我相信你最终会要求错误的顶点。 Honestly, I often make the same mistake.老实说,我经常犯同样的错误。 Maybe this is the traversal you looking for:也许这就是你要找的遍历:
graph.V().hasLabel(100).outE().inV().label().toList()
If you like me and often get confused by inV()
and outV()
you can use otherV
which gets the opposite vertex.如果你喜欢我并且经常被inV()
和outV()
弄糊涂,你可以使用获得相反顶点的otherV
。 Like so:像这样:
graph.V().hasLabel(100).outE().otherV().label().toList()
Finally you can even shorten your traversal by not explicitly stating the edge part:最后,您甚至可以通过不明确说明边缘部分来缩短遍历:
graph.V().hasLabel(100).out().label().toList()
By using out()
instead of outE()
you don't need to specify you want the vertex, out()
gets you the vertex directly.通过使用out()
而不是outE()
你不需要指定你想要的顶点, out()
直接让你得到顶点。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.