Dear all,
I would like to ask if there is a way to define a filter globally. That is, for a Pipeline, or even for a graph (so for all Pipelines processed over that graph). The idea for such a global filter is that it will provide a way to work on a sub graph without changing the rest of the code (the other Pipelines).
The rational for that is as follows:
Suppose you have a big graph of people who know each other. Each person has an age.
And suppose you have already created a nice application looking at the connections between the people.
But now, you need to see connections only between kids. How do you do that? You want to look at the very same graph, but filter all the adults from it.
Usually, you will need to go over all the pipelines in the application, and after to each step emitting vertices, add a step like .has(“age”, T.lt, 12)
But this can be a big work (which also ends up with not very elegant code) for quite a simple problem. Obviously, later you might want to look at other parts of the graph (e.g. all people in other ages, or with certain professions…).
I could not find if gremlin-java supports something like that and wonder if anyone has any suggestion.
Thanks,
Rani
--
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.
For more options, visit https://groups.google.com/groups/opt_out.
Hi Marko,
There are few problems that will not be solved by this suggestion:
In the application I might just get all vertices with g.V(). So now I have to add a filter to these statements.
Also, such a filter has to be after each step emitting vertices, not only in the end of the
path. For example if we are looking for the friends of the friends of someone,
we will have something like:
.out(“knows”).out(“knows”).simplePath()
If we want it only for connections between kids, the following will not be
enough:
.out(“knows”).out(“knows”).simplePath().has(“age”, T.lt, 12)
because a child can know an adult that knows another child that is not known to
the first child. So the following path will be needed:
.has(“age”, T.lt, 12).out(“knows”).has(“age”, T.lt, 12).out(“knows”).simplePath().has(“age”,
T.lt, 12)
In general, adding a filter (has(), or filter()) makes all the code very long and complex.
I am looking for something like:
g.setGlobalPipe(pipe.has(“age”, T.lt, 12))
that will filter all the vertices whenever the graph g is accessed.
Kind regards,
Rani
a = g.addVertex(['name':'A','age':10])b = g.addVertex(['name':'B','age':11])c = g.addVertex(['name':'C','age':12])d = g.addVertex(['name':'D','age':13])g.addEdge(a, b, 'knows')g.addEdge(a, c, 'knows')g.addEdge(b, c, 'knows')g.addEdge(b, d, 'knows')
Gremlin.defineStep('fof', [Vertex,Pipe], { closure ->pipe = _().out('knows')if (closure != null) {pipe = pipe.filter(closure)}pipe = pipe.out('knows')if (closure != null) {pipe = pipe.filter(closure)}pipe})
gremlin> a.fof().map()==>{name=C, age=12}==>{name=D, age=13}gremlin> a.fof{ it.age < 13 }.map()==>{name=C, age=12}gremlin> a.fof{ it.age < 12 }.map()gremlin>
gremlin> myFilter = {true}; a.out('knows').filter(myFilter).out('knows').filter(myFilter).map()
==>{name=C, age=12}==>{name=D, age=13}
gremlin> myFilter = {it.age < 13}; a.out('knows').filter(myFilter).out('knows').filter(myFilter).map()==>{name=C, age=12}gremlin> myFilter = {it.age < 12}; a.out('knows').filter(myFilter).out('knows').filter(myFilter).map()gremlin>