libSNA: Examples

Simple Social Network Analysis(SNA) example

#create a SocialNetwork object
sna = SocialNetwork()

#load data in from a comma seperated value (CSV) file
sna.loadFromCsv("flintstones.csv")

#run a measure against the network
sna.runMeasure("betweennessCentrality")

#print the results to standard output (STDOUT)
sna.displayResults("betweennessCentrality")

#save the network to graphML for use in an external tool
sna.saveToGraphMl("flintstones.xml")

Slightly more complicated Social Network Analysis (SNA) example

#create a SocialNetwork object
sna = SocialNetwork()

#load data in from a comma seperated value (CSV) file
sna.loadFromCsv("flintstones.csv")
#load additional data in
sna.loadFromCsv("smurfs.csv")

#run a measure against the network
sna.runMeasure("betweennessCentrality")
#run another measure
sna.runMeasure("totaldegreeCentrality")

#print the results to standard output (STDOUT)
sna.displayResults("betweennessCentrality")
sna.displayResults("totaldegreeCentrality")

#save the merged network of Flintstones and Smurfs to a file
sna.saveToCsv("flintstones_and_smurfs.csv")