<Jump out from behind bushes/>

Hey hey,

> Thank you again, Marko. Let's try with a query that I'm not able to
> build in Gremlin. Looking at the property graph, I need the final
> vertices of all the paths of length 3, with at least one property
> "name" equals to "josh" in some vertex except the first one.


Here is the concise pro-style, where 'both' traverses both incoming and 
outgoing adjacent vertices.

        g.V.both.loop(1){it.loops < 4}[[name:'josh']]

Here is the less than pro-style (as('x') is a way to name a step so its more 
readable where to "loop back to"):

        g.V.as('x').both.loop('x'){it.loops < 4}[[name:'josh']]

This will give you the actual paths with, of course, the last element in the 
path being the vertex with name 'josh' (v[4]).

        g.V.both.loop(1){it.loops < 4}[[name:'josh']].paths

Finally, realize that you might incur "reverberation" in your paths. 

        gremlin> g.V.both.loop(1){it.loops < 4}[[name:'josh']].paths
        ==>[v[3], v[1], v[3], v[4]] // reverb
        ==>[v[3], v[4], v[1], v[4]] // reverb
        ==>[v[3], v[4], v[5], v[4]] // reverb
        ==>[v[3], v[4], v[3], v[4]] // reverb
        ==>[v[3], v[6], v[3], v[4]] // reverb
        ==>[v[2], v[1], v[3], v[4]]
        ==>[v[1], v[2], v[1], v[4]] // reverb
        ==>[v[1], v[3], v[1], v[4]] // reverb
        ==>[v[1], v[4], v[1], v[4]] // reverb
        ==>[v[1], v[4], v[5], v[4]] // reverb
        ==>[v[1], v[4], v[3], v[4]] // reverb
        ==>[v[6], v[3], v[1], v[4]]
        ==>[v[5], v[4], v[1], v[4]] // reverb
        ==>[v[5], v[4], v[5], v[4]] // reverb
        ==>[v[5], v[4], v[3], v[4]] // reverb
        ==>[v[4], v[1], v[3], v[4]] // reverb
        ==>[v[4], v[3], v[1], v[4]] // reverb

As such you can use uniquePath to remove reverberant paths:

        gremlin> g.V.both.loop(1){it.loops < 4}[[name:'josh']].uniquePath 
        ==>v[4]
        ==>v[4]
        gremlin> g.V.both.loop(1){it.loops < 4}[[name:'josh']].uniquePath.paths
        ==>[v[2], v[1], v[3], v[4]]
        ==>[v[6], v[3], v[1], v[4]]

Hope that helps,
Marko.

http://markorodriguez.com
_______________________________________________
Neo4j mailing list
[email protected]
https://lists.neo4j.org/mailman/listinfo/user

Reply via email to