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[1]:

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

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[2],e[7][1-knows->2],v[1]]
==>[v[3],e[9][1-created->3],v[1]]
==>[v[3],e[11][4-created->3],v[4],e[8][1-knows->4],v[1]]
==>[v[4],e[8][1-knows->4],v[1]]
==>[v[4],e[11][4-created->3],v[3],e[9][1-created->3],v[1]]
==>[v[5],e[10][4-created->5],v[4],e[8][1-knows->4],v[1]]
==>[v[5],e[10][4-created->5],v[4],e[11][4-created->3],v[3],e[9][1-created->3],v[1]]
==>[v[6],e[12][6-created->3],v[3],e[9][1-created->3],v[1]]
==>[v[6],e[12][6-created->3],v[3],e[11][4-created->3],v[4],e[8][1-knows->4],v[1]]

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[2],e[7][1-knows->2],v[1]]
==>[e[9][1-created->3],v[1]]
==>[e[11][4-created->3],v[4],e[8][1-knows->4],v[1]]
==>[v[4],e[8][1-knows->4],v[1]]
==>[v[4],e[11][4-created->3],e[9][1-created->3],v[1]]
==>[e[10][4-created->5],v[4],e[8][1-knows->4],v[1]]
==>[e[10][4-created->5],v[4],e[11][4-created->3],e[9][1-created->3],v[1]]
==>[v[6],e[12][6-created->3],e[9][1-created->3],v[1]]
==>[v[6],e[12][6-created->3],e[11][4-created->3],v[4],e[8][1-knows->4],v[1]]

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 <yair...@...> 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.