I have a HashMap
called List<String, Intger> wordFreqMap
whose size
is 234
wordFreqMap = {radiology=1, shift=2, mummy=1, empirical=1, awful=1, geoff=1, .......}
I want to calculate the term frequency
of each word.
term frequency = frequency of term / total number of terms
public static Map<String, Double> getTFMap (Map<String, Integer> wordFreqMap)
{
Map<String, Double> tfMap = new HashMap<String, Double>();
int noOfTerms = wordFreqMap.size();
Double tf;
for (Entry<String, Integer> word : wordFreqMap.entrySet() )
{
tf = (double) ( word.getValue() / noOfTerms );
tfMap.put(word.getKey(), tf );
}
return tfMap;
}
My problem is that, tfMap
is returning {radiology=0.0, shift=0.0, mummy=0.0, empirical=0.0, awful=0.0, geoff=0.0, .....}
I don't understand why it returns 0.0
for every term. How do I fix it?
I should get something like {radiology=0.00427, shift=0.00854, ...}