@SuppressWarnings("deprecation")
protected Map<String,Float> calculateWordScores(
List<List<String>> phrases) {
Bag<String> wordFreq = new HashBag<String>();
Bag<String> wordDegree = new HashBag<String>();
for (List<String> phrase : phrases) {
int degree = -1;
for (String word : phrase) {
if (NumberUtils.isNumber(word)) continue;
else degree++;
}
for (String word : phrase) {
wordFreq.add(word);
wordDegree.add(word, degree);
}
}
for (String word : wordFreq.uniqueSet()) {
wordDegree.add(word, wordFreq.getCount(word));
}
Map<String,Float> wordScores = new HashMap<String,Float>();
for (String word : wordFreq.uniqueSet()) {
float score = (float) wordDegree.getCount(word) /
(float) wordFreq.getCount(word);
wordScores.put(word, score);
}
return wordScores;
}