| 73 | } |
| 74 | |
| 75 | public static int parseSimple(int wordStart, int wordEnd) { |
| 76 | if (wordEnd >= sentence.length()) { |
| 77 | return wordEnd - wordStart; |
| 78 | } |
| 79 | |
| 80 | String word = sentence.substring(wordStart, wordEnd + 1); |
| 81 | |
| 82 | /* break current word */ |
| 83 | int bestExact = parseSimple(wordEnd + 1, wordEnd + 1); |
| 84 | if (!dictionary.contains(word, true)) { |
| 85 | bestExact += word.length(); |
| 86 | } |
| 87 | |
| 88 | /* extend current word */ |
| 89 | int bestExtend = parseSimple(wordStart, wordEnd + 1); |
| 90 | |
| 91 | /* find best */ |
| 92 | return Math.min(bestExact, bestExtend); |
| 93 | } |
| 94 | |
| 95 | public static String clean(String str) { |
| 96 | char[] punctuation = {',', '"', '!', '.', '\'', '?', ','}; |