What you're missing is (1) initializing Gremlin, and (2) collecting
results.  To initialize Gremlin, your code needs to execute the following
once (and preferably only once):

import com.tinkerpop.gremlin.groovy.Gremlin

Gremlin.load()


Once you've done that, you can run your query.  Right now your method
creates a Gremlin query, but hasn't started it.  There are lots of ways to
collect results; one way would be to use the Groovy collect() if you're
expecting a list of results. For something more complicated, such as the
what you're doing, I'd suggest something like this:

import com.tinkerpop.pipes.util.structures.Table

def t = new Table()
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]}.table( t ).iterate()


That should give you a table structure that contains your results.

- Craig -

On Fri, Mar 20, 2015 at 12:24 PM, sck2015 <[email protected]> wrote:

> I am trying to find path traversals and explore them by increasing weight,
> I was able to do this in gremlin and was trying to replicate the code in
> groovy (using groovyc to compile a groovy file and integrate with my other
> java code)... Can someone point me to documentation or how to execute the
> following query in a .groovy file, my understanding is that gremlin is
> interpreted by groovy but I cannot cache the results of the following
> pipeline which should return a set of weights and paths:
>
>  public static List  findAllPaths(Vertex s, Vertex e) {
>         String targetName = e.getProperty("firstName");
>         // look at paths that end at target, match on first name, calc
> weights of these paths
>         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]};
>         // how to save results of pipe
>
>     }
>
> I've gotten simple gremlin queries to return and pass back a list to java,
> I could try stringing together gremlin pipelines but I thought the point of
> having .groovy files was to be able to use/integrate gremlin directly to
> talk to java, thanks, Sonu
>
> --
>
> ---
> You received this message because you are subscribed to the Google Groups
> "OrientDB" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to [email protected].
> For more options, visit https://groups.google.com/d/optout.
>

-- 

--- 
You received this message because you are subscribed to the Google Groups 
"OrientDB" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/d/optout.

Reply via email to