Sequential edge creation between streamed vertices
I would like to create an edge between vertices as they are streamed in sequence from a traversal. I want to connect each vertex to the next one in the stream, like a linear chain of vertices with a
next
edge.
For example, given this g.V().hasLabel("person").values("name")
produces:
I'd like to achieve something like josh -next-> peter -next-> marko -next-> vadas
My current approach is to create a "sliding window" of vertex pairs:
Which results in:
Next I add edges between each pair:
This works, but I’m not sure if this is the idiomatic way to do this. I think modeling data where vertices are explicitly ordered through an edge connection is not uncommon, right?Solution:Jump to solution
i think that's about as good as most approaches. we're missing a step that coudl simplify this code though. i've long wanted a
partition()
step so that you could change all that code to just:
```
g.V().hasLabel('person').
partition(2).
addE('next').from.......2 Replies
Solution
i think that's about as good as most approaches. we're missing a step that coudl simplify this code though. i've long wanted a
partition()
step so that you could change all that code to just:
@Kelvin Lawrence do you have any other ways that you might do what's asked in this question?