LinkedDataSail

89 views
Skip to first unread message

Roberto Mirizzi

unread,
May 30, 2012, 5:31:25 AM5/30/12
to gremli...@googlegroups.com
Dear All,

I'm using Gremlin via Java.
More precisely, I'm trying to make it work the example about the Spreading Activation at https://github.com/tinkerpop/gremlin/wiki/LinkedData-Sail#wiki-recommendation.

I have some problems with the Java equivalent of the loop:
.loop(4){it.loops < 4}

In fact, I get the following expection:

Exception in thread "main" java.lang.ClassCastException: com.tinkerpop.blueprints.impls.sail.SailVertex cannot be cast to com.tinkerpop.blueprints.Edge
    at com.tinkerpop.gremlin.pipes.transform.EdgesVerticesPipe.processNextStart(EdgesVerticesPipe.java:37)
    at com.tinkerpop.gremlin.pipes.transform.EdgesVerticesPipe.processNextStart(EdgesVerticesPipe.java:12)
    at com.tinkerpop.pipes.AbstractPipe.next(AbstractPipe.java:81)
    at com.tinkerpop.pipes.sideeffect.GroupCountPipe.processNextStart(GroupCountPipe.java:28)
    at com.tinkerpop.pipes.AbstractPipe.next(AbstractPipe.java:81)
    at com.tinkerpop.pipes.util.Pipeline.next(Pipeline.java:115)
    at com.tinkerpop.pipes.branch.LoopPipe.processNextStart(LoopPipe.java:44)
    at com.tinkerpop.pipes.AbstractPipe.next(AbstractPipe.java:81)
    at com.tinkerpop.pipes.util.Pipeline.next(Pipeline.java:115)
    at com.tinkerpop.pipes.util.PipeHelper.iterate(PipeHelper.java:36)
    at com.tinkerpop.gremlin.java.GremlinPipeline.iterate(GremlinPipeline.java:1083)
    at foo.Test.main(Test.java:128)


Here is my code:
###################################################
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import com.tinkerpop.blueprints.Edge;
import com.tinkerpop.blueprints.TransactionalGraph.Conclusion;
import com.tinkerpop.blueprints.Vertex;
import com.tinkerpop.blueprints.impls.sail.SailGraph;
import com.tinkerpop.blueprints.impls.sail.impls.LinkedDataSailGraph;
import com.tinkerpop.blueprints.impls.sail.impls.MemoryStoreSailGraph;
import com.tinkerpop.gremlin.java.GremlinPipeline;
import com.tinkerpop.pipes.PipeFunction;
import com.tinkerpop.pipes.branch.LoopPipe.LoopBundle;


public class Test {
    public static void main(String[] args) {
        SailGraph g = new LinkedDataSailGraph(new MemoryStoreSailGraph());

        Vertex v = g.getVertex("http://dbpedia.org/resource/The_Godfather");
       
       final List<String> prop = new ArrayList<String>();
       prop.add("http://dbpedia.org/ontology/starring");
       prop.add("http://purl.org/dc/terms/subject");
       prop.add("http://www.w3.org/2004/02/skos/core#broader");


        HashMap<Vertex, Number> m = new HashMap<Vertex, Number>();
        GremlinPipeline pipe = new GremlinPipeline(v).outE()
                .filter(new PipeFunction<Edge, Boolean>() {
                    @Override
                    public Boolean compute(Edge edge) {
                        return prop.contains(edge.getLabel());
                    }
                }).random(0.5).inV().groupCount(m)
                .loop(4, new PipeFunction<LoopBundle<Vertex>, Boolean>() {
                    @Override
                    public Boolean compute(LoopBundle<Vertex> argument) {
                        return (argument.getLoops() < 4);
                    }
                });

        pipe.iterate(); ////////////////(this is line 128 where the exception is raised)

        System.out.println(m);

        g.shutdown();
    }
}
###################################################

If I remove the loop part, I do not get any exceptions. Moreover, if I comment the "random(0.5)" part, or try with a different number of iterations, sometimes I don't get any exception.

If I try the same procedure but directly via gremlin (via the console, as specified in the previous link: https://github.com/tinkerpop/gremlin/wiki/LinkedData-Sail#wiki-recommendation) I do not get any errors.

Could you figure out where is the problem and what am I missing?

Thank you very much for you support.

Cheers.

--
Roberto Mirizzi
PhD
http://sisinflab.poliba.it/mirizzi

Marko Rodriguez

unread,
May 30, 2012, 9:10:51 AM5/30/12
to gremli...@googlegroups.com
Hi,

That sounds like you are looping back to early. Do a System.out.println() on your Pipe and see how the loop is working. You are sending back and edge and treating it like a vertex. --- Then you will want to do loop(5).

Good luck,
Marko.
Reply all
Reply to author
Forward
0 new messages