2
votes

I have a list of vertex ids. I want to get all possible edges among them.

I understand methods like filter/where would be of help here, but since I'm using gremlin-python, their implementation must be different.

I have tried :

a = [0,2,4,6,8,10]

g.V(a).outE().inV().hasId(a).toList()
# This gives me []

g.V(a).bothE().filter(otherV().hasId(a)).toSet()
# Traceback otherV is not defined

g.V(a).bothE().otherV().hasId(a).toList()
# This gives me []

# Some information on edges :
g.E().toList()
# [e[16][0-Likes->8], e[17][8-Likes->0], e[18][4-Likes->8], e[19][2-Likes->6], e[20][6-Likes->2], e[21][12-Likes->10], e[22][10-Likes->12], e[23][10-Likes->14], e[24][14-Likes->8], e[25][6-Likes->4]]

How can I achieve this? It seems like an easy problem, but still I am stuck on it.

1

1 Answers

3
votes

There are number of ways to do this - how about this one?

gremlin> a = ['marko','josh','lop']
==>marko
==>josh
==>lop
gremlin> g.V().has('name',within(a)).
......1>   aggregate('a').
......2>   outE().
......3>   filter(inV().where(within('a')))
==>e[9][1-created->3]
==>e[8][1-knows->4]
==>e[11][4-created->3]

This used the modern TinkerPop toy graph as an example. First, we find those starting vertices and aggregate them to a list side-effect called "a". Then, we traverse the outgoing edges of each and filter them for matches with those vertices in "a".