Created
March 18, 2014 18:13
-
-
Save gouthamvel/9625998 to your computer and use it in GitHub Desktop.
titan-gremlin-load-script
This file contains 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
g = TitanFactory.open('conf/titan-cassandra.properties') | |
bg = new BatchGraph(g, VertexIDType.NUMBER , 1300) | |
file = new File("/tmp/data.csv") | |
get_fields = {line-> | |
line_list = line.split(",") | |
size = line_list.size() | |
(ind_object_id, ind_temp_moneyhouse_id, ind_temp_moneyhouse_url, first_name, last_name, city_of_residence, ind_derived_state, relationship_type, org_object_id, org_temp_moneyhouse_id, org_temp_moneyhouse_url, name, city_of_registration, org_derived_state) = line_list[0..(size-1)] | |
return [ind_object_id, first_name, last_name, relationship_type, org_object_id] | |
} | |
create_vertex = {v1_id="",properties=null-> | |
print "creating vertex with " | |
print v1_id + " " | |
println properties | |
if (v1_id.toString().isInteger()) { | |
v1 = bg.getVertex(v1_id.toInteger() ) | |
if(!v1){ | |
v1 = bg.addVertex(v1_id.toInteger() ) | |
} | |
if (properties) { | |
ElementHelper.setProperties(v1, properties) | |
} | |
return v1 | |
} | |
return null | |
} | |
link_vertex = {v1_id,v2_id, relationship_type -> | |
print "linking vertexs " | |
print v1_id + " " | |
print v2_id + " " | |
println relationship_type | |
if(v2_id.toString().isInteger()){ | |
v2 = bg.getVertex(v2_id.toInteger() ) | |
if(!v2) { | |
v2 = bg.addVertex(v2_id.toInteger() ) | |
} | |
v2 = bg.getVertex(v2_id.toInteger() ) | |
v1 = bg.getVertex(v1_id.toInteger() ) | |
if (v1 == null) { | |
v1 = bg.addVertex(v1_id.toInteger() ) | |
} | |
result = null | |
if (relationship_type) { | |
result = bg.addEdge(null, v1, v2, relationship_type) | |
} | |
return result | |
} | |
} | |
file.readLines()[0..50].each({line-> | |
(ind_object_id, first_name, last_name, relationship_type, org_object_id) =get_fields(line) | |
create_vertex(ind_object_id, ["first_name":first_name, "last_name":last_name]) | |
link_vertex(ind_object_id, org_object_id, relationship_type) | |
}) | |
bg.commit() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment