[Titan 0.9] Shortest Path : Eror

567 views
Skip to first unread message

Kamilos Polo

unread,
Sep 1, 2015, 8:43:56 PM9/1/15
to Aurelius
Hi all,
I'm trying to simply compute the shortest path between 2 nodes labelled "Person".

So I have ;

final Vertex startnode = graphDb.traversal().V().hasLabel("Person").has("name", 5).next(); final Vertex endNode = graphDb.traversal().V().hasLabel("Person").has("name", 6).next();
//Computing final GremlinPipeline pipe = new GremlinPipeline(startnode).as("node") .outE("knows").loop("node", new PipeFunction<LoopBundle<Vertex>, Boolean>() { @Override public Boolean compute(LoopBundle<Vertex> bundle) { return bundle.getLoops() < 10 && bundle.getObject() != endNode; } }).path();
//Showing the result if (pipe.hasNext()) { //Error at this line final ArrayList<CacheVertex> shortestPath = (ArrayList<Vertex>) pipe.next(); for (final Vertex v : shortestPath) { System.out.print(" -> " + v.property("name")); } System.out.println(); }


But I got the error : com.thinkaurelius.titan.graphdb.vertices.CacheVertex cannot be cast to com.tinkerpop.blueprints.Vertex

Daniel Kuppitz

unread,
Sep 1, 2015, 10:54:06 PM9/1/15
to aureliu...@googlegroups.com
That's a crazy way to mix Gremlin2 and Gremlin3, I didn't expect that this code would make it through the compilter. Stick with Gremlin3 and remove the TinkerPop2 dependencies from your project. Then do this:

gremlin> graph = TinkerFactory.createModern()
==>tinkergraph[vertices:6 edges:6]

gremlin> g = graph.traversal()
==>graphtraversalsource[tinkergraph[vertices:6 edges:6], standard]
gremlin> marko = g.V().has("name", "marko").next()
==>v[1]
gremlin> peter = g.V().has("name", "peter").next()
==>v[6]
gremlin> g.V(marko).repeat(both().simplePath()).until(is(peter)).limit(1).path()
==>[v[1], v[3], v[6]]

It's almost the same in Java.

Cheers,
Daniel



--
You received this message because you are subscribed to the Google Groups "Aurelius" group.
To unsubscribe from this group and stop receiving emails from it, send an email to aureliusgraph...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/aureliusgraphs/7dc18742-8240-426a-a40d-80c2b3712825%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Kamilos Polo

unread,
Sep 2, 2015, 8:00:31 AM9/2/15
to Aurelius
Hi Daniel,

thanks for your answer but how can I integrate this query into java ?

I guess I should use something like this.

graphDb = TitanFactory.build().
                set("storage.backend", "berkeleyje").
                set("storage.directory", DB_PATH_Titan).
                open();

Pipe pipe = Gremlin.compile("_().repeat(both().simplePath()).until(is(peter)).limit(1).path()");
pipe.setStarts(new SingleIterator<Vertex>( graphDb.traversal().V().has("name","marko").next()));
for(Object name : pipe) {
     System.out.println((String) name);
}   


But I get the error : No signature of method: com.tinkerpop.gremlin.groovy.jsr223.GremlinGroovyScriptEngine._() is applicable for argument types: () values: []

Furthermore how to tell to Gremlin what is "peter" vertex ?

Kamilos Polo

unread,
Sep 2, 2015, 8:12:08 AM9/2/15
to Aurelius
Seems like switching from the maven dependency
    <dependency>
      <groupId>com.tinkerpop</groupId>
      <artifactId>gremlin-groovy</artifactId>
      <version>3.0.0.M7</version>
    </dependency>
to
    <dependency>
      <groupId>com.tinkerpop.gremlin</groupId>
      <artifactId>gremlin-groovy</artifactId>
      <version>2.6.0</version>
    </dependency>

Solve the first error !

Daniel Kuppitz

unread,
Sep 2, 2015, 10:19:33 AM9/2/15
to aureliu...@googlegroups.com
You're still mixing up TinkerPop2 and TinkerPop3. Titan 0.9.0-M2 uses TinkerPop 3.0.0.M9-incubating.
Again, get your dependencies cleaned up. There's no Pipe in TinkerPop3.

Cheers,
Daniel


--
You received this message because you are subscribed to the Google Groups "Aurelius" group.
To unsubscribe from this group and stop receiving emails from it, send an email to aureliusgraph...@googlegroups.com.

Jason Plurad

unread,
Sep 2, 2015, 3:37:35 PM9/2/15
to Aurelius
I've converted Daniel's example into a program https://github.com/pluradj/titan-tp3-java-example

Kamilos, you should make sure you refer to the appropriate documentation. Titan 0.9 uses TinkerPop 3.

Daniel Kuppitz

unread,
Sep 2, 2015, 3:39:35 PM9/2/15
to aureliu...@googlegroups.com
Awesome! Thanks for that sample Jason, I was going to to create such a quick start project later today.

Cheers,
Daniel

Kamilos Polo

unread,
Sep 2, 2015, 4:09:36 PM9/2/15
to Aurelius

Thank you very much guys, it's working like a charm !

One last question, is there any efficient way to get only the vertices ?

I'm currently doing this, it comes after the code posted by Jason :

ImmutablePath path = (ImmutablePath) list.get(0);

Iterator<Object> nodes =  path.objects().iterator();
while(nodes.hasNext()){
      System.out.println(((TitanVertex)nodes.next()).properties("name"));
 }
       

Jason Plurad

unread,
Sep 2, 2015, 4:24:49 PM9/2/15
to Aurelius

http://tinkerpop.incubator.apache.org/docs/3.0.0-incubating/#repeat-step

g.V(fromNode).repeat(both().simplePath()).until(is(toNode)).limit(1).path().by("name").fill(list);
Reply all
Reply to author
Forward
0 new messages