Two node paths example question

30 views
Skip to first unread message

project2501

unread,
Apr 2, 2012, 3:41:18 PM4/2/12
to Gremlin-users
Hi,
I'm using Neo4j gremlin console and attempting the recipe for paths
between two nodes. I see odd results and need some help.

I get different results if I change the it.loops<X condition and don't
understand why. Also, the last condition (< 2) produces a path that
was never indicated in the previous two conditions (<=3, <3)

The example given is:

g.v(A).out.loop(1){it.loops<=N && !(it.object.id in
[A,B])}.filter{it.id==B}.paths

How does one select the value of N, since my results seem dependent on
it. Only paths that seem to be exactly N hops away are generated and
the shorter paths
are excluded. Is that right? If so, it means some paths cannot be
found with some queries, like the results below.

gremlin> g.v(35).out.loop(1){it.loops<3}.paths
==> [v[35], v[41], v[42]]
==> [v[35], v[41], v[42]]
==> [v[35], v[41], v[42]]
==> [v[35], v[41], v[42]]
gremlin> g.v(35).out.loop(1){it.loops<=3}.paths
==> [v[35], v[41], v[42], v[55]]
==> [v[35], v[41], v[42], v[55]]
==> [v[35], v[41], v[42], v[55]]
==> [v[35], v[41], v[42], v[55]]
==> [v[35], v[41], v[42], v[55]]
==> [v[35], v[41], v[42], v[55]]
==> [v[35], v[41], v[42], v[55]]
==> [v[35], v[41], v[42], v[55]]
gremlin> g.v(35).out.loop(1){it.loops<2}.paths
==> [v[35], v[36]]
==> [v[35], v[36]]
==> [v[35], v[36]]
==> [v[35], v[36]]
==> [v[35], v[36]]
==> [v[35], v[36]]
==> [v[35], v[36]]
==> [v[35], v[36]]
==> [v[35], v[41]]
==> [v[35], v[41]]
gremlin>

Marko Rodriguez

unread,
Apr 2, 2012, 3:46:17 PM4/2/12
to gremli...@googlegroups.com
Hi,

You can provide an emit-closure to the 'loop'-step to solve your problem.

g.v(A).out.loop(1){it.loops <= 3}{true}.paths

The {true} will emit all paths of lengths 1, 2, and 3.


HTH,
Marko.
Reply all
Reply to author
Forward
0 new messages