summaryrefslogtreecommitdiff
path: root/src/main
diff options
context:
space:
mode:
Diffstat (limited to 'src/main')
-rw-r--r--src/main/java/bjc/inflexion/EnglishUtils.java24
-rw-r--r--src/main/java/bjc/inflexion/InflectionML.java46
-rw-r--r--src/main/java/bjc/inflexion/nouns/CategoricalNounInflection.java121
-rw-r--r--src/main/java/bjc/inflexion/nouns/CompoundNounInflection.java215
-rw-r--r--src/main/java/bjc/inflexion/nouns/DefaultNounInflection.java27
-rw-r--r--src/main/java/bjc/inflexion/nouns/InflectionAffix.java14
-rw-r--r--src/main/java/bjc/inflexion/nouns/InflectionAffixes.java26
-rw-r--r--src/main/java/bjc/inflexion/nouns/InflectionException.java12
-rw-r--r--src/main/java/bjc/inflexion/nouns/IrregularNounInflection.java132
-rw-r--r--src/main/java/bjc/inflexion/nouns/Noun.java24
-rw-r--r--src/main/java/bjc/inflexion/nouns/NounInflection.java42
-rw-r--r--src/main/java/bjc/inflexion/nouns/Nouns.java176
-rw-r--r--src/main/java/bjc/inflexion/nouns/Prepositions.java24
-rw-r--r--src/main/java/bjc/inflexion/nouns/SimpleInflectionAffix.java58
14 files changed, 476 insertions, 465 deletions
diff --git a/src/main/java/bjc/inflexion/EnglishUtils.java b/src/main/java/bjc/inflexion/EnglishUtils.java
index c782162..e3c0823 100644
--- a/src/main/java/bjc/inflexion/EnglishUtils.java
+++ b/src/main/java/bjc/inflexion/EnglishUtils.java
@@ -50,37 +50,33 @@ public class EnglishUtils {
/**
* Convert small integers to words.
- *
+ *
* @param num
* The number to convert.
- *
+ *
* @return The word for the number, if it's less than ten.
*/
- public static String smallIntToWord(int num) {
- if (num >= 0 && num <= 10) {
- return smallNums[num];
- }
+ public static String smallIntToWord(final int num) {
+ if (num >= 0 && num <= 10) return smallNums[num];
return Integer.toString(num);
}
/**
* Summarize an integer.
- *
+ *
* @param num
* The number to summarize.
- *
+ *
* @param atEnd
* Whether or not the integer is at the end of a string.
- *
+ *
* @return A string summarizing the integer.
*/
- public static String intSummarize(int num, boolean atEnd) {
- String[] nums = atEnd ? endSummaryNums : summaryNums;
+ public static String intSummarize(final int num, final boolean atEnd) {
+ final String[] nums = atEnd ? endSummaryNums : summaryNums;
- if (num >= 0 && num < 10) {
- return nums[summaryMap[num]];
- }
+ if (num >= 0 && num < 10) return nums[summaryMap[num]];
return "many";
}
diff --git a/src/main/java/bjc/inflexion/InflectionML.java b/src/main/java/bjc/inflexion/InflectionML.java
index 4ceda7a..5705cab 100644
--- a/src/main/java/bjc/inflexion/InflectionML.java
+++ b/src/main/java/bjc/inflexion/InflectionML.java
@@ -40,7 +40,7 @@ public class InflectionML {
private static Nouns nounDB;
static {
- Prepositions prepositionDB = new Prepositions();
+ final Prepositions prepositionDB = new Prepositions();
prepositionDB.loadFromStream(InflexionTester.class.getResourceAsStream("/prepositions.txt"));
nounDB = new Nouns(prepositionDB);
@@ -49,26 +49,26 @@ public class InflectionML {
/**
* Apply inflection to marked forms in the string.
- *
+ *
* @param form
* The string to inflect.
- *
+ *
* @return The inflected string.
*/
- public static String inflect(String form) {
- Matcher formMatcher = FORM_MARKER.matcher(form);
+ public static String inflect(final String form) {
+ final Matcher formMatcher = FORM_MARKER.matcher(form);
- StringBuffer formBuffer = new StringBuffer();
+ final StringBuffer formBuffer = new StringBuffer();
int curCount = 1;
boolean inflectSingular = true;
while (formMatcher.find()) {
- String command = formMatcher.group("command");
- String options = formMatcher.group("options");
- String text = formMatcher.group("text");
+ final String command = formMatcher.group("command");
+ final String options = formMatcher.group("options");
+ final String text = formMatcher.group("text");
- Set<String> optionSet = new HashSet<>();
+ final Set<String> optionSet = new HashSet<>();
for (int i = 1; i <= options.length(); i++) {
optionSet.add(options.substring(i - 1, i));
}
@@ -87,9 +87,11 @@ public class InflectionML {
}
if (curCount != 1) {
- if (curCount == 0 && optionSet.contains("s"))
+ if (curCount == 0 && optionSet.contains("s")) {
inflectSingular = true;
- else inflectSingular = false;
+ } else {
+ inflectSingular = false;
+ }
} else {
inflectSingular = true;
}
@@ -105,7 +107,9 @@ public class InflectionML {
String rep = text;
if (optionSet.contains("n")) {
- if (curCount == 0) rep = "no";
+ if (curCount == 0) {
+ rep = "no";
+ }
}
if (optionSet.contains("s")) {
@@ -120,7 +124,7 @@ public class InflectionML {
*/
}
- boolean shouldOverride = !(rep.equals("no") || rep.equals("a")
+ final boolean shouldOverride = !(rep.equals("no") || rep.equals("a")
|| rep.equals("an"));
if (optionSet.contains("w") && shouldOverride) {
@@ -132,13 +136,13 @@ public class InflectionML {
}
formMatcher.appendReplacement(formBuffer, rep);
- } catch (NumberFormatException nfex) {
+ } catch (final NumberFormatException nfex) {
throw new InflectionException("Count setter must take a number as a parameter",
nfex);
}
break;
case "N":
- Noun noun = nounDB.getNoun(text);
+ final Noun noun = nounDB.getNoun(text);
if (optionSet.contains("p") || !inflectSingular) {
if (optionSet.contains("c")) {
formMatcher.appendReplacement(formBuffer, noun.classicalPlural());
@@ -150,7 +154,7 @@ public class InflectionML {
}
break;
default:
- String msg = String.format("Unknown command '%s'", command);
+ final String msg = String.format("Unknown command '%s'", command);
throw new InflectionException(msg);
}
@@ -163,16 +167,16 @@ public class InflectionML {
/**
* Alias method to format a string, then inflect it.
- *
+ *
* @param format
* The combined format/inflection string.
- *
+ *
* @param objects
* The parameters for the format string.
- *
+ *
* @return The string, formatted & inflected.
*/
- public static String iprintf(String format, Object... objects) {
+ public static String iprintf(final String format, final Object... objects) {
return inflect(String.format(format, objects));
}
}
diff --git a/src/main/java/bjc/inflexion/nouns/CategoricalNounInflection.java b/src/main/java/bjc/inflexion/nouns/CategoricalNounInflection.java
index 136d393..1989596 100644
--- a/src/main/java/bjc/inflexion/nouns/CategoricalNounInflection.java
+++ b/src/main/java/bjc/inflexion/nouns/CategoricalNounInflection.java
@@ -18,7 +18,7 @@ package bjc.inflexion.nouns;
/**
* Implementation of {@link NounInflection} for nouns matched by a regular
* expression.
- *
+ *
* @author EVE
*
*/
@@ -26,28 +26,28 @@ public class CategoricalNounInflection implements NounInflection {
private static final String TOSTRING_FMT = "CategoricalNounInflection [singular=%s, modernPlural=%s,"
+ " classicalPlural=%s]";
- private InflectionAffix singular;
+ private final InflectionAffix singular;
- private InflectionAffix modernPlural;
- private InflectionAffix classicalPlural;
+ private final InflectionAffix modernPlural;
+ private final InflectionAffix classicalPlural;
/**
* Create a new categorical inflection.
- *
+ *
* @param singlar
* The affix for the singular form.
- *
+ *
* @param modrnPlural
* The affix for the modern plural.
- *
+ *
* @param classiclPlural
* The affix for the classical plural.
*/
- public CategoricalNounInflection(InflectionAffix singlar, InflectionAffix modrnPlural,
- InflectionAffix classiclPlural) {
- if(singlar == null)
+ public CategoricalNounInflection(final InflectionAffix singlar, final InflectionAffix modrnPlural,
+ final InflectionAffix classiclPlural) {
+ if (singlar == null)
throw new NullPointerException("Singular form must not be null");
- else if(modrnPlural == null && classiclPlural == null)
+ else if (modrnPlural == null && classiclPlural == null)
throw new NullPointerException("One of modern/classical plural forms must not be null");
singular = singlar;
@@ -56,79 +56,76 @@ public class CategoricalNounInflection implements NounInflection {
}
@Override
- public boolean matches(String noun) {
- if(singular.hasAffix(noun))
+ public boolean matches(final String noun) {
+ if (singular.hasAffix(noun))
return true;
- else if(modernPlural != null && modernPlural.hasAffix(noun))
+ else if (modernPlural != null && modernPlural.hasAffix(noun))
return true;
- else if(classicalPlural != null && classicalPlural.hasAffix(noun))
+ else if (classicalPlural != null && classicalPlural.hasAffix(noun))
return true;
- else
- return false;
+ else return false;
}
@Override
- public boolean isSingular(String noun) {
- if(singular.hasAffix(noun))
+ public boolean isSingular(final String noun) {
+ if (singular.hasAffix(noun))
return true;
- else if(matchesPlural(noun))
+ else if (matchesPlural(noun))
return false;
else {
- String msg = String.format("Noun '%s' doesn't belong to this inflection", noun, this);
+ final String msg = String.format("Noun '%s' doesn't belong to this inflection", noun, this);
throw new InflectionException(msg);
}
}
@Override
- public boolean isPlural(String noun) {
- if(singular.hasAffix(noun))
+ public boolean isPlural(final String noun) {
+ if (singular.hasAffix(noun))
return false;
- else if(matchesPlural(noun))
+ else if (matchesPlural(noun))
return true;
else {
- String msg = String.format("Noun '%s' doesn't belong to this inflection", noun, this);
+ final String msg = String.format("Noun '%s' doesn't belong to this inflection", noun, this);
throw new InflectionException(msg);
}
}
@Override
- public String singularize(String plural) {
- if(singular.hasAffix(plural))
+ public String singularize(final String plural) {
+ if (singular.hasAffix(plural))
return plural;
- else if(modernPlural != null && modernPlural.hasAffix(plural))
+ else if (modernPlural != null && modernPlural.hasAffix(plural))
return singular.affix(modernPlural.deaffix(plural));
- else if(classicalPlural != null && classicalPlural.hasAffix(plural))
+ else if (classicalPlural != null && classicalPlural.hasAffix(plural))
return singular.affix(classicalPlural.deaffix(plural));
else {
- String msg = String.format("Noun '%s' doesn't belong to this inflection", plural, this);
+ final String msg = String.format("Noun '%s' doesn't belong to this inflection", plural, this);
throw new InflectionException(msg);
}
}
@Override
- public String pluralize(String singlar) {
- if(singular.hasAffix(singlar)) {
- if(modernPlural == null) {
- return classicalPlural.affix(singular.deaffix(singlar));
- } else {
- return modernPlural.affix(singular.deaffix(singlar));
- }
- } else if(matchesPlural(singlar)) {
+ public String pluralize(final String singlar) {
+ if (singular.hasAffix(singlar)) {
+ if (modernPlural == null) return classicalPlural.affix(singular.deaffix(singlar));
+
+ return modernPlural.affix(singular.deaffix(singlar));
+ } else if (matchesPlural(singlar))
return singlar;
- } else {
- String msg = String.format("Noun '%s' doesn't belong to this inflection", singlar, this);
+ else {
+ final String msg = String.format("Noun '%s' doesn't belong to this inflection", singlar, this);
throw new InflectionException(msg);
}
}
- private boolean matchesPlural(String noun) {
- boolean hasModernPlural = modernPlural != null && modernPlural.hasAffix(noun);
+ private boolean matchesPlural(final String noun) {
+ final boolean hasModernPlural = modernPlural != null && modernPlural.hasAffix(noun);
- return hasModernPlural || (classicalPlural != null && classicalPlural.hasAffix(noun));
+ return hasModernPlural || classicalPlural != null && classicalPlural.hasAffix(noun);
}
@Override
@@ -141,37 +138,37 @@ public class CategoricalNounInflection implements NounInflection {
final int prime = 31;
int result = 1;
- result = prime * result + ((classicalPlural == null) ? 0 : classicalPlural.hashCode());
- result = prime * result + ((modernPlural == null) ? 0 : modernPlural.hashCode());
+ result = prime * result + (classicalPlural == null ? 0 : classicalPlural.hashCode());
+ result = prime * result + (modernPlural == null ? 0 : modernPlural.hashCode());
return result;
}
@Override
- public boolean equals(Object obj) {
- if(this == obj) return true;
- if(obj == null) return false;
- if(!(obj instanceof CategoricalNounInflection)) return false;
+ public boolean equals(final Object obj) {
+ if (this == obj) return true;
+ if (obj == null) return false;
+ if (!(obj instanceof CategoricalNounInflection)) return false;
- CategoricalNounInflection other = (CategoricalNounInflection) obj;
+ final CategoricalNounInflection other = (CategoricalNounInflection) obj;
- if(classicalPlural == null) {
- if(other.classicalPlural != null) return false;
- } else if(!classicalPlural.equals(other.classicalPlural)) return false;
+ if (classicalPlural == null) {
+ if (other.classicalPlural != null) return false;
+ } else if (!classicalPlural.equals(other.classicalPlural)) return false;
- if(modernPlural == null) {
- if(other.modernPlural != null) return false;
- } else if(!modernPlural.equals(other.modernPlural)) return false;
+ if (modernPlural == null) {
+ if (other.modernPlural != null) return false;
+ } else if (!modernPlural.equals(other.modernPlural)) return false;
return true;
}
@Override
- public String pluralizeModern(String singlar) {
- if(modernPlural == null) return pluralizeClassical(singlar);
+ public String pluralizeModern(final String singlar) {
+ if (modernPlural == null) return pluralizeClassical(singlar);
String actSinglar = singlar;
- if(isPlural(singlar)) {
+ if (isPlural(singlar)) {
actSinglar = singularize(singlar);
}
@@ -179,11 +176,11 @@ public class CategoricalNounInflection implements NounInflection {
}
@Override
- public String pluralizeClassical(String singlar) {
- if(classicalPlural == null) return pluralizeModern(singlar);
+ public String pluralizeClassical(final String singlar) {
+ if (classicalPlural == null) return pluralizeModern(singlar);
String actSinglar = singlar;
- if(isPlural(singlar)) {
+ if (isPlural(singlar)) {
actSinglar = singularize(singlar);
}
diff --git a/src/main/java/bjc/inflexion/nouns/CompoundNounInflection.java b/src/main/java/bjc/inflexion/nouns/CompoundNounInflection.java
index 2eb0813..da551a3 100644
--- a/src/main/java/bjc/inflexion/nouns/CompoundNounInflection.java
+++ b/src/main/java/bjc/inflexion/nouns/CompoundNounInflection.java
@@ -21,7 +21,7 @@ import java.util.regex.Pattern;
/**
* Implementation of {@link NounInflection} for words that don't inflect at the
* end.
- *
+ *
* @author EVE
*
*/
@@ -31,29 +31,29 @@ public class CompoundNounInflection implements NounInflection {
/*
* Data stores for use.
*/
- private Nouns nounDB;
- private Prepositions prepositionDB;
+ private final Nouns nunDB;
+ private final Prepositions pepositionDB;
- private Pattern compoundMatcher;
+ private final Pattern cmpoundMatcher;
- private String singularPattern;
+ private final String sigularPattern;
- private String modernPluralPattern;
- private String classicalPluralPattern;
+ private final String mdernPluralPattern;
+ private final String clasicalPluralPattern;
/*
* Whether or not this inflection takes a preposition.
*/
- private boolean hasPreposition;
+ private final boolean haPreposition;
/*
* Whether or not there is a scratch word in place.
*/
- private boolean hasScratch;
+ private final boolean hasScratch;
/**
* TODO fill in documentation.
- *
+ *
* @param nounDB
* @param prepositionDB
* @param compoundMatcher
@@ -63,133 +63,124 @@ public class CompoundNounInflection implements NounInflection {
* @param hasPreposition
* @param hasScrtch
*/
- public CompoundNounInflection(Nouns nounDB, Prepositions prepositionDB, Pattern compoundMatcher,
- String singularPattern, String modernPluralPattern, String classicalPluralPattern,
- boolean hasPreposition, boolean hasScrtch) {
- this.nounDB = nounDB;
- this.prepositionDB = prepositionDB;
- this.compoundMatcher = compoundMatcher;
- this.singularPattern = singularPattern;
- this.modernPluralPattern = modernPluralPattern;
- this.classicalPluralPattern = classicalPluralPattern;
- this.hasPreposition = hasPreposition;
+ public CompoundNounInflection(final Nouns nounDB, final Prepositions prepositionDB,
+ final Pattern compoundMatcher, final String singularPattern, final String modernPluralPattern,
+ final String classicalPluralPattern, final boolean hasPreposition, final boolean hasScrtch) {
+ nunDB = nounDB;
+ pepositionDB = prepositionDB;
+ cmpoundMatcher = compoundMatcher;
+ sigularPattern = singularPattern;
+ mdernPluralPattern = modernPluralPattern;
+ clasicalPluralPattern = classicalPluralPattern;
+ haPreposition = hasPreposition;
hasScratch = hasScrtch;
}
@Override
- public boolean matches(String noun) {
- Matcher matcher = compoundMatcher.matcher(noun);
+ public boolean matches(final String noun) {
+ final Matcher matcher = cmpoundMatcher.matcher(noun);
+
+ if (matcher.matches()) {
+ final Noun actNoun = nunDB.getNoun(matcher.group("noun"));
- if(matcher.matches()) {
- Noun actNoun = nounDB.getNoun(matcher.group("noun"));
+ if (actNoun == null) return false;
- if(actNoun == null) return false;
+ if (haPreposition) return pepositionDB.isPreposition(matcher.group("preposition"));
- if(hasPreposition) {
- return prepositionDB.isPreposition(matcher.group("preposition"));
- } else
- return true;
- } else {
- return false;
+ return true;
}
+
+ return false;
}
@Override
- public boolean isSingular(String noun) {
- Matcher matcher = compoundMatcher.matcher(noun);
- Noun actNoun = nounDB.getNoun(matcher.group("noun"));
+ public boolean isSingular(final String noun) {
+ final Matcher matcher = cmpoundMatcher.matcher(noun);
+ final Noun actNoun = nunDB.getNoun(matcher.group("noun"));
return actNoun.isSingular();
}
@Override
- public boolean isPlural(String noun) {
- Matcher matcher = compoundMatcher.matcher(noun);
- Noun actNoun = nounDB.getNoun(matcher.group("noun"));
+ public boolean isPlural(final String noun) {
+ final Matcher matcher = cmpoundMatcher.matcher(noun);
+ final Noun actNoun = nunDB.getNoun(matcher.group("noun"));
return actNoun.isPlural();
}
@Override
- public String singularize(String plural) {
- Matcher matcher = compoundMatcher.matcher(plural);
- Noun actNoun = getNoun(matcher);
+ public String singularize(final String plural) {
+ final Matcher matcher = cmpoundMatcher.matcher(plural);
+ final Noun actNoun = getNoun(matcher);
- if(hasPreposition && hasScratch) {
- return String.format(singularPattern, actNoun.singular(), matcher.group("preposition"),
+ if (haPreposition && hasScratch)
+ return String.format(sigularPattern, actNoun.singular(), matcher.group("preposition"),
matcher.group("scratch"));
- } else if(hasScratch) {
- return String.format(singularPattern, actNoun.singular(), matcher.group("scratch"));
- } else if(hasPreposition) {
- return String.format(singularPattern, actNoun.singular(), matcher.group("preposition"));
- } else {
- return String.format(singularPattern, actNoun.singular());
- }
+ else if (hasScratch)
+ return String.format(sigularPattern, actNoun.singular(), matcher.group("scratch"));
+ else if (haPreposition)
+ return String.format(sigularPattern, actNoun.singular(), matcher.group("preposition"));
+ else return String.format(sigularPattern, actNoun.singular());
}
@Override
- public String pluralize(String singular) {
- Matcher matcher = compoundMatcher.matcher(singular);
- Noun actNoun = getNoun(matcher);
+ public String pluralize(final String singular) {
+ final Matcher matcher = cmpoundMatcher.matcher(singular);
+ final Noun actNoun = getNoun(matcher);
- String patt = modernPluralPattern == null ? classicalPluralPattern : modernPluralPattern;
+ final String patt = mdernPluralPattern == null ? clasicalPluralPattern : mdernPluralPattern;
- if(hasPreposition && hasScratch) {
+ if (haPreposition && hasScratch)
return String.format(patt, actNoun.plural(), matcher.group("preposition"),
matcher.group("scratch"));
- } else if(hasScratch) {
+ else if (hasScratch)
return String.format(patt, actNoun.plural(), matcher.group("scratch"));
- } else if(hasPreposition) {
+ else if (haPreposition)
return String.format(patt, actNoun.plural(), matcher.group("preposition"));
- } else {
- return String.format(patt, actNoun.plural());
- }
+ else return String.format(patt, actNoun.plural());
}
@Override
- public String pluralizeModern(String singular) {
- if(modernPluralPattern == null) return pluralizeClassical(singular);
+ public String pluralizeModern(final String singular) {
+ if (mdernPluralPattern == null) return pluralizeClassical(singular);
- Matcher matcher = compoundMatcher.matcher(singular);
- Noun actNoun = getNoun(matcher);
+ final Matcher matcher = cmpoundMatcher.matcher(singular);
+ final Noun actNoun = getNoun(matcher);
- if(hasPreposition && hasScratch) {
- return String.format(modernPluralPattern, actNoun.modernPlural(), matcher.group("preposition"),
+ if (haPreposition && hasScratch)
+ return String.format(mdernPluralPattern, actNoun.modernPlural(), matcher.group("preposition"),
matcher.group("scratch"));
- } else if(hasScratch) {
- return String.format(modernPluralPattern, actNoun.modernPlural(), matcher.group("scratch"));
- } else if(hasPreposition) {
- return String.format(modernPluralPattern, actNoun.modernPlural(), matcher.group("preposition"));
- } else {
- return String.format(modernPluralPattern, actNoun.modernPlural());
- }
+ else if (hasScratch)
+ return String.format(mdernPluralPattern, actNoun.modernPlural(), matcher.group("scratch"));
+ else if (haPreposition)
+ return String.format(mdernPluralPattern, actNoun.modernPlural(), matcher.group("preposition"));
+ else return String.format(mdernPluralPattern, actNoun.modernPlural());
}
@Override
- public String pluralizeClassical(String singular) {
- if(classicalPluralPattern == null) return pluralizeModern(singular);
+ public String pluralizeClassical(final String singular) {
+ if (clasicalPluralPattern == null) return pluralizeModern(singular);
- Matcher matcher = compoundMatcher.matcher(singular);
- Noun actNoun = getNoun(matcher);
+ final Matcher matcher = cmpoundMatcher.matcher(singular);
+ final Noun actNoun = getNoun(matcher);
- if(hasPreposition && hasScratch) {
- return String.format(classicalPluralPattern, actNoun.classicalPlural(),
+ if (haPreposition && hasScratch)
+ return String.format(clasicalPluralPattern, actNoun.classicalPlural(),
matcher.group("preposition"), matcher.group("scratch"));
- } else if(hasScratch) {
- return String.format(classicalPluralPattern, actNoun.classicalPlural(),
+ else if (hasScratch)
+ return String.format(clasicalPluralPattern, actNoun.classicalPlural(),
matcher.group("scratch"));
- } else if(hasPreposition) {
- return String.format(classicalPluralPattern, actNoun.classicalPlural(),
+ else if (haPreposition)
+ return String.format(clasicalPluralPattern, actNoun.classicalPlural(),
matcher.group("preposition"));
- } else {
- return String.format(classicalPluralPattern, actNoun.classicalPlural());
- }
+ else return String.format(clasicalPluralPattern, actNoun.classicalPlural());
}
- private Noun getNoun(Matcher matcher) {
+ private Noun getNoun(final Matcher matcher) {
matcher.matches();
- Noun actNoun = nounDB.getNoun(matcher.group("noun"));
+ final Noun actNoun = nunDB.getNoun(matcher.group("noun"));
return actNoun;
}
@@ -198,47 +189,47 @@ public class CompoundNounInflection implements NounInflection {
final int prime = 31;
int result = 1;
- result = prime * result + ((classicalPluralPattern == null) ? 0 : classicalPluralPattern.hashCode());
- result = prime * result + ((compoundMatcher == null) ? 0 : compoundMatcher.hashCode());
- result = prime * result + (hasPreposition ? 1231 : 1237);
- result = prime * result + ((modernPluralPattern == null) ? 0 : modernPluralPattern.hashCode());
- result = prime * result + ((singularPattern == null) ? 0 : singularPattern.hashCode());
+ result = prime * result + (clasicalPluralPattern == null ? 0 : clasicalPluralPattern.hashCode());
+ result = prime * result + (cmpoundMatcher == null ? 0 : cmpoundMatcher.hashCode());
+ result = prime * result + (haPreposition ? 1231 : 1237);
+ result = prime * result + (mdernPluralPattern == null ? 0 : mdernPluralPattern.hashCode());
+ result = prime * result + (sigularPattern == null ? 0 : sigularPattern.hashCode());
return result;
}
@Override
- public boolean equals(Object obj) {
- if(this == obj) return true;
- if(obj == null) return false;
- if(!(obj instanceof CompoundNounInflection)) return false;
+ public boolean equals(final Object obj) {
+ if (this == obj) return true;
+ if (obj == null) return false;
+ if (!(obj instanceof CompoundNounInflection)) return false;
- CompoundNounInflection other = (CompoundNounInflection) obj;
+ final CompoundNounInflection other = (CompoundNounInflection) obj;
- if(singularPattern == null) {
- if(other.singularPattern != null) return false;
- } else if(!singularPattern.equals(other.singularPattern)) return false;
+ if (sigularPattern == null) {
+ if (other.sigularPattern != null) return false;
+ } else if (!sigularPattern.equals(other.sigularPattern)) return false;
- if(classicalPluralPattern == null) {
- if(other.classicalPluralPattern != null) return false;
- } else if(!classicalPluralPattern.equals(other.classicalPluralPattern)) return false;
+ if (clasicalPluralPattern == null) {
+ if (other.clasicalPluralPattern != null) return false;
+ } else if (!clasicalPluralPattern.equals(other.clasicalPluralPattern)) return false;
- if(hasPreposition != other.hasPreposition) return false;
+ if (haPreposition != other.haPreposition) return false;
- if(modernPluralPattern == null) {
- if(other.modernPluralPattern != null) return false;
- } else if(!modernPluralPattern.equals(other.modernPluralPattern)) return false;
+ if (mdernPluralPattern == null) {
+ if (other.mdernPluralPattern != null) return false;
+ } else if (!mdernPluralPattern.equals(other.mdernPluralPattern)) return false;
- if(compoundMatcher == null) {
- if(other.compoundMatcher != null) return false;
- } else if(!compoundMatcher.equals(other.compoundMatcher)) return false;
+ if (cmpoundMatcher == null) {
+ if (other.cmpoundMatcher != null) return false;
+ } else if (!cmpoundMatcher.equals(other.cmpoundMatcher)) return false;
return true;
}
@Override
public String toString() {
- return String.format(TOSTRING_FMT, compoundMatcher, singularPattern, modernPluralPattern,
- classicalPluralPattern, hasPreposition);
+ return String.format(TOSTRING_FMT, cmpoundMatcher, sigularPattern, mdernPluralPattern,
+ clasicalPluralPattern, haPreposition);
}
} \ No newline at end of file
diff --git a/src/main/java/bjc/inflexion/nouns/DefaultNounInflection.java b/src/main/java/bjc/inflexion/nouns/DefaultNounInflection.java
index 458c3f2..71adba3 100644
--- a/src/main/java/bjc/inflexion/nouns/DefaultNounInflection.java
+++ b/src/main/java/bjc/inflexion/nouns/DefaultNounInflection.java
@@ -17,52 +17,49 @@ package bjc.inflexion.nouns;
/**
* Default noun inflection for english nouns.
- *
+ *
* @author EVE
*
*/
public class DefaultNounInflection implements NounInflection {
@Override
- public boolean matches(String noun) {
+ public boolean matches(final String noun) {
return true;
}
@Override
- public boolean isSingular(String noun) {
+ public boolean isSingular(final String noun) {
return !noun.endsWith("s");
}
@Override
- public boolean isPlural(String noun) {
+ public boolean isPlural(final String noun) {
return noun.endsWith("s");
}
@Override
- public String singularize(String plural) {
- if(plural.endsWith("ses")) {
+ public String singularize(final String plural) {
+ if (plural.endsWith("ses"))
return plural.substring(0, plural.length() - 3);
- } else if(plural.endsWith("s")) {
+ else if (plural.endsWith("s"))
return plural.substring(0, plural.length() - 1);
- } else
- return plural;
+ else return plural;
}
@Override
- public String pluralize(String singular) {
- if(singular.endsWith("s")) {
- return singular + "es";
- }
+ public String pluralize(final String singular) {
+ if (singular.endsWith("s")) return singular + "es";
return singular + "s";
}
@Override
- public String pluralizeModern(String singular) {
+ public String pluralizeModern(final String singular) {
return pluralize(singular);
}
@Override
- public String pluralizeClassical(String singular) {
+ public String pluralizeClassical(final String singular) {
return pluralize(singular);
}
} \ No newline at end of file
diff --git a/src/main/java/bjc/inflexion/nouns/InflectionAffix.java b/src/main/java/bjc/inflexion/nouns/InflectionAffix.java
index d8c8cb4..54588a2 100644
--- a/src/main/java/bjc/inflexion/nouns/InflectionAffix.java
+++ b/src/main/java/bjc/inflexion/nouns/InflectionAffix.java
@@ -17,7 +17,7 @@ package bjc.inflexion.nouns;
/**
* An affix attached to a word and used for inflection.
- *
+ *
* @author EVE
*
*/
@@ -25,30 +25,30 @@ public interface InflectionAffix {
/**
* Check if a word has this affix.
- *
+ *
* @param word
* The word to check.
- *
+ *
* @return Whether or not the word has the affix.
*/
boolean hasAffix(String word);
/**
* Remove the affix from a word.
- *
+ *
* @param word
* The word to remove the affix from.
- *
+ *
* @return The word with the affix removed.
*/
String deaffix(String word);
/**
* Apply this affix to a word.
- *
+ *
* @param word
* The word to apply the affix to.
- *
+ *
* @return The word with the affix applied.
*/
String affix(String word);
diff --git a/src/main/java/bjc/inflexion/nouns/InflectionAffixes.java b/src/main/java/bjc/inflexion/nouns/InflectionAffixes.java
index 4061776..4b1d2cf 100644
--- a/src/main/java/bjc/inflexion/nouns/InflectionAffixes.java
+++ b/src/main/java/bjc/inflexion/nouns/InflectionAffixes.java
@@ -19,55 +19,55 @@ import java.util.regex.Pattern;
/**
* Utility methods for constructing inflection affixes.
- *
+ *
* @author EVE
*
*/
public class InflectionAffixes {
/*
* Template for 'complete' affix patterns.
- *
+ *
* Match the start of the word, followed by zero or more word
* characters, followed by the suffix, then the end of the string.
- *
+ *
* The word is in a capturing group named 'stem'.
*/
private static final String COMPLETE_PATT_FMT = "(?<stem>\\w*)%s$";
/*
* Template for 'incomplete' affix patterns.
- *
+ *
* Match the start of the word, followed by one or more word characters,
* followed by the suffix, then the end of the string.
- *
+ *
* The word is in a capturing group named 'stem'.
*/
private static final String INCOMPLETE_PATT_FMT = "(?<stem>\\w+)%s$";
/**
* Create an affix that's a word by itself.
- *
+ *
* @param suffix
* The suffix to use.
- *
+ *
* @return A affix that represents the suffix.
*/
- public static InflectionAffix complete(String suffix) {
- Pattern patt = Pattern.compile(String.format(COMPLETE_PATT_FMT, suffix));
+ public static InflectionAffix complete(final String suffix) {
+ final Pattern patt = Pattern.compile(String.format(COMPLETE_PATT_FMT, suffix));
return new SimpleInflectionAffix("%s" + suffix, patt);
}
/**
* Create an affix that's not a word by itself.
- *
+ *
* @param suffix
* The suffix to use.
- *
+ *
* @return An affix that represents the suffix.
*/
- public static InflectionAffix incomplete(String suffix) {
- Pattern patt = Pattern.compile(String.format(INCOMPLETE_PATT_FMT, suffix));
+ public static InflectionAffix incomplete(final String suffix) {
+ final Pattern patt = Pattern.compile(String.format(INCOMPLETE_PATT_FMT, suffix));
return new SimpleInflectionAffix("%s" + suffix, patt);
}
diff --git a/src/main/java/bjc/inflexion/nouns/InflectionException.java b/src/main/java/bjc/inflexion/nouns/InflectionException.java
index a2d92bc..59ec61b 100644
--- a/src/main/java/bjc/inflexion/nouns/InflectionException.java
+++ b/src/main/java/bjc/inflexion/nouns/InflectionException.java
@@ -17,7 +17,7 @@ package bjc.inflexion.nouns;
/**
* Exception thrown when something goes wrong with inflection.
- *
+ *
* @author EVE
*
*/
@@ -26,24 +26,24 @@ public class InflectionException extends RuntimeException {
/**
* Create a new inflection exception with the given message and cause.
- *
+ *
* @param message
* The message of the exception.
- *
+ *
* @param cause
* The cause of the exception.
*/
- public InflectionException(String message, Throwable cause) {
+ public InflectionException(final String message, final Throwable cause) {
super(message, cause);
}
/**
* Create a new inflection exception with the given message.
- *
+ *
* @param message
* The message of the exception.
*/
- public InflectionException(String message) {
+ public InflectionException(final String message) {
super(message);
}
}
diff --git a/src/main/java/bjc/inflexion/nouns/IrregularNounInflection.java b/src/main/java/bjc/inflexion/nouns/IrregularNounInflection.java
index 772c5a9..b64b341 100644
--- a/src/main/java/bjc/inflexion/nouns/IrregularNounInflection.java
+++ b/src/main/java/bjc/inflexion/nouns/IrregularNounInflection.java
@@ -17,7 +17,7 @@ package bjc.inflexion.nouns;
/**
* Implementation of {@link NounInflection} for irregular nouns.
- *
+ *
* @author EVE
*
*/
@@ -25,33 +25,33 @@ public class IrregularNounInflection implements NounInflection {
private static final String TOSTRING_FMT = "IrregularNounInflection [singular=%s, modernPlural=%s,"
+ " classicalPlural=%s, preferClassical=%s]";
- private String singular;
+ private final String singular;
- private String modernPlural;
- private String classicalPlural;
+ private final String modernPlural;
+ private final String classicalPlural;
- private boolean preferClassical;
+ private final boolean preferClassical;
/**
* Create a new irregular noun inflection.
- *
+ *
* @param singlar
* The singular form of the noun.
- *
+ *
* @param modrnPlural
* The modern plural of the noun.
- *
+ *
* @param classiclPlural
* The classical plural of the noun.
- *
+ *
* @param prefrClassical
* Whether the classical form should be preferred if it
* is available.
*/
- public IrregularNounInflection(String singlar, String modrnPlural, String classiclPlural,
- boolean prefrClassical) {
- if(singlar == null) throw new NullPointerException("Singular form must not be null");
- if(modrnPlural == null && classiclPlural == null)
+ public IrregularNounInflection(final String singlar, final String modrnPlural, final String classiclPlural,
+ final boolean prefrClassical) {
+ if (singlar == null) throw new NullPointerException("Singular form must not be null");
+ if (modrnPlural == null && classiclPlural == null)
throw new NullPointerException("One of modern/classical plural forms must not be null");
singular = singlar;
@@ -61,83 +61,83 @@ public class IrregularNounInflection implements NounInflection {
}
@Override
- public boolean matches(String noun) {
- if(noun.equalsIgnoreCase(singular))
+ public boolean matches(final String noun) {
+ if (noun.equalsIgnoreCase(singular))
return true;
- else if(noun.equalsIgnoreCase(modernPlural))
+ else if (noun.equalsIgnoreCase(modernPlural))
return true;
- else if(noun.equalsIgnoreCase(classicalPlural))
+ else if (noun.equalsIgnoreCase(classicalPlural))
return true;
- else
- return false;
+ else return false;
}
@Override
- public boolean isSingular(String noun) {
- if(noun.equalsIgnoreCase(singular))
+ public boolean isSingular(final String noun) {
+ if (noun.equalsIgnoreCase(singular))
return true;
- else if(matchesPlural(noun))
+ else if (matchesPlural(noun))
return false;
else {
- String msg = String.format("Noun '%s' doesn't belong to this inflection '%s'", noun, this);
+ final String msg = String.format("Noun '%s' doesn't belong to this inflection '%s'", noun,
+ this);
throw new InflectionException(msg);
}
}
@Override
- public boolean isPlural(String noun) {
- if(noun.equalsIgnoreCase(singular))
+ public boolean isPlural(final String noun) {
+ if (noun.equalsIgnoreCase(singular))
return false;
- else if(matchesPlural(noun))
+ else if (matchesPlural(noun))
return true;
else {
- String msg = String.format("Noun '%s' doesn't belong to this inflection '%s'", noun, this);
+ final String msg = String.format("Noun '%s' doesn't belong to this inflection '%s'", noun,
+ this);
throw new InflectionException(msg);
}
}
@Override
- public String singularize(String plural) {
- if(plural.equalsIgnoreCase(singular))
+ public String singularize(final String plural) {
+ if (plural.equalsIgnoreCase(singular))
return singular;
- else if(matchesPlural(plural))
+ else if (matchesPlural(plural))
return singular;
else {
- String msg = String.format("Noun '%s' doesn't belong to this inflection '%s'", plural, this);
+ final String msg = String.format("Noun '%s' doesn't belong to this inflection '%s'", plural,
+ this);
throw new InflectionException(msg);
}
}
@Override
- public String pluralize(String singular) {
- if(singular.equalsIgnoreCase(singular))
+ public String pluralize(final String singlar) {
+ if (singlar.equalsIgnoreCase(singlar))
return getPlural();
- else if(matchesPlural(singular))
+ else if (matchesPlural(singlar))
return getPlural();
else {
- String msg = String.format("Noun '%s' doesn't belong to this inflection '%s'", singular, this);
+ final String msg = String.format("Noun '%s' doesn't belong to this inflection '%s'", singlar,
+ this);
throw new InflectionException(msg);
}
}
private String getPlural() {
- if(preferClassical) {
- if(classicalPlural == null)
- return modernPlural;
- else
- return classicalPlural;
- } else if(modernPlural == null) {
+ if (preferClassical) {
+ if (classicalPlural == null) return modernPlural;
+
return classicalPlural;
- } else {
- return modernPlural;
- }
+ } else if (modernPlural == null)
+ return classicalPlural;
+ else return modernPlural;
}
- private boolean matchesPlural(String noun) {
+ private boolean matchesPlural(final String noun) {
return noun.equalsIgnoreCase(modernPlural) || noun.equalsIgnoreCase(classicalPlural);
}
@@ -151,46 +151,46 @@ public class IrregularNounInflection implements NounInflection {
final int prime = 31;
int result = 1;
- result = prime * result + ((classicalPlural == null) ? 0 : classicalPlural.hashCode());
- result = prime * result + ((modernPlural == null) ? 0 : modernPlural.hashCode());
- result = prime * result + ((singular == null) ? 0 : singular.hashCode());
+ result = prime * result + (classicalPlural == null ? 0 : classicalPlural.hashCode());
+ result = prime * result + (modernPlural == null ? 0 : modernPlural.hashCode());
+ result = prime * result + (singular == null ? 0 : singular.hashCode());
return result;
}
@Override
- public boolean equals(Object obj) {
- if(this == obj) return true;
- if(obj == null) return false;
- if(!(obj instanceof IrregularNounInflection)) return false;
+ public boolean equals(final Object obj) {
+ if (this == obj) return true;
+ if (obj == null) return false;
+ if (!(obj instanceof IrregularNounInflection)) return false;
- IrregularNounInflection other = (IrregularNounInflection) obj;
+ final IrregularNounInflection other = (IrregularNounInflection) obj;
- if(singular == null) {
- if(other.singular != null) return false;
- } else if(!singular.equals(other.singular)) return false;
+ if (singular == null) {
+ if (other.singular != null) return false;
+ } else if (!singular.equals(other.singular)) return false;
- if(classicalPlural == null) {
- if(other.classicalPlural != null) return false;
- } else if(!classicalPlural.equals(other.classicalPlural)) return false;
+ if (classicalPlural == null) {
+ if (other.classicalPlural != null) return false;
+ } else if (!classicalPlural.equals(other.classicalPlural)) return false;
- if(modernPlural == null) {
- if(other.modernPlural != null) return false;
- } else if(!modernPlural.equals(other.modernPlural)) return false;
+ if (modernPlural == null) {
+ if (other.modernPlural != null) return false;
+ } else if (!modernPlural.equals(other.modernPlural)) return false;
return true;
}
@Override
- public String pluralizeModern(String singular) {
- if(modernPlural == null) return pluralizeClassical(singular);
+ public String pluralizeModern(final String singlar) {
+ if (modernPlural == null) return pluralizeClassical(singlar);
return modernPlural;
}
@Override
- public String pluralizeClassical(String singular) {
- if(classicalPlural == null) return pluralizeModern(singular);
+ public String pluralizeClassical(final String singlar) {
+ if (classicalPlural == null) return pluralizeModern(singlar);
return classicalPlural;
}
diff --git a/src/main/java/bjc/inflexion/nouns/Noun.java b/src/main/java/bjc/inflexion/nouns/Noun.java
index 4f785ad..5ab5009 100644
--- a/src/main/java/bjc/inflexion/nouns/Noun.java
+++ b/src/main/java/bjc/inflexion/nouns/Noun.java
@@ -17,7 +17,7 @@ package bjc.inflexion.nouns;
/**
* A noun attached to an inflection.
- *
+ *
* @author EVE
*
*/
@@ -30,21 +30,21 @@ public class Noun {
/**
* Create a new noun from a word and inflection.
- *
+ *
* @param wrd
* The word for the noun.
- *
+ *
* @param inflction
* The inflection for the word.
*/
- public Noun(String wrd, NounInflection inflction) {
+ public Noun(final String wrd, final NounInflection inflction) {
word = wrd;
inflection = inflction;
}
/**
* Get the input noun.
- *
+ *
* @return The noun, as input.
*/
public String getWord() {
@@ -53,7 +53,7 @@ public class Noun {
/**
* Get the inflection for this noun.
- *
+ *
* @return The inflection for this noun.
*/
public NounInflection getInflection() {
@@ -62,7 +62,7 @@ public class Noun {
/**
* Check if this noun is singular.
- *
+ *
* @return Whether or not the noun is singular.
*/
public boolean isSingular() {
@@ -71,7 +71,7 @@ public class Noun {
/**
* Check if this noun is plural.
- *
+ *
* @return Whether or not this noun is plural.
*/
public boolean isPlural() {
@@ -80,7 +80,7 @@ public class Noun {
/**
* Get the singular form of this noun.
- *
+ *
* @return The singular form of this noun.
*/
public String singular() {
@@ -89,7 +89,7 @@ public class Noun {
/**
* Get the plural form of this noun.
- *
+ *
* @return The plural form of this noun.
*/
public String plural() {
@@ -103,7 +103,7 @@ public class Noun {
/**
* Get the modern plural form of this noun.
- *
+ *
* @return The modern plural form of this noun.
*/
public String modernPlural() {
@@ -112,7 +112,7 @@ public class Noun {
/**
* Get the classical plural form of this noun.
- *
+ *
* @return The classical plural form of this noun.
*/
public String classicalPlural() {
diff --git a/src/main/java/bjc/inflexion/nouns/NounInflection.java b/src/main/java/bjc/inflexion/nouns/NounInflection.java
index 9e6f4d4..142968f 100644
--- a/src/main/java/bjc/inflexion/nouns/NounInflection.java
+++ b/src/main/java/bjc/inflexion/nouns/NounInflection.java
@@ -17,29 +17,29 @@ package bjc.inflexion.nouns;
/**
* Interface for inflecting nouns.
- *
+ *
* @author EVE
*
*/
public interface NounInflection {
/**
* Check if a noun matches this inflection.
- *
+ *
* @param noun
* The noun to check on this inflection.
- *
+ *
* @return Whether or not the noun belongs to the inflection.
*/
public boolean matches(String noun);
/**
* Check if a noun for this inflection is singular or not.
- *
+ *
* @param noun
* The noun to check for singularity.
- *
+ *
* @return Whether or not the noun is singular.
- *
+ *
* @throws InflectionException
* If the noun isn't part of this inflection.
*/
@@ -47,12 +47,12 @@ public interface NounInflection {
/**
* Check if a noun for this inflection is plural or not.
- *
+ *
* @param noun
* The noun to check for plurality.
- *
+ *
* @return Whether or not the noun is plural.
- *
+ *
* @throws InflectionException
* If the noun isn't part of this inflection.
*/
@@ -60,12 +60,12 @@ public interface NounInflection {
/**
* Convert a singular noun to a plural noun.
- *
+ *
* @param plural
* The plural noun to inflect to a singular form.
- *
+ *
* @return The singular form of the noun.
- *
+ *
* @throws InflectionException
* If the noun isn't part of the inflection.
*/
@@ -73,12 +73,12 @@ public interface NounInflection {
/**
* Convert a singular noun to a plural noun.
- *
+ *
* @param singular
* The singular noun to inflect to a plural form.
- *
+ *
* @return The plural form of the noun.
- *
+ *
* @throws InflectionException
* If the noun isn't part of the inflection.
*/
@@ -86,12 +86,12 @@ public interface NounInflection {
/**
* Convert a singular noun to a modern plural noun.
- *
+ *
* @param singular
* The singular noun to inflect to a modern plural form.
- *
+ *
* @return The modern plural form of the noun.
- *
+ *
* @throws InflectionException
* If the noun isn't part of the inflection.
*/
@@ -99,13 +99,13 @@ public interface NounInflection {
/**
* Convert a singular noun to a classical plural noun.
- *
+ *
* @param singular
* The singular noun to inflect to a classical plural
* form.
- *
+ *
* @return The classical plural form of the noun.
- *
+ *
* @throws InflectionException
* If the noun isn't part of the inflection.
*/
diff --git a/src/main/java/bjc/inflexion/nouns/Nouns.java b/src/main/java/bjc/inflexion/nouns/Nouns.java
index 8bfbea2..0fbfddd 100644
--- a/src/main/java/bjc/inflexion/nouns/Nouns.java
+++ b/src/main/java/bjc/inflexion/nouns/Nouns.java
@@ -15,7 +15,8 @@
*/
package bjc.inflexion.nouns;
-import static bjc.inflexion.nouns.InflectionAffixes.*;
+import static bjc.inflexion.nouns.InflectionAffixes.complete;
+import static bjc.inflexion.nouns.InflectionAffixes.incomplete;
import java.io.InputStream;
import java.util.ArrayList;
@@ -33,21 +34,21 @@ import java.util.regex.Pattern;
public class Nouns {
private static final DefaultNounInflection DEFAULT_INFLECTION = new DefaultNounInflection();
- private Prepositions prepositionDB;
+ private final Prepositions prepositionDB;
- private Map<String, NounInflection> userIrregulars;
- private List<NounInflection> userInflections;
+ private final Map<String, NounInflection> userIrregulars;
+ private final List<NounInflection> userInflections;
- private Map<String, NounInflection> predefinedIrregulars;
- private List<NounInflection> predefinedInflections;
+ private final Map<String, NounInflection> predefinedIrregulars;
+ private final List<NounInflection> predefinedInflections;
/**
* Create a new empty noun DB.
- *
+ *
* @param prepDB
* The source for prepositions.
*/
- public Nouns(Prepositions prepDB) {
+ public Nouns(final Prepositions prepDB) {
prepositionDB = prepDB;
userIrregulars = new HashMap<>();
@@ -59,23 +60,23 @@ public class Nouns {
/**
* Retrieve a noun with its inflection from the database of inflections.
- *
+ *
* @param noun
* The noun to retrieve.
- *
+ *
* @return The noun with its inflection.
- *
+ *
* @throws InflectionException
* If the noun matched no inflection.
*/
- public Noun getNoun(String noun) {
+ public Noun getNoun(final String noun) {
if (userIrregulars.containsKey(noun)) return new Noun(noun, userIrregulars.get(noun));
- for (NounInflection inflect : userInflections) {
+ for (final NounInflection inflect : userInflections) {
if (inflect.matches(noun)) return new Noun(noun, inflect);
}
if (predefinedIrregulars.containsKey(noun)) return new Noun(noun, predefinedIrregulars.get(noun));
- for (NounInflection inflect : predefinedInflections) {
+ for (final NounInflection inflect : predefinedInflections) {
if (inflect.matches(noun)) return new Noun(noun, inflect);
}
@@ -84,20 +85,24 @@ public class Nouns {
/**
* Load the contents of the stream into this DB.
- *
+ *
* @param stream
* The stream to load from.
*/
- public void loadFromStream(InputStream stream) {
+ public void loadFromStream(final InputStream stream) {
try (Scanner scn = new Scanner(stream)) {
while (scn.hasNextLine()) {
- String ln = scn.nextLine().trim();
+ final String ln = scn.nextLine().trim();
/*
* Ignore comments and blank lines.
*/
- if (ln.startsWith("#")) continue;
- if (ln.equals("")) continue;
+ if (ln.startsWith("#")) {
+ continue;
+ }
+ if (ln.equals("")) {
+ continue;
+ }
if (ln.contains("-")) {
handleLine(ln);
@@ -109,23 +114,23 @@ public class Nouns {
}
}
- private void handleLine(String ln) {
- String[] parts = ln.split(Pattern.quote("=>"));
+ private void handleLine(final String ln) {
+ final String[] parts = ln.split(Pattern.quote("=>"));
if (parts.length != 2) {
- String msg = String.format("Improperly formatted noun defn '%s'", ln);
+ final String msg = String.format("Improperly formatted noun defn '%s'", ln);
throw new InflectionException(msg);
}
- String singular = parts[0].trim();
- String plural = parts[1].trim();
+ final String singular = parts[0].trim();
+ final String plural = parts[1].trim();
String modernPlural = "";
String classicalPlural = "";
if (plural.contains("|")) {
- String[] plurals = plural.split(Pattern.quote("|"));
+ final String[] plurals = plural.split(Pattern.quote("|"));
if (plurals.length == 1) {
modernPlural = plurals[0].trim();
@@ -134,8 +139,12 @@ public class Nouns {
classicalPlural = plurals[1].trim();
}
- if (modernPlural.equals("")) modernPlural = null;
- if (classicalPlural.equals("")) classicalPlural = null;
+ if (modernPlural.equals("")) {
+ modernPlural = null;
+ }
+ if (classicalPlural.equals("")) {
+ classicalPlural = null;
+ }
} else {
modernPlural = plural;
classicalPlural = null;
@@ -152,20 +161,21 @@ public class Nouns {
}
}
- private void handleCompoundPlural(String singular, String modernPlural, String classicalPlural) {
+ private void handleCompoundPlural(final String singular, final String modernPlural,
+ final String classicalPlural) {
String actSingular = singular;
String actModern = modernPlural == null ? "" : modernPlural;
String actClassical = classicalPlural == null ? "" : classicalPlural;
- String singularPatt = actSingular.replaceAll(Pattern.quote("(SING)"), "(?<noun>\\\\w+)");
- String modernPatt = actModern.replaceAll(Pattern.quote("(PL)"), "(?<noun>\\\\w+)");
- String classicalPatt = actClassical.replaceAll(Pattern.quote("(PL)"), "(?<noun>\\\\w+)");
+ final String singularPatt = actSingular.replaceAll(Pattern.quote("(SING)"), "(?<noun>\\\\w+)");
+ final String modernPatt = actModern.replaceAll(Pattern.quote("(PL)"), "(?<noun>\\\\w+)");
+ final String classicalPatt = actClassical.replaceAll(Pattern.quote("(PL)"), "(?<noun>\\\\w+)");
actSingular = actSingular.replaceAll(Pattern.quote("(SING)"), "%1\\$s");
actModern = actModern.replaceAll(Pattern.quote("(PL)"), "%1\\$s");
actClassical = actClassical.replaceAll(Pattern.quote("(PL)"), "%1\\$s");
- List<CompoundNounInflection> inflections = new ArrayList<>(3);
+ final List<CompoundNounInflection> inflections = new ArrayList<>(3);
if (singular.contains("(PREP)")) {
handleCompoundPreposition(actSingular, actModern, actClassical, singularPatt, modernPatt,
@@ -175,21 +185,22 @@ public class Nouns {
inflections);
}
- for (NounInflection inf : inflections) {
+ for (final NounInflection inf : inflections) {
predefinedInflections.add(inf);
}
}
- private void handleCompound(String actSinglar, String actModrn, String actClasscal, String singularPtt,
- String modernPtt, String classicalPtt, List<CompoundNounInflection> inflections) {
+ private void handleCompound(final String actSinglar, final String actModrn, final String actClasscal,
+ final String singularPtt, final String modernPtt, final String classicalPtt,
+ final List<CompoundNounInflection> inflections) {
if (singularPtt.contains("*")) {
- String singularPatt = singularPtt.replaceAll(Pattern.quote("*"), "(?<scratch>\\\\w+)");
- String modernPatt = modernPtt.replaceAll(Pattern.quote("*"), "(?<scratch>\\\\w+)");
- String classicalPatt = classicalPtt.replaceAll(Pattern.quote("*"), "(?<scratch>\\\\w+)");
+ final String singularPatt = singularPtt.replaceAll(Pattern.quote("*"), "(?<scratch>\\\\w+)");
+ final String modernPatt = modernPtt.replaceAll(Pattern.quote("*"), "(?<scratch>\\\\w+)");
+ final String classicalPatt = classicalPtt.replaceAll(Pattern.quote("*"), "(?<scratch>\\\\w+)");
- String actSingular = actSinglar.replaceAll(Pattern.quote("*"), "%2\\$s");
- String actModern = actModrn.replaceAll(Pattern.quote("*"), "%2\\$s");
- String actClassical = actClasscal.replaceAll(Pattern.quote("*"), "%2\\$s");
+ final String actSingular = actSinglar.replaceAll(Pattern.quote("*"), "%2\\$s");
+ final String actModern = actModrn.replaceAll(Pattern.quote("*"), "%2\\$s");
+ final String actClassical = actClasscal.replaceAll(Pattern.quote("*"), "%2\\$s");
handleNonpluralCompound(actSingular, actModern, actClassical, singularPatt, modernPatt,
classicalPatt, inflections, true);
@@ -199,19 +210,19 @@ public class Nouns {
}
}
- private void handleNonpluralCompound(String actSinglar, String actModrn, String actClasscal,
- String singularPatt, String modernPatt, String classicalPatt,
- List<CompoundNounInflection> inflections, boolean hasScratch) {
- String actModern = actModrn.equals("") ? null : actModrn;
- String actClassical = actClasscal.equals("") ? null : actClasscal;
+ private void handleNonpluralCompound(final String actSinglar, final String actModrn, final String actClasscal,
+ final String singularPatt, final String modernPatt, final String classicalPatt,
+ final List<CompoundNounInflection> inflections, final boolean hasScratch) {
+ final String actModern = actModrn.equals("") ? null : actModrn;
+ final String actClassical = actClasscal.equals("") ? null : actClasscal;
- CompoundNounInflection singularInflection = new CompoundNounInflection(this, prepositionDB,
+ final CompoundNounInflection singularInflection = new CompoundNounInflection(this, prepositionDB,
Pattern.compile(singularPatt), actSinglar, actModern, actClassical, false, hasScratch);
inflections.add(singularInflection);
if (!modernPatt.equals("")) {
- CompoundNounInflection modernInflection = new CompoundNounInflection(this, prepositionDB,
+ final CompoundNounInflection modernInflection = new CompoundNounInflection(this, prepositionDB,
Pattern.compile(modernPatt), actSinglar, actModern, actClassical, false,
hasScratch);
@@ -219,17 +230,17 @@ public class Nouns {
}
if (!classicalPatt.equals("")) {
- CompoundNounInflection classicalInflection = new CompoundNounInflection(this, prepositionDB,
- Pattern.compile(classicalPatt), actSinglar, actModern, actClassical, false,
- hasScratch);
+ final CompoundNounInflection classicalInflection = new CompoundNounInflection(this,
+ prepositionDB, Pattern.compile(classicalPatt), actSinglar, actModern,
+ actClassical, false, hasScratch);
inflections.add(classicalInflection);
}
}
- private void handleCompoundPreposition(String actSinglar, String actModrn, String actClasscal,
- String singularPtt, String modernPtt, String classicalPtt,
- List<CompoundNounInflection> inflections) {
+ private void handleCompoundPreposition(final String actSinglar, final String actModrn, final String actClasscal,
+ final String singularPtt, final String modernPtt, final String classicalPtt,
+ final List<CompoundNounInflection> inflections) {
String singularPatt = singularPtt.replaceAll(Pattern.quote("(PREP)"), "(?<preposition>\\\\w+)");
String modernPatt = modernPtt.replaceAll(Pattern.quote("(PREP)"), "(?<preposition>\\\\w+)");
String classicalPatt = classicalPtt.replaceAll(Pattern.quote("(PREP)"), "(?<preposition>\\\\w+)");
@@ -258,16 +269,16 @@ public class Nouns {
}
}
- private void addCompoundInflections(String actSingular, String actModern, String actClassical,
- String singularPatt, String modernPatt, String classicalPatt,
- List<CompoundNounInflection> inflections, boolean hasScratch) {
- CompoundNounInflection singularInflection = new CompoundNounInflection(this, prepositionDB,
+ private void addCompoundInflections(final String actSingular, final String actModern, final String actClassical,
+ final String singularPatt, final String modernPatt, final String classicalPatt,
+ final List<CompoundNounInflection> inflections, final boolean hasScratch) {
+ final CompoundNounInflection singularInflection = new CompoundNounInflection(this, prepositionDB,
Pattern.compile(singularPatt), actSingular, actModern, actClassical, true, hasScratch);
inflections.add(singularInflection);
if (!modernPatt.equals("")) {
- CompoundNounInflection modernInflection = new CompoundNounInflection(this, prepositionDB,
+ final CompoundNounInflection modernInflection = new CompoundNounInflection(this, prepositionDB,
Pattern.compile(modernPatt), actSingular, actModern, actClassical, true,
hasScratch);
@@ -275,55 +286,68 @@ public class Nouns {
}
if (!classicalPatt.equals("")) {
- CompoundNounInflection classicalInflection = new CompoundNounInflection(this, prepositionDB,
- Pattern.compile(classicalPatt), actSingular, actModern, actClassical, true,
- hasScratch);
+ final CompoundNounInflection classicalInflection = new CompoundNounInflection(this,
+ prepositionDB, Pattern.compile(classicalPatt), actSingular, actModern,
+ actClassical, true, hasScratch);
inflections.add(classicalInflection);
}
}
- private void handleIncompletePlural(String singular, String modernPlural, String classicalPlural) {
- InflectionAffix singularAffix = incomplete(singular.substring(1));
+ private void handleIncompletePlural(final String singular, final String modernPlural,
+ final String classicalPlural) {
+ final InflectionAffix singularAffix = incomplete(singular.substring(1));
InflectionAffix modernAffix = null;
InflectionAffix classicalAffix = null;
- if (modernPlural != null) modernAffix = incomplete(modernPlural.substring(1));
- if (classicalPlural != null) classicalAffix = incomplete(classicalPlural.substring(1));
+ if (modernPlural != null) {
+ modernAffix = incomplete(modernPlural.substring(1));
+ }
+ if (classicalPlural != null) {
+ classicalAffix = incomplete(classicalPlural.substring(1));
+ }
- CategoricalNounInflection inflection = new CategoricalNounInflection(singularAffix, modernAffix,
+ final CategoricalNounInflection inflection = new CategoricalNounInflection(singularAffix, modernAffix,
classicalAffix);
predefinedInflections.add(inflection);
}
- private void handleCompletePlural(String singular, String modernPlural, String classicalPlural) {
- InflectionAffix singularAffix = complete(singular.substring(1));
+ private void handleCompletePlural(final String singular, final String modernPlural,
+ final String classicalPlural) {
+ final InflectionAffix singularAffix = complete(singular.substring(1));
InflectionAffix modernAffix = null;
InflectionAffix classicalAffix = null;
- if (modernPlural != null) modernAffix = complete(modernPlural.substring(1));
- if (classicalPlural != null) classicalAffix = complete(classicalPlural.substring(1));
+ if (modernPlural != null) {
+ modernAffix = complete(modernPlural.substring(1));
+ }
+ if (classicalPlural != null) {
+ classicalAffix = complete(classicalPlural.substring(1));
+ }
- CategoricalNounInflection inflection = new CategoricalNounInflection(singularAffix, modernAffix,
+ final CategoricalNounInflection inflection = new CategoricalNounInflection(singularAffix, modernAffix,
classicalAffix);
predefinedInflections.add(inflection);
}
- private void handleIrregularPlural(String singular, String modernPlural, String classicalPlural) {
- IrregularNounInflection inflection = new IrregularNounInflection(singular, modernPlural,
+ private void handleIrregularPlural(final String singular, final String modernPlural,
+ final String classicalPlural) {
+ final IrregularNounInflection inflection = new IrregularNounInflection(singular, modernPlural,
classicalPlural, false);
if (!predefinedIrregulars.containsKey(singular)) {
predefinedIrregulars.put(singular, inflection);
}
- if (modernPlural != null && !predefinedIrregulars.containsKey(modernPlural))
+ if (modernPlural != null && !predefinedIrregulars.containsKey(modernPlural)) {
predefinedIrregulars.put(modernPlural, inflection);
- if (classicalPlural != null && !predefinedIrregulars.containsKey(classicalPlural))
+ }
+ if (classicalPlural != null && !predefinedIrregulars.containsKey(classicalPlural)) {
predefinedIrregulars.put(classicalPlural, inflection);
+ }
}
} \ No newline at end of file
diff --git a/src/main/java/bjc/inflexion/nouns/Prepositions.java b/src/main/java/bjc/inflexion/nouns/Prepositions.java
index 356aa1c..9f8424e 100644
--- a/src/main/java/bjc/inflexion/nouns/Prepositions.java
+++ b/src/main/java/bjc/inflexion/nouns/Prepositions.java
@@ -22,12 +22,12 @@ import java.util.Set;
/**
* List of prepositions.
- *
+ *
* @author EVE
*
*/
public class Prepositions {
- private Set<String> prepositions;
+ private final Set<String> prepositions;
/**
* Create an empty preposition DB.
@@ -38,31 +38,33 @@ public class Prepositions {
/**
* Check if a word is a preposition.
- *
+ *
* @param word
* The word as a preposition.
- *
+ *
* @return Whether or not the word is a preposition.
*/
- public boolean isPreposition(String word) {
+ public boolean isPreposition(final String word) {
return prepositions.contains(word);
}
/**
* Load the contents of the stream into this DB.
- *
+ *
* @param stream
* The stream to load from.
*/
- public void loadFromStream(InputStream stream) {
- try(Scanner scn = new Scanner(stream)) {
- while(scn.hasNextLine()) {
- String ln = scn.nextLine().trim();
+ public void loadFromStream(final InputStream stream) {
+ try (Scanner scn = new Scanner(stream)) {
+ while (scn.hasNextLine()) {
+ final String ln = scn.nextLine().trim();
/*
* Ignore comments
*/
- if(ln.startsWith("#")) continue;
+ if (ln.startsWith("#")) {
+ continue;
+ }
prepositions.add(ln);
}
diff --git a/src/main/java/bjc/inflexion/nouns/SimpleInflectionAffix.java b/src/main/java/bjc/inflexion/nouns/SimpleInflectionAffix.java
index c9db8a1..00b9689 100644
--- a/src/main/java/bjc/inflexion/nouns/SimpleInflectionAffix.java
+++ b/src/main/java/bjc/inflexion/nouns/SimpleInflectionAffix.java
@@ -20,55 +20,55 @@ import java.util.regex.Pattern;
/**
* Simple implementation of {@link InflectionAffix}
- *
+ *
* @author EVE
*
*/
public class SimpleInflectionAffix implements InflectionAffix {
private static final String TOSTRING_FMT = "SimpleInflectionAffix [affixTemplate=%s, affixMatcher=%s]";
- private String affixTemplate;
+ private final String affixTmplate;
- private Pattern affixMatcher;
+ private final Pattern affixMtcher;
/**
* Create a new inflection affix.
- *
+ *
* @param affixTemplate
* The template for applying the affix, Should be a
* printf-style format string with a single string blank.
- *
+ *
* @param affixMatcher
* The regular expression that matches the affix on
* strings. The 'stem' or word should be placed in a
* named capturing group named 'stem'.
*/
- public SimpleInflectionAffix(String affixTemplate, Pattern affixMatcher) {
- this.affixTemplate = affixTemplate;
- this.affixMatcher = affixMatcher;
+ public SimpleInflectionAffix(final String affixTemplate, final Pattern affixMatcher) {
+ affixTmplate = affixTemplate;
+ affixMtcher = affixMatcher;
}
@Override
- public boolean hasAffix(String word) {
- return affixMatcher.matcher(word).matches();
+ public boolean hasAffix(final String word) {
+ return affixMtcher.matcher(word).matches();
}
@Override
- public String deaffix(String word) {
- Matcher matcher = affixMatcher.matcher(word);
+ public String deaffix(final String word) {
+ final Matcher matcher = affixMtcher.matcher(word);
matcher.matches();
-
+
return matcher.group("stem");
}
@Override
- public String affix(String word) {
- return String.format(affixTemplate, word);
+ public String affix(final String word) {
+ return String.format(affixTmplate, word);
}
@Override
public String toString() {
- return String.format(TOSTRING_FMT, affixTemplate, affixMatcher);
+ return String.format(TOSTRING_FMT, affixTmplate, affixMtcher);
}
@Override
@@ -76,27 +76,27 @@ public class SimpleInflectionAffix implements InflectionAffix {
final int prime = 31;
int result = 1;
- result = prime * result + ((affixMatcher == null) ? 0 : affixMatcher.hashCode());
- result = prime * result + ((affixTemplate == null) ? 0 : affixTemplate.hashCode());
+ result = prime * result + (affixMtcher == null ? 0 : affixMtcher.hashCode());
+ result = prime * result + (affixTmplate == null ? 0 : affixTmplate.hashCode());
return result;
}
@Override
- public boolean equals(Object obj) {
- if(this == obj) return true;
- if(obj == null) return false;
- if(!(obj instanceof SimpleInflectionAffix)) return false;
+ public boolean equals(final Object obj) {
+ if (this == obj) return true;
+ if (obj == null) return false;
+ if (!(obj instanceof SimpleInflectionAffix)) return false;
- SimpleInflectionAffix other = (SimpleInflectionAffix) obj;
+ final SimpleInflectionAffix other = (SimpleInflectionAffix) obj;
- if(affixTemplate == null) {
- if(other.affixTemplate != null) return false;
- } else if(!affixTemplate.equals(other.affixTemplate)) return false;
+ if (affixTmplate == null) {
+ if (other.affixTmplate != null) return false;
+ } else if (!affixTmplate.equals(other.affixTmplate)) return false;
- if(affixMatcher == null) {
- if(other.affixMatcher != null) return false;
- } else if(!affixMatcher.equals(other.affixMatcher)) return false;
+ if (affixMtcher == null) {
+ if (other.affixMtcher != null) return false;
+ } else if (!affixMtcher.equals(other.affixMtcher)) return false;
return true;
}