index method error removed

This commit is contained in:
Andrin Fassbind 2021-11-12 11:19:10 +01:00
parent a7c1e411d0
commit 6b7c4fb736
1 changed files with 19 additions and 17 deletions

View File

@ -181,28 +181,30 @@ public class Text {
String firstLetter; String firstLetter;
String restLetters; String restLetters;
for (int i = 0; i < text.size(); i++) { for (int i = 0; i < text.size(); i++) {
String[] words = text.get(i).trim().toLowerCase().split("[ :;.,!?><+*}{)('/\n]+"); String[] words = text.get(i).trim().toLowerCase().split("[. ,:?!\"'-]+");
for (String word : words) { for (String word : words) {
//Words get formatted consistently //Words get formatted consistently
counter = 1; if(word.length()>0){
firstLetter = word.substring(0, 1); counter = 1;
restLetters = word.substring(1); firstLetter = word.substring(0, 1);
word = firstLetter.toUpperCase() + restLetters; restLetters = word.substring(1);
//Words are beeing counted word = firstLetter.toUpperCase() + restLetters;
if (wordbook.containsKey(word)) { //Words are beeing counted
numbersList = wordbook.get(word); if (wordbook.containsKey(word)) {
counter = numbersList.get(0); numbersList = wordbook.get(word);
numbersList.remove(0); counter = numbersList.get(0);
numbersList.add(0, counter + 1); numbersList.remove(0);
if (numbersList.get(numbersList.size() - 1) < i + 1) { numbersList.add(0, counter + 1);
if (numbersList.get(numbersList.size() - 1) < i + 1) {
numbersList.add(i + 1);
}
} else {
numbersList = new ArrayList<>();
numbersList.add(counter);
numbersList.add(i + 1); numbersList.add(i + 1);
} }
} else { wordbook.put(word, numbersList);
numbersList = new ArrayList<>();
numbersList.add(counter);
numbersList.add(i + 1);
} }
wordbook.put(word, numbersList);
} }
} }
} }