Get a complete path from the traversal

31 views
Skip to first unread message

Rajesh Paudel

unread,
Oct 23, 2022, 4:15:17 PM10/23/22
to Gremlin-users
Hi, 
I have a graph which is cyclic in some cases and not in other so what I would want to do is follow a property within graph from where it starts to the end. And get it's path to all the way to end. The path could be between two vertex or between 10 vertex it doesn't matter but it should follow same property(name). So far I have tried with sack but I am missing something.

g.withSack([])
    .V()
    .where(
      outE()
        .count()
        .is(gt(0))
        .and()
        .union(
          inE().values('name'),
          outE().values('name')
        )
        .groupCount()
        .unfold()
        .where(
          select(values).is(eq(1))
        )
        .count()
        .is(gte(1))
    )
    .repeat(
     
               
              outE()
                .sack(assign)
                .by(
                    union(
                        sack().unfold(),identity().values('name')
                    )
                    .fold()
                )
                .filter( sack().unfold().dedup().count().is(1) )    // it's here for optimization
                .inV()
     
    )
    .until(
        outE().filter( sack().unfold().dedup().count().is(1) ).count().is(1)
    )
    .filter(path().unfold().count().is(gt(5)))
    .path()
    

This will give me a result but this provides me with name property that goes from middle too which is not what I want I want complete path. 
Suppose there's location 
a -> b -> c -> d -> e -> f -> g
then there's persons travelling
p1 travels from c -> d -> e ->f
p2 travels from a -> c -> d -> e ->f
p3 travels from b -> c -> d -> e

SO the path I expect is these three. And if someone travels from d -> d which could happen I would only want d one time (which simplePath should give me if I'm correct)

I'm using Neptune and my graph is medium which is about 4000vertex and about 50,000 edges and about 5K complete travels. And my case is I need to get all the places from where a certain number of people start their path from

Kelvin Lawrence

unread,
Nov 5, 2022, 2:45:57 PM11/5/22
to Gremlin-users
Just a comment that there was a quite lengthy discussion of this question on StackOverflow https://stackoverflow.com/questions/74140450/optimize-query-complete-path-based-on-a-provided-vertex-using-starting-edge-prop
Reply all
Reply to author
Forward
0 new messages