Find all in and out edges from a nodes using gremlin and java

39 views
Skip to first unread message

Amrutha Valli

unread,
Jul 4, 2016, 12:35:54 PM7/4/16
to OrientDB
Hi,

I am trying to get all the in and out nodes from the node using java and gremlin i tried bel;ow and able to get all the node ids now i want to get the properties also.

below is the  code and output


GremlinPipeline<String, List> sources =new GremlinPipeline().start((graph.getVertices("name", "HEY BO DIDDLEY"))).bothE().outV().path();
Iterator iter = sources.iterator();
   while(iter.hasNext()) {
       System.out.println("-it--"+iter.next());
   }

}



output:
-it--[v[#9:1], e[#11:0][#9:1-followed_by->#9:2], v[#9:1]] -it--[v[#9:1], e[#11:1][#9:1-followed_by->#9:3], v[#9:1]] -it--[v[#9:1], e[#11:2][#9:1-followed_by->#9:4], v[#9:1]] -it--[v[#9:1], e[#11:3][#9:1-followed_by->#9:5], v[#9:1]] -it--[v[#9:1], e[#11:4][#9:1-followed_by->#9:6], v[#9:1]] -it--[v[#9:1], e[#12:0][#9:1-written_by->#9:7], v[#9:1]] -it--[v[#9:1], e[#13:0][#9:1-sung_by->#9:8], v[#9:1]] -it--[v[#9:1], e[#11:745][#9:3-followed_by->#9:1], v[#9:3]] -it--[v[#9:1], e[#11:713][#9:5-followed_by->#9:1], v[#9:5]] -it--[v[#9:1], e[#11:2407][#9:145-followed_by->#9:1], v[#9:145]] -it--[v[#9:1], e[#11:6235][#9:124-followed_by->#9:1], v[#9:124]]    

alessand...@gmail.com

unread,
Jul 5, 2016, 5:37:57 AM7/5/16
to OrientDB
Hi,
you could try with this code

GremlinPipeline<Vertex, Vertex> sources =new GremlinPipeline().start((g.getVertices("name", "HEY BO DIDDLEY"))).bothE().outV().path();
 
List<Vertex> fls3 = sources.toList();
 
for(int i=0;i<fls3.size();i++){
 
List<Object> l=(List<Object>) fls3.get(i);
 
Vertex in=(Vertex) l.get(0);
 
Vertex out=(Vertex) l.get(2);
 
System.out.println(in.getProperty("yourproperty") + "  " + out.getProperty("yourproperty"));
 
}

Hope it helps.

Best regards,
Alessandro

Amrutha Valli

unread,
Jul 5, 2016, 5:57:09 AM7/5/16
to OrientDB
I am able to achieve this as 
GremlinPipeline<String, List> sources =new GremlinPipeline().start((graph.getVertices("name", "HEY BO DIDDLEY"))).bothE().bothV().simplePath().path();
Iterator iter = sources.iterator();
Object element =null;
while(iter.hasNext()) {
element = iter.next();
                 ArrayList<Object> newObj = (ArrayList<Object>) (element);
                 OrientVertex source = (OrientVertex) newObj.get(0);
                 OrientVertex target = (OrientVertex) newObj.get(2);
                 System.out.println("source"+source);
                 System.out.println("target"+target);
               
                 OrientEdge link = (OrientEdge) newObj.get(1);
                 System.out.println("link"+link);
}
finally if i am getting vertex id and i can get the properties from it by using graph.getVertices(rid, value).iterator().next()
Reply all
Reply to author
Forward
0 new messages