Emitting current element (before looping)

45 views
Skip to first unread message

Jonas Michel

unread,
Feb 26, 2015, 6:50:52 PM2/26/15
to gremli...@googlegroups.com
Hello,

I'm fairly new to Gremlin and need to emit an element before jumping into a loop. Is there a way to do this?

So, given a graph with alternating edges like this:

A(1) --gives--> B(2) <--takes-- C(3) --gives--> D(4) <--takes-- E(5) --gives--> F(6)

I have the following query:

g.v(2).as("x").in("takes").out("gives").loop("x"){ it.object.in("takes").hasNext() }{ true }

This query emits D and F, I would like B, D, and F.

Alternatively, is there a better way to structure this traversal?

Many thanks!
Jonas

Jonas Michel

unread,
Feb 27, 2015, 1:27:54 AM2/27/15
to gremli...@googlegroups.com
Solved with the help of store() and fill()...

x = []
g.v(2).store(x).as("x").in("takes").out("gives").loop("x"){ it.object.in("takes").hasNext() }{ true }.fill(x)
x
==> B(2)
==> D(4)
==> F(6)

Though I would like to know if this can be accomplished without an external collection.

Daniel Kuppitz

unread,
Feb 27, 2015, 11:49:18 AM2/27/15
to gremli...@googlegroups.com
I guess your solution is the best ting you can do in TP2. But just saying, it's just this in TP3:

g.V(2).emit().repeat(in("takes").out("gives"))

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/c2f517b7-ae5d-4166-ae5e-de9d6944e055%40googlegroups.com.

For more options, visit https://groups.google.com/d/optout.

Jonas Michel

unread,
Feb 27, 2015, 11:54:03 AM2/27/15
to gremli...@googlegroups.com
Hi Daniel,

Wow, the TP3 version is much more to the point. Thanks! However, I'm using a Titan 0.5.4 implementation so I'm restricted to TP2.

Thanks again!
Jonas
Reply all
Reply to author
Forward
0 new messages