A library that calculates useful social metrics from a social graph, using Neo4j and written in Scala.
- Compatible with the JVM.
- Degree centrality metric calculation.
- Betweenness centrality metric calculation.
- Closeness centrality metric calculation.
- Graph snapshots for efficient global centralities calculation and records over time.
To create a packaged jar just run this command in the root dorectory:
cd path/to/census
sbt assembly
The .jar will be created in path/to/census/target/scala-2.10/census-vX.X.jar
.
Note: Normally you will need to calculate this social metrics globaly (for all nodes), in that case you should use the Snapshot feature.
First import the api package.
import edu.udlap.census.CensusAPI;
Then instantiate the api. The constructor recieves a string which is the path to where the database will be created.
CensusAPI api = new CensusAPI("target/testdb");
Inserts a person with specified id and name into the graph database.
Relates two persons with specified ids.
Calculates the relative degree centrality of a node with the specified id.
Calculates the betweenness centrality of a node with the specified id.
Calculates the closeness centrality of a node with the specified id.
A graph snapshot is a recorded state of a graph at any time, when created it calculates the 3 centralities and all shortest paths for ALL the nodes in the graph, it is useful because it is more efficient overall and you can have a record of change.
Note: a snapshot calculates the relative betweenness and degree of the nodes, which should be a much more useful measure.
First import the Snapshot and Graph classes.
import edu.udlap.graph.Graph;
import edu.udlap.graph.Snapshot;
Then create a graph.
Graph graph = new Graph("path/to/the/graph/db");
After that add some persons to the graph and relate them.
graph.insertPerson("ID01", "Franco");
graph.insertPerson("ID02", "Francisco");
graph.relatePersons("ID01", "ID02");
Then create a snapshot with the graph.
Snapshot snapshot = new Snapshot(graph);
Depending on how many nodes the calculation of the 3 centralities on ALL nodes could take some time; after that time is finished you can access to the data through the centralities caches or though the centrality methods.
graph.degreeOf("ID01");
graph.betweennessOf("ID01");
graph.closenessOf("ID01");
The number of nodes in the graph.
A List of all the ids in the graph.
A System.currentTimeMillis
record of the snapshot.
A Map <String, List <List <String>>>
with all the shortest paths between all nodes. They key is in the form <id1>-<id2>
.
A Map <String, Float>
with all the degree centralities. The key is in the form <node-id>
, for example:
float francosDegree = snapshot.degreeCache.get("ID01");
A Map <String, Float>
with all the betweenness centralities.
A Map <String, Float>
with all the closeness centralities.
Retrieves the relative degree centrality of a node with the specified id.
Retrieves the relative betweenness centrality of a node with the specified id.
Retrieves the closeness centrality of a node with the specified id.
- Parallelize the shortest paths computation for the snapshot.
The MIT License (MIT)
Copyright (c) 2013 Francisco Miguel Arámburo Torres
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.