summaryrefslogtreecommitdiff
path: root/src/Chapter4/util/InDegreeScorer.java
blob: 014adc62deeb4f9dac3110d5fef0ef9a4bcf8366 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
package Chapter4.util;

import edu.uci.ics.jung.algorithms.scoring.VertexScorer;
import edu.uci.ics.jung.graph.Hypergraph;

/**
 * This is a Jung Node Scorer that computes the 
 * In-Degree Centrality of nodes.
 */
public class InDegreeScorer<T> implements VertexScorer<T, Double>{

	//The graph representation in JUNG.
	private Hypergraph<T, ?> graph;
	
	/**
	 * Initialize the graph scorer.
	 * @param graph
	 * The graph we wish to score.
	 */
	public InDegreeScorer(Hypergraph<T, ?> graph){
		this.graph = graph;
	}
	
	/**
	 * @return The In-Degree Centrality of the vertex. 
	 */
	public Double getVertexScore(T node) {
		return (double) graph.getInEdges(node).size();
	}
}