From 2f6a7807f7180fb467e3d06f2af4263a45759c28 Mon Sep 17 00:00:00 2001 From: Ben Culkin Date: Mon, 13 Apr 2020 18:44:24 -0400 Subject: Cleanup pass Pass to do some cleanups --- src/main/java/bjc/inflexion/EnglishUtils.java | 29 +++++++++++++++++---------- 1 file changed, 18 insertions(+), 11 deletions(-) (limited to 'src/main/java/bjc/inflexion/EnglishUtils.java') diff --git a/src/main/java/bjc/inflexion/EnglishUtils.java b/src/main/java/bjc/inflexion/EnglishUtils.java index cee804d..0fafe86 100644 --- a/src/main/java/bjc/inflexion/EnglishUtils.java +++ b/src/main/java/bjc/inflexion/EnglishUtils.java @@ -24,7 +24,9 @@ import java.util.regex.Pattern; public class EnglishUtils { /** * Pick an indefinite article ('a' or 'an') for a phrase. - * @param phrase The phrase to pick an article for. + * + * @param phrase + * The phrase to pick an article for. * @return The article to use for the phrase. */ public static String pickIndefinite(String phrase) { @@ -36,10 +38,10 @@ public class EnglishUtils { return "a"; } - // Getting the first word + // Getting the first word pattern = Pattern.compile("(\\w+)\\s*.*"); matcher = pattern.matcher(phrase); - if(matcher.matches() == true) { + if (matcher.matches() == true) { word = matcher.group(1); } else { return "an"; @@ -48,37 +50,42 @@ public class EnglishUtils { lowercaseWord = word.toLowerCase(); // Specific start of words that should be preceded by 'an' - String [] altCases = { "euler", "heir", "honest", "hono" }; + String[] altCases = { + "euler", "heir", "honest", "hono" + }; for (String altCase : altCases) { if (lowercaseWord.startsWith(altCase) == true) { return "an"; } } - if (lowercaseWord.startsWith("hour") == true && lowercaseWord.startsWith("houri") == false) { + if (lowercaseWord.startsWith("hour") == true + && lowercaseWord.startsWith("houri") == false) { return "an"; } - // Single letter word which should be preceded by 'an' if (lowercaseWord.length() == 1) { if ("aedhilmnorsx".indexOf(lowercaseWord) >= 0) { return "an"; } - + return "a"; } // Capital words which should likely be preceded by 'an' - if (word.matches("(?!FJO|[HLMNS]Y.|RY[EO]|SQU|(F[LR]?|[HL]|MN?|N|RH?|S[CHKLMNPTVW]?|X(YL)?)[AEIOU])[FHLMNRSX][A-Z]")) { + if (word.matches( + "(?!FJO|[HLMNS]Y.|RY[EO]|SQU|(F[LR]?|[HL]|MN?|N|RH?|S[CHKLMNPTVW]?|X(YL)?)[AEIOU])[FHLMNRSX][A-Z]")) { return "an"; } // Special cases where a word that begins with a vowel should be preceded by 'a' - String [] regexes = { "^e[uw]", "^onc?e\\b", "^uni([^nmd]|mo)", "^u[bcfhjkqrst][aeiou]" }; + String[] regexes = { + "^e[uw]", "^onc?e\\b", "^uni([^nmd]|mo)", "^u[bcfhjkqrst][aeiou]" + }; for (String regex : regexes) { - if (lowercaseWord.matches(regex+".*") == true) { + if (lowercaseWord.matches(regex + ".*") == true) { return "a"; } } @@ -90,7 +97,7 @@ public class EnglishUtils { if ("aedhilmnorsx".indexOf(lowercaseWord.substring(0, 1)) >= 0) { return "an"; } - + return "a"; } -- cgit v1.2.3 From e71ef0d03e87df19900db8328cda68d38d523b0b Mon Sep 17 00:00:00 2001 From: Ben Culkin Date: Mon, 13 Apr 2020 18:52:30 -0400 Subject: Cleanup some latent bugs Cleanup some latent bugs --- src/main/java/bjc/inflexion/EnglishUtils.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/main/java/bjc/inflexion/EnglishUtils.java') diff --git a/src/main/java/bjc/inflexion/EnglishUtils.java b/src/main/java/bjc/inflexion/EnglishUtils.java index 0fafe86..942a2a0 100644 --- a/src/main/java/bjc/inflexion/EnglishUtils.java +++ b/src/main/java/bjc/inflexion/EnglishUtils.java @@ -93,7 +93,7 @@ public class EnglishUtils { // Special capital words (UK, UN) if (word.matches("^U[NK][AIEO].*") == true) { return "a"; - } else if (word == word.toUpperCase()) { + } else if (word.equals(word.toUpperCase())) { if ("aedhilmnorsx".indexOf(lowercaseWord.substring(0, 1)) >= 0) { return "an"; } -- cgit v1.2.3