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




Yair Ogen <yair...@...>
 

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



Daniel Kuppitz <me@...>
 

even those in between start and end

Does that mean you want to exclude the whole path or only matching vertices on the path? If the latter, then what about the edges? Taking out a single vertex leaves 2 invalid edges on the path.
If the former, then it's:

...repeat(outE().inV().has("num", gt(50)).simplePath())...

Cheers,
Daniel
 

On Wed, Aug 30, 2017 at 6:34 AM, <yair...@...> wrote:
What's the best way to filter a path based on a Vertex property.

I am using the gremlin-scala lib.

This is the code:

val paths = startVertex.asScala().start()
      .repeat(_.outE().inV().simplePath())
      .until(_.is(endVertex.vertex))
      .path()
      .toList()


This works great. Now I want to add a filter that will filter out any Vertexes (even those in between start and end) in the path where property("num") > 50.

Seems that the filter API is only for the End Vertex? 

--
You received this message because you are subscribed to the Google Groups "JanusGraph users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to janusgraph-users+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


yair...@...
 

What's the best way to filter a path based on a Vertex property.

I am using the gremlin-scala lib.

This is the code:

val paths = startVertex.asScala().start()
      .repeat(_.outE().inV().simplePath())
      .until(_.is(endVertex.vertex))
      .path()
      .toList()


This works great. Now I want to add a filter that will filter out any Vertexes (even those in between start and end) in the path where property("num") > 50.

Seems that the filter API is only for the End Vertex?