#### Re: filtering a path

Daniel Kuppitz <me@...>

I don't know how to write Scala code, so you'll always have to convert my code snippets from Java to Scala ;).

Again, the snippet assumes, that all vertices on a certain path have a num value greater than 50. If that's not what you want, then how do you want to treat edges that are connected to vertices that don't match the filter criteria?

Let me demonstrate the problem. Let's say you want to find all paths in the modern graph, that end at v:

gremlin> endVertex = g.V(1).next(); g.V().repeat(bothE().otherV().simplePath()).until(__.is(endVertex)).path()
==>[v,e[1-knows->2],v]
==>[v,e[1-created->3],v]
==>[v,e[4-created->3],v,e[1-knows->4],v]
==>[v,e[1-knows->4],v]
==>[v,e[4-created->3],v,e[1-created->3],v]
==>[v,e[4-created->5],v,e[1-knows->4],v]
==>[v,e[4-created->5],v,e[4-created->3],v,e[1-created->3],v]
==>[v,e[6-created->3],v,e[1-created->3],v]
==>[v,e[6-created->3],v,e[4-created->3],v,e[1-knows->4],v]

Another way to do that would be:

gremlin> endVertex = g.V(1).next(); g.V().as("a").repeat(bothE().as("a").otherV().as("a").simplePath()).until(__.is(endVertex)).select(all, "a")
==>[v,e[1-knows->2],v]
==>[v,e[1-created->3],v]
==>[v,e[4-created->3],v,e[1-knows->4],v]
==>[v,e[1-knows->4],v]
==>[v,e[4-created->3],v,e[1-created->3],v]
==>[v,e[4-created->5],v,e[1-knows->4],v]
==>[v,e[4-created->5],v,e[4-created->3],v,e[1-created->3],v]
==>[v,e[6-created->3],v,e[1-created->3],v]
==>[v,e[6-created->3],v,e[4-created->3],v,e[1-knows->4],v]

Using this approach, you can filter out certain vertices (e.g. you only want person vertices):

gremlin> endVertex = g.V(1).next(); g.V().choose(hasLabel("person"), __.as("a"), identity()).repeat(bothE().as("a").otherV().choose(hasLabel("person"), __.as("a"), identity()).simplePath()).until(__.is(endVertex)).select(all, "a")
==>[v,e[1-knows->2],v]
==>[e[1-created->3],v]
==>[e[4-created->3],v,e[1-knows->4],v]
==>[v,e[1-knows->4],v]
==>[v,e[4-created->3],e[1-created->3],v]
==>[e[4-created->5],v,e[1-knows->4],v]
==>[e[4-created->5],v,e[4-created->3],e[1-created->3],v]
==>[v,e[6-created->3],e[1-created->3],v]
==>[v,e[6-created->3],e[4-created->3],v,e[1-knows->4],v]

As you can see, that keeps some edges, that no longer make any sense.

Cheers,
Daniel

On Wed, Aug 30, 2017 at 7:14 AM, Yair Ogen wrote:
That didn't compile.

I changed it to use Key:

.repeat(_.outE().inV().has(Key[Long]("num"),gt(50)).simplePath())

oddly enough it filters everything although clearly some ages do have higher than 50 in this property

Join janusgraph-users@lists.lfaidata.foundation to automatically receive all group messages.