How to access the vertices of a path in Gremlin through Java? -


i'm using java access gremlin. have following lines of code creating path between 2 vertices in created graph:

//begin simple path finding         vertex fromnode = g.v().has("name", "i2").next();         vertex tonode = g.v().has("name", "state1").next();         arraylist list = new arraylist();         g.v(fromnode).repeat(both().simplepath()).until(is(tonode)).limit(1).path().fill(list); 

however, @ point i"m stuck. can print out list using list.tostring() , vertices (i believe) on path. however, want vertices themselves, access , potentially mutate data. instance, isn't enough know v[32] on path if can't access id 32 itself.

i should mention i'm bit new please let me know if i'm using outdated/incorrect practices.

you ended list filled path objects. think you're looking unfold() step (see docs) can unroll/flatten out the elements in path put list. here's gremlin console session showing it:

gremlin> graph = tinkergraph.open() ==>tinkergraph[vertices:0 edges:0] gremlin> g = graph.traversal() ==>graphtraversalsource[tinkergraph[vertices:0 edges:0], standard] gremlin> g.addv("name", "i2").as("a").addv("name", "state1").adde("to").from("a").tolist() ==>e[4][0-to->2] gremlin> fromnode = g.v().has("name", "i2").next() ==>v[0] gremlin> tonode = g.v().has("name", "state1").next() ==>v[2] gremlin> l = new arraylist() gremlin> g.v(fromnode).repeat(both().simplepath()).until(is(tonode)).limit(1).path().fill(l) ==>[v[0],v[2]] gremlin> l = []; g.v(fromnode).repeat(both().simplepath()).until(is(tonode)).limit(1).path().fill(l) ==>[v[0],v[2]] gremlin> l = []; g.v(fromnode).repeat(both().simplepath()).until(is(tonode)).limit(1).path().unfold().fill(l) ==>v[0] ==>v[2] gremlin> l[0].getclass() ==>class org.apache.tinkerpop.gremlin.tinkergraph.structure.tinkervertex gremlin> l[0].property("name", "j3") // mutate vertex's name ==>vp[name->i3] gremlin> g.v(fromnode).valuemap(true).tolist() ==>[id:0,name:[j3],label:vertex] 

Comments

Popular posts from this blog

php - Vagrant up error - Uncaught Reflection Exception: Class DOMDocument does not exist -

vue.js - Create hooks for automated testing -

.htaccess - ERR_TOO_MANY_REDIRECTS htaccess -