[Pipes/Gremlin] Updated the semantics of GroupCountFunctionPipe

26 views
Skip to first unread message

Marko Rodriguez

unread,
Feb 9, 2012, 5:52:00 PM2/9/12
to gremli...@googlegroups.com
Hi,

With GroupCountFunctionPipe, you can pass two functions, one that generates a key for the incoming object and a second that generates a number from the number previously existing for that key.

Regarding the second function, I have many times stumbled on trying to use a property of the incoming element as a modulator of the count value. To rectify this situation, the value function now takes a Pair<?, Number> and emits a Number. Thus, you can now do stuff like this:

gremlin> g.v(1).outE('knows').groupCount{it.inVertex}{it.a.weight + it.b}.cap.next()
==>v[2]=0.5
==>v[4]=1.0

That is, weight (via groupCount) friends by the strength of the their edge weights. You could do this before, but it required some magic using sideEffects and variables.

Anywho, a Pair is a Pipes structure class that is simple: Pair.getA(), Pair.getB(). For GroupCountFunctionPipe, getA() is the object flowing through the stream and getB() is the last numeric value in the Map associated with the key of that object.

I hope that is clear and you find it as useful as I do.

SIDENOTE: I also did some package reorganizing of com.tinkerpop.pipes.util so be wary if your SNAPSHOT code doesn't compile.

Thanks,
Marko.

http://markorodriguez.com

Pierre De Wilde

unread,
Feb 9, 2012, 7:14:08 PM2/9/12
to gremli...@googlegroups.com
Hey Marko,

The difference between inV and inVertex is confusing:

gremlin> g.e(7).inV                   
==>v[2]
gremlin> g.e(7).inVertex
==>v[2]

gremlin> g.v(1).outE('knows').inV
==>v[2]
==>v[4]
gremlin> g.v(1).outE('knows').inVertex
==>null
==>null

gremlin> g.v(1).outE('knows').groupCount{it.inV}{it.a.weight + it.b}.cap.next()     
==>[StartPipe, InVertexPipe]=1.0
==>[StartPipe, InVertexPipe]=0.5
gremlin> g.v(1).outE('knows').groupCount{it.inVertex}{it.a.weight + it.b}.cap.next()
==>v[2]=0.5
==>v[4]=1.0

Is it possible to simplify it?

Thanks,
Pierre
Reply all
Reply to author
Forward
0 new messages