gremlin,groovy,iterating thru weighted path traversals

104 views
Skip to first unread message

sck2015

unread,
Mar 20, 2015, 1:29:41 PM3/20/15
to gremli...@googlegroups.com
 
Hi all, I am new to this and wondered has any experience using groovy to translate stuff that works in the gremlin shell, I wanted to know how to parse the results of the following gremlin code back in java , when I run in gremlin, I get an a set of weights and the corresponding paths traversed, when i look at this, I just get the set of linked pipes, does loop resolve in groovy, cannot use the pipeline.fill() to return a list, thanks


public static List  findAllPaths(Vertex s, Vertex e){ 

        //Set<Vertex> m;
        String targetName = e.getProperty("firstName");

        System.out.println("in findAllPaths start vertex name" + (String) s.getProperty("firstName"));
        System.out.println("in findAllPaths end vertex name" + (String) e.getProperty("firstName"));

        def results = []

        results = s.outE.inV.loop(2){it.object.firstName!=targetName && it.loops < 6}.path.filter{it.last().firstName==targetName}.transform{[it.findAll{it instanceof Edge}.sum{it.weight}, it]};
        
}

Stephen Mallette

unread,
Mar 23, 2015, 7:38:25 AM3/23/15
to gremli...@googlegroups.com
I don't exactly understand your question, but If you are getting "linked pipes" then you aren't iterating your pipeline somewhere.  in your above code it looks like you just need to do:

results = s.outE.inV.loop(2){it.object.firstName!=targetName && it.loops < 6}.path.filter{it.last().firstName==targetName}.transform{[it.findAll{it instanceof Edge}.sum{it.weight}, it]}.toList()

--
You received this message because you are subscribed to the Google Groups "Gremlin-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to gremlin-user...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/gremlin-users/f05f7c4c-7d85-4843-aedb-8f90e80034f8%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

sck2015

unread,
Mar 26, 2015, 1:47:03 PM3/26/15
to gremli...@googlegroups.com
thanks Stephen for your reply, this worked. I am wondering if there is a way to use the following logic to search bi-directionally, so note that I am looking at outgoing edges to incoming vertices, but what if I also wanted to look at incoming edges and outgoing vertices...

I can't use both() as that only returns vertices in the paths and i am summing weights to get the path traversal, using bothE is a problem in the syntax as how do I then specify which vertex I landed on, essentially I want to do an "OR" condition , so
outE.inV  OR inE.outV in my traversal below:

results = s.outE.inV.loop(2){it.object.firstName!=targetName && it.loops < 6}.path.filter{it.last().firstName==targetName}.transform{[it.findAll{it instanceof Edge}.sum{it.weight}, it]}.toList()

Daniel Kuppitz

unread,
Mar 26, 2015, 2:42:02 PM3/26/15
to gremli...@googlegroups.com
using bothE is a problem in the syntax as how do I then specify which vertex I landed on

s.bothE().bothV().except([s])... // or, if s is a pipe
s.as("x").bothE().bothV().except("x")...

And, just saying, in TP3 it's simply:

s.bothE().otherV()...

Cheers,
Daniel


Reply all
Reply to author
Forward
0 new messages