From dbc11c3a41ea67a8981905a10f550df33cf76096 Mon Sep 17 00:00:00 2001 From: jaumeortola Date: Wed, 20 Apr 2022 12:08:37 +0200 Subject: [PATCH] improve run-on suggestions for camel case words --- .../src/main/java/morfologik/speller/Speller.java | 4 +++- .../src/test/java/morfologik/speller/SpellerTest.java | 4 ++++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/morfologik-speller/src/main/java/morfologik/speller/Speller.java b/morfologik-speller/src/main/java/morfologik/speller/Speller.java index 4337b8fe..78609dc4 100644 --- a/morfologik-speller/src/main/java/morfologik/speller/Speller.java +++ b/morfologik-speller/src/main/java/morfologik/speller/Speller.java @@ -335,7 +335,9 @@ public List 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))) { diff --git a/morfologik-speller/src/test/java/morfologik/speller/SpellerTest.java b/morfologik-speller/src/test/java/morfologik/speller/SpellerTest.java index 8dba2ad0..6f82ba1b 100644 --- a/morfologik-speller/src/test/java/morfologik/speller/SpellerTest.java +++ b/morfologik-speller/src/test/java/morfologik/speller/SpellerTest.java @@ -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());