summaryrefslogtreecommitdiff
path: root/gi/posterior-regularisation/prjava/src/util/Sorters.java
blob: 836444e52ed4cf1b59f83280c0d1a79c7a870c53 (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
31
32
33
34
35
36
37
38
39
package util;

import java.util.Comparator;

public class Sorters {
	public static class sortWordsCounts implements Comparator{
		
		/**
		 * Sorter for a pair of word id, counts. Sort ascending by counts
		 */
		public int compare(Object arg0, Object arg1) {
			Pair<Integer,Integer> p1 = (Pair<Integer,Integer>)arg0;
			Pair<Integer,Integer> p2 = (Pair<Integer,Integer>)arg1;
			if(p1.second() > p2.second()){
				return 1;
			}else{
				return -1;
			}
		}
		
	}
	
public static class sortWordsDouble implements Comparator{
		
		/**
		 * Sorter for a pair of word id, counts. Sort by counts
		 */
		public int compare(Object arg0, Object arg1) {
			Pair<Integer,Double> p1 = (Pair<Integer,Double>)arg0;
			Pair<Integer,Double> p2 = (Pair<Integer,Double>)arg1;
			if(p1.second() < p2.second()){
				return 1;
			}else{
				return -1;
			}
		}
		
	}
}