Skip to content

Instantly share code, notes, and snippets.

@okram
Created April 8, 2013 18:31
Show Gist options
  • Save okram/5339252 to your computer and use it in GitHub Desktop.
Save okram/5339252 to your computer and use it in GitHub Desktop.
conf = new BaseConfiguration()
conf.setProperty("storage.backend","cassandra")
//conf.setProperty("storage.hostname","localhost")
conf.setProperty("storage.hostname","10.172.137.237,10.174.89.108,10.172.111.134")
conf.setProperty("storage.batch-loading","true")
g = TitanFactory.open(conf)
bg = new BatchGraph(g, VertexIDType.NUMBER, 2000);
bg.setVertexIdKey("uid")
def getOrCreate(BatchGraph bg, long id) {
v = bg.getVertex(id)
if(null == v) v = bg.addVertex(id)
return v;
}
counter = 0;
new File('/graph/friendster/').eachFile { File f ->
println "Processing ${f}"
f.eachLine { String line ->
parts = line.trim().split(':')
if(parts.length == 1) {
v = getOrCreate(bg, Long.valueOf(parts[0].trim()))
v.setProperty('private',false)
} else if(!parts[1].equals('notfound')) {
v = getOrCreate(bg, Long.valueOf(parts[0].trim()))
if(!parts[1].equals('private')) {
v.setProperty('private',false)
parts[1].trim().split(',').each {
u = getOrCreate(bg, Long.valueOf(it))
bg.addEdge(null, v, u, 'friend')
}
} else {
v.setProperty('private',true)
}
}
if(++counter % 1000 == 0) println("Processed ${counter} vertices.")
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment