How to add multiple edges?

1,361 views
Skip to first unread message

Dylan Millikin

unread,
Jun 4, 2015, 9:06:47 AM6/4/15
to gremli...@googlegroups.com
Hey guys,

I apologize in advance if this is stupid but I can't seem to workout how to add multiple edges between vertices. The following doesn't work:

v1 = g.addV();
v2 = g.addV();
v1.addOutE('FRIEND_A', v2);
v1.addOutE('FRIEND_B', v2);
v1.addOutE('FRIEND_C', v2);

Only FRIEND_A is created. I've tried using iterate(), I've tried addOutE().inV().addOutE() etc.. can't seem to get it working.
I'm sure I'm missing something very simple but I'd appreciate your help on the matter.

Thanks.

Daniel Kuppitz

unread,
Jun 4, 2015, 10:32:37 AM6/4/15
to gremli...@googlegroups.com
Hi Dylan,

addV() and addOutE() are meant to be used in a traversal. You should either operate directly on the graph:

v1 = graph.addVertex()
v2 = graph.addVertex()
v1.addEdge('FRIEND_A', v2)
v1.addEdge('FRIEND_B', v2)
v1.addEdge('FRIEND_C', v2)

Or wrap it all in a single traversal:

g.addV().as('x').addV().as('y').select().union(addOutE('x', 'FRIEND_A', 'y'), addOutE('x', 'FRIEND_B', 'y'), addOutE('x', 'FRIEND_C', 'y'))

Cheers,
Daniel



--
You received this message because you are subscribed to the Google Groups "Gremlin-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to gremlin-user...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/gremlin-users/CAK-m_Kz%2B%2B_6Ki5ZW6o5D4DzOs-jDMMOGrd%2Bw-sZbqmkz2aEPjA%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

Dylan Millikin

unread,
Jun 12, 2015, 1:57:22 PM6/12/15
to gremli...@googlegroups.com
Hey guys, I'm still trying to figure this one out. Any help would be greatly appreciated. 
The only script I've managed to make work is the following:

v1 = g.addV().id().next();
v2 = g.addV().id().next();
g.V(v1).addOutE('FRIEND_A', g.V(v2));
g.V(v1).addOutE('FRIEND_B', g.V(v2));
g.V(v1).addOutE('FRIEND_C', g.V(v2));

This just doesn't look right so I must be missing something simple. (also in my first email I meant addOutE().outV().addOutE())

Thanks for the help. 

On Thu, Jun 4, 2015 at 3:06 PM, Dylan Millikin <dylan.m...@gmail.com> wrote:

Stephen Mallette

unread,
Jun 12, 2015, 3:16:00 PM6/12/15
to gremli...@googlegroups.com
as of latest SNAPSHOT I don't think you even have that syntax that you are using available to you.  assuming you had v1/v2 you would probably do:

gremlin> g.withSideEffect('a',[v2]).V(v1).addOutE('friend1','a')
==>e[2][0-friend1->1]
gremlin> g.withSideEffect('a',[v2]).V(v1).addOutE('friend2','a')
==>e[3][0-friend2->1]
gremlin> g.withSideEffect('a',[v2]).V(v1).addOutE('friend3','a')
==>e[4][0-friend3->1]

i guess you could one-liner it:

gremlin> ['friend1','friend2','friend3'].collect{g.withSideEffect('a',[v2]).V(v1).addOutE(it,'a').next()}
==>e[5][0-friend1->1]
==>e[6][0-friend2->1]
==>e[7][0-friend3->1]

of course if you have the raw vertices in hand, and you only want to add edges between them, why not just do:

gremlin> v1 = g.addV().next()
==>v[0]
gremlin> v2 = g.addV().next()
==>v[1]
gremlin> ['friend1','friend2','friend3'].collect{v1.addEdge(it,v2)}
==>e[2][0-friend1->1]
==>e[3][0-friend2->1]
==>e[4][0-friend3->1]

i'm sure daniel with improve any of this answer if he can....



--
You received this message because you are subscribed to the Google Groups "Gremlin-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to gremlin-user...@googlegroups.com.

Stephen Mallette

unread,
Jun 12, 2015, 4:36:25 PM6/12/15
to gremli...@googlegroups.com
Hey Dylan - i'd forgotten that daniel had already replied to this.  did you somehow miss his previous answer:


or was there there something wrong with it?  i like his use of union() actually now that i'm looking at it again.

Daniel Kuppitz

unread,
Jun 12, 2015, 4:36:30 PM6/12/15
to gremli...@googlegroups.com
Hi Dylan,

just in case you missed it, I still think my first answer nailed it: https://groups.google.com/d/msg/gremlin-users/bWWs0cIoidQ/5cUpy4C4t6cJ

Cheers,
Daniel


Dmill

unread,
Jun 14, 2015, 6:59:22 AM6/14/15
to gremli...@googlegroups.com
Hey guys,

Terribly sorry, apparently the group isn't emailing me replies to my topics anymore so I've missed your replies (I just picked up on it today). 
The replies are great, it explains the issues I've had and I can easily implement those.

Thanks a tonne.
Reply all
Reply to author
Forward
0 new messages