gremlin query to count by path-length all paths between nodes that share the same (specified) label

35 views Asked by At

I have a graph with no cycles. Each vertex has a label. For those with a specific label, call it "A", I want to count

  • how many nodes with label "A" are not connected to any other nodes with label "A"
  • how many are connected in a chain of length 2: (A) > (A)
  • how many are connected in a chain of length 3: (A) > (A) > (A)
  • and so on, up to the longest such path.

I only need to follow out edges.

I have brute forced something related with a set of queries (below) but I want to generalize into one query and not count longer paths with the shorter paths.

g.V().has('label','A').outE().inV().has('label', 'A').count()
g.V().has('label','A').outE().inV().has('label', 'A').outE().inV().has('label', 'segment').count()
g.V().has('label','A').outE().inV().has('label', 'A').outE().inV().has('label', 'A').outE().inV().has('label', 'A').count()

Thanks

0

There are 0 answers