//put entries in bag to get count
String entryBuilder;
Bag <String> bagOfEntries = new <String>HashBag();
for (ArrayList<String> temp : output)
{
entryBuilder = "";
for (String tempWord : temp)
{
String scrap = tempWord + " ";
entryBuilder += scrap;
}
bagOfEntries.add(entryBuilder);
}
//make a map with values - count and keys - string and sort by frequency
Map<String, Integer> frequentWords = new <String, Integer>HashMap();
for (String pattern : bagOfEntries.uniqueSet()) {
frequentWords.put(pattern, bagOfEntries.getCount(pattern));
}
Map.Entry<String, Integer>[] entries = frequentWords.entrySet().toArray(new Map.Entry[0]);
Arrays.sort(entries, new Comparator<Map.Entry<String, Integer>>() {
public int compare(Map.Entry<String, Integer> o1, Map.Entry<String, Integer> o2) {
return o2.getValue().compareTo(o1.getValue());