Created
July 30, 2012 21:49
-
-
Save okram/3210615 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
arguments to pass in: | |
twitterId | |
traversals | |
numRecommendations | |
/////////////////////////// | |
// this function will return an ordered collection | |
// one thing to optimize is to return the map, not the set of vertices (this is more information and faster) | |
// to do so, "return [:]" and no ".keySet()" on last line. | |
// finally this only works with Gremlin 2.1.0-SNAPSHOT as this has limit() added which was not in Gremlin 2.0.0. See: | |
// gremlin> g.v(1).outE('knows')[0..30].inV.toString() | |
// ==>[StartPipe, QueryPipe(out,[knows],has:false,interval:false,limit:31,edge), IdentityPipe, InVertexPipe] | |
def random = new Random() | |
followers = g.V('twitterId',twitterId).out('follows').toList() | |
if(followers.isEmpty()) return [] | |
m = [:] | |
(0..traversals).each { | |
followers[random.nextInt(followers.size)].outE('follows')[0..29].inV.groupCount(m).iterate() | |
} | |
return m.sort{a,b -> b.value <=> a.value}[0..numRecommendations].keySet() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment