Skip to content

Instantly share code, notes, and snippets.

@rjbriody
Created September 6, 2016 20:22
Show Gist options
  • Save rjbriody/1aa82bd8952dc4a46a6fa597716c1987 to your computer and use it in GitHub Desktop.
Save rjbriody/1aa82bd8952dc4a46a6fa597716c1987 to your computer and use it in GitHub Desktop.
C* Summit 2016 - Network Analysis Adventure
// Set DSE Graph to Development mode
schema.config().option('graph.schema_mode').set('Development')
// Remove myself (the ego vertex) for demonstration purposes since I am connected to everyone
g.V().has('screen_name', 'bobbriody').drop()
// Graph Size
long vertexCount = g.V().hasLabel('user').count().next()
long edgeCount = g.E().hasLabel('follows').count().next()
'Vertices: ' + vertexCount + '\nEdges: ' + edgeCount
// Degree Density
'Density: ' + edgeCount / (vertexCount * (vertexCount -1))
// Degree Distribution
g.V().groupCount().by(inE('follows').count())
// Where does everyone live?
g.V().has('time_zone').
groupCount().by('time_zone').
order(local).by(values, decr).next()
// Degree Centrality
g.V().hasLabel('user').as("person").map(inE('follows').count()).as("followers").
select("person","followers").by("screen_name").by().
order().by(select("followers"), decr).
limit(10)
// PageRank
g.V().hasLabel('user').
pageRank().
by(outE('follows')).
by('pageRank').
order().by('pageRank',decr).
limit(10)
// Community Detection
// Local Example
// Just grabbing the Vertex IDs of the top 10 PageRank Vertices. Used later to visualize as a subgraph.
pageRankTopTenIds = g.V().
pageRank().
by(outE('follows')).
by('pageRank').
order().by('pageRank', decr).
id().
limit(10).
store('x').cap('x').next()
g.V(pageRankTopTenIds)
// Aggregate Example
Map communities =
g.V().hasLabel('user').
peerPressure().by('cluster').by(outE('follows')).
group().by('cluster').by('screen_name').
next()
StringBuilder prettyPrint = new StringBuilder()
communities.
findAll{ it.value.size() > 1 }.
sort{ a, b -> b.value.size() <=> a.value.size() }.
each{ it ->
prettyPrint.
append(g.V(it.key).values('screen_name').next()).append('\'s community: ').
append('\n\t').append(it.value).
append('\n')
}
prettyPrint.toString()
// Unreciprocated followship
g.V().as("followers").
out("follows").as("snobs").
not(
out("follows").where(eq("followers"))
).
select("followers","snobs").by('screen_name')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment