0

I use Titan Graph Database (0.4.1 release). I have a directed graph and I am trying to find the neighbors of a node. I use the GremlinPipeLine with the following code:

GremlinPipeline<String, Vertex> pipe = new GremlinPipeline<String, Vertex>(vertex).both("similar");

I suppose that this is caused because if I have the following edge list of a directed graph

1   32
32  1

the above function return node 32 two times. Is there a way to filter this with the GremlinPipeline or should I do it manually?

P.S. any other way to find the neighbors of a node is also accepted.

salvador
  • 1,079
  • 3
  • 14
  • 28

1 Answers1

0

You can use dedup and map to do a sort of Gremlin DISTINCT-like equivalent query:

GremlinPipeline<String, Vertex> pipe = new GremlinPipeline<String, Vertex>(vertex).both("similar").dedup(new PipeFunction<Vertex,String>() {
  public String compute(Vertex vertex) {
    return vertex.id;
  }
}).back(1);

The last back returns you the same kind of result you should have with the both call.

MarcoL
  • 9,829
  • 3
  • 37
  • 50