Skip to content

Commit

Permalink
improve run-on suggestions for camel case words
Browse files Browse the repository at this point in the history
  • Loading branch information
jaumeortola committed Apr 20, 2022
1 parent 3364cf6 commit dbc11c3
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -335,7 +335,9 @@ public List<CandidateData> replaceRunOnWordCandidates(final String original) {
// chop from left to right
final String prefix = wordToCheck.substring(0, i);
final String suffix = wordToCheck.substring(i);
if (isInDictionary(suffix)) {
if (isInDictionary(suffix)
// camel case words: e.g. GreatElephant
|| (!isNotCapitalizedWord(suffix) && isInDictionary(suffix.toLowerCase(locale)))) {
if (isInDictionary(prefix)) {
addReplacement(candidates, prefix + " " + suffix);
} else if (Character.isUpperCase(prefix.charAt(0)) && isInDictionary(prefix.toLowerCase(locale))) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,10 @@ public void testRunonWords() throws IOException {
final URL url2 = getClass().getResource("single-char-word.dict");
final Speller spell2 = new Speller(Dictionary.read(url2));
assertTrue(spell2.replaceRunOnWords("alot").contains("a lot"));
assertTrue(spell2.replaceRunOnWords("Alot").contains("A lot"));
assertTrue(spell2.replaceRunOnWords("ALot").contains("A Lot"));
assertTrue(spell2.replaceRunOnWords("LotAmusement").contains("Lot Amusement"));
//TODO? assertTrue(spell2.replaceRunOnWords("LOTAMUSEMENT").contains("LOT AMUSEMENT"));
assertTrue(spell2.replaceRunOnWords("aalot").contains("aa lot"));
assertTrue(spell2.replaceRunOnWords("aamusement").contains("a amusement"));
assertTrue(spell2.replaceRunOnWords("clot").isEmpty());
Expand Down

0 comments on commit dbc11c3

Please sign in to comment.