summaryrefslogtreecommitdiff
path: root/src/main/java/bjc/inflexion/EnglishUtils.java
diff options
context:
space:
mode:
authorBen Culkin <scorpress@gmail.com>2020-04-13 18:44:24 -0400
committerBen Culkin <scorpress@gmail.com>2020-04-13 18:44:24 -0400
commit2f6a7807f7180fb467e3d06f2af4263a45759c28 (patch)
treea2c07895dd0f2ab60e864f402e8a38ad0ca0735a /src/main/java/bjc/inflexion/EnglishUtils.java
parent5c76def2cdba199ca42ffc440506f6c17624196d (diff)
Cleanup pass
Pass to do some cleanups
Diffstat (limited to 'src/main/java/bjc/inflexion/EnglishUtils.java')
-rw-r--r--src/main/java/bjc/inflexion/EnglishUtils.java29
1 files changed, 18 insertions, 11 deletions
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";
}