4

Sample data: TinkerPop Modern

Summary: I want to find People who have created 2 softwares.

I started with the basics, and got the count properly

g.V().hasLabel("Person").as("from" ,"to1" )
.repeat(bothE().as("e1").otherV().as("to1").dedup("from", "to1")).times(1)
.emit(filter(hasLabel("Software"))).hasLabel("Software")
.group().by(select("from").by("name")).by(count()).as("c")

Result:

>> {'Marko': 1, 'Peter': 1, 'Josh': 2}

So I tried to apply a filter but its not working (ie. Result is incorrect), what I tried:

g.V().hasLabel("Person").as("from")
.repeat(bothE().as("e1").otherV().as("to1").dedup("from", "to1")).times(1)
.filter(bothE().otherV().hasLabel("Software").count(local).is(eq(1)))
.dedup()
.values("name")

Any idea what am I doing wrong?


Sample data:

enter image description here

stephen mallette
  • 45,298
  • 5
  • 67
  • 135
Srinath Ganesh
  • 2,496
  • 2
  • 30
  • 60

1 Answers1

3

If you just need "person" vertices by edge count I don't really see why you need all that repeat() infrastructure. It's just:

gremlin> g.V().hasLabel('person').
......1>   filter(outE('created').limit(2).count().is(2))
==>v[4]

You only need to count outgoing edges because the schema is such that the "created" label only connects to "software", so you don't need to check the "software" vertex label. You limit(2) to exit the edge iteration as soon as possible but not before you have the 2 edges you are trying to count.

stephen mallette
  • 45,298
  • 5
  • 67
  • 135