diff --git a/src/Text.java b/src/Text.java index 2ca4077..afada4b 100644 --- a/src/Text.java +++ b/src/Text.java @@ -181,28 +181,30 @@ public class Text { String firstLetter; String restLetters; 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) { //Words get formatted consistently - counter = 1; - firstLetter = word.substring(0, 1); - restLetters = word.substring(1); - word = firstLetter.toUpperCase() + restLetters; - //Words are beeing counted - if (wordbook.containsKey(word)) { - numbersList = wordbook.get(word); - counter = numbersList.get(0); - numbersList.remove(0); - numbersList.add(0, counter + 1); - if (numbersList.get(numbersList.size() - 1) < i + 1) { + if(word.length()>0){ + counter = 1; + firstLetter = word.substring(0, 1); + restLetters = word.substring(1); + word = firstLetter.toUpperCase() + restLetters; + //Words are beeing counted + if (wordbook.containsKey(word)) { + numbersList = wordbook.get(word); + counter = numbersList.get(0); + numbersList.remove(0); + 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); } - } else { - numbersList = new ArrayList<>(); - numbersList.add(counter); - numbersList.add(i + 1); + wordbook.put(word, numbersList); } - wordbook.put(word, numbersList); } } }