Good Morning
I write a function that calculates for me the frequency of a term:
public static int tfCalculator(String[] totalterms, String termToCheck) {
int count = 0; //to count the overall occurrence of the term termToCheck
for (String s : totalterms) {
if (s.equalsIgnoreCase(termToCheck)) {
count++;
}
}
return count;
}
and after that I use it on the code below to calculate every word from a String[] words
for(String word:words){
int freq = tfCalculator(words, word);
System.out.println(word + "|" + freq);
mm+=word + "|" + freq+"\n";
}
well the problem that I have is that the words repeat here is for example the result:
- cytoskeletal|2
- network|1
- enable|1
- equal|1
- spindle|1
- cytoskeletal|2
- ...
- ...
so can someone help me to remove the repeated word and get as result like that:
- cytoskeletal|2
- network|1
- enable|1
- equal|1
- spindle|1
- ...
- ...
Thank you very much!
Setand the duplicates are goneMap<Integer, String>to map the words to their frequencies. Then again, there's quite a few better ways to calculate the frequency itself, but that's another story.int countOccurancesOfTerm(String term, String[] stringsToCheck)or something alike.Map<Integer, String>, or anathor way to calculate the Term frequency