I have a multigraph and I am interested in counting the number of edges connecting each pair of nodes; moreover, I would need to get, for each pair of nodes, the maximum value of a certain attribute.
Unfortunately it seems to me we can use .group().by(...)
with one attribute only, while I would need to group by inV
and outV
.
In Cypher I would write something like
MATCH (e0: Employee)-[fb: R]-> (e1: Employee)
WITH e0, e1, count(*) AS frequency, min(fb.value) AS min_val
RETURN e0, e1, frequency, min_val
Can anybody help?
Cheers!
Answered on the Gremlin users mailing list, but to close the circle, here's the traversal again:
gremlin> g.V().as("e0").outE("e").as("e").inV().as("e1").select("e0","e","e1").
gremlin> group().by(select("e0","e1").by("name")).
gremlin> by(fold().match(__.as("x").count(local).as("freq"),
gremlin> __.as("x").unfold().select("e").by("value").max().as("max")).select("freq","max")
gremlin> ).next()
==>{e0=c, e1=d}={freq=1, max=9}
==>{e0=b, e1=d}={freq=1, max=9}
==>{e0=f, e1=h}={freq=1, max=9}
==>{e0=e, e1=h}={freq=1, max=9}
==>{e0=a, e1=b}={freq=2, max=10000}
==>{e0=b, e1=c}={freq=4, max=4}
==>{e0=e, e1=f}={freq=1, max=9}
==>{e0=f, e1=g}={freq=1, max=9}
==>{e0=a, e1=c}={freq=1, max=9}