diff options
| author | Benjamin J. Culkin <bjculkin@mix.wvu.edu> | 2020-09-10 17:12:59 -0300 |
|---|---|---|
| committer | Benjamin J. Culkin <bjculkin@mix.wvu.edu> | 2020-09-10 17:12:59 -0300 |
| commit | 229054f4839ad99c8c9fc757cce7edc0d2ca3cf1 (patch) | |
| tree | f9de568967b82c46f6d22eda9c843529b6045b5d /src/main/java/bjc/inflexion/nouns | |
| parent | cb45132debdbce593a235323e9155b5c47906558 (diff) | |
| parent | e71ef0d03e87df19900db8328cda68d38d523b0b (diff) | |
Merge branch 'master' of https://github.com/bculkin2442/Inflexion
Diffstat (limited to 'src/main/java/bjc/inflexion/nouns')
12 files changed, 405 insertions, 383 deletions
diff --git a/src/main/java/bjc/inflexion/nouns/CategoricalNounInflection.java b/src/main/java/bjc/inflexion/nouns/CategoricalNounInflection.java index 9fafcff..8f1fde9 100644 --- a/src/main/java/bjc/inflexion/nouns/CategoricalNounInflection.java +++ b/src/main/java/bjc/inflexion/nouns/CategoricalNounInflection.java @@ -24,8 +24,8 @@ package bjc.inflexion.nouns; */ public class CategoricalNounInflection implements NounInflection { /* The toString format. */ - private static final String TOSTRING_FMT = - "CategoricalNounInflection [singular=%s, modernPlural=%s, classicalPlural=%s]"; + private static final String TOSTRING_FMT + = "CategoricalNounInflection [singular=%s, modernPlural=%s, classicalPlural=%s]"; /* The affix for a singular noun. */ private final InflectionAffix singular; @@ -39,21 +39,21 @@ public class CategoricalNounInflection implements NounInflection { * Create a new categorical inflection. * * @param singlar - * The affix for the singular form. + * The affix for the singular form. * * @param modrnPlural - * The affix for the modern plural. + * The affix for the modern plural. * * @param classiclPlural - * The affix for the classical plural. + * The affix for the classical plural. */ public CategoricalNounInflection(final InflectionAffix singlar, - final InflectionAffix modrnPlural, - final InflectionAffix classiclPlural) { + final InflectionAffix modrnPlural, final InflectionAffix classiclPlural) { if (singlar == null) { throw new NullPointerException("Singular form must not be null"); } else if (modrnPlural == null && classiclPlural == null) { - throw new NullPointerException("One of modern/classical plural forms must not be null"); + throw new NullPointerException( + "One of modern/classical plural forms must not be null"); } singular = singlar; @@ -63,10 +63,14 @@ public class CategoricalNounInflection implements NounInflection { @Override public boolean matches(final String noun) { - if (singular.hasAffix(noun)) return true; - else if (modernPlural != null && modernPlural.hasAffix(noun)) return true; - else if (classicalPlural != null && classicalPlural.hasAffix(noun)) return true; - else return false; + if (singular.hasAffix(noun)) + return true; + else if (modernPlural != null && modernPlural.hasAffix(noun)) + return true; + else if (classicalPlural != null && classicalPlural.hasAffix(noun)) + return true; + else + return false; } @Override @@ -76,7 +80,8 @@ public class CategoricalNounInflection implements NounInflection { } else if (matchesPlural(noun)) { return false; } else { - final String msg = String.format("Noun '%s' doesn't belong to this inflection", noun); + final String msg + = String.format("Noun '%s' doesn't belong to this inflection", noun); throw new InflectionException(msg); } @@ -89,7 +94,8 @@ public class CategoricalNounInflection implements NounInflection { } else if (matchesPlural(noun)) { return true; } else { - final String msg = String.format("Noun '%s' doesn't belong to this inflection", noun); + final String msg + = String.format("Noun '%s' doesn't belong to this inflection", noun); throw new InflectionException(msg); } @@ -104,8 +110,8 @@ public class CategoricalNounInflection implements NounInflection { } else if (classicalPlural != null && classicalPlural.hasAffix(plural)) { return singular.affix(classicalPlural.deaffix(plural)); } else { - final 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 (%s) inflection", plural, this); throw new InflectionException(msg); } @@ -114,14 +120,15 @@ public class CategoricalNounInflection implements NounInflection { @Override public String pluralize(final String singlar) { if (singular.hasAffix(singlar)) { - if (modernPlural == null) return classicalPlural.affix(singular.deaffix(singlar)); + if (modernPlural == null) + return classicalPlural.affix(singular.deaffix(singlar)); return modernPlural.affix(singular.deaffix(singlar)); } else if (matchesPlural(singlar)) { return singlar; } else { - final String msg = String.format("Noun '%s' doesn't belong to this inflection", singlar, - this); + final String msg = String + .format("Noun '%s' doesn't belong to this (%s) inflection", singlar, this); throw new InflectionException(msg); } @@ -129,9 +136,11 @@ public class CategoricalNounInflection implements NounInflection { /* Check if a string matches a plural form. */ private boolean matchesPlural(final String noun) { - final boolean hasModernPlural = modernPlural != null && modernPlural.hasAffix(noun); + final boolean hasModernPlural + = modernPlural != null && modernPlural.hasAffix(noun); - return hasModernPlural || classicalPlural != null && classicalPlural.hasAffix(noun); + return hasModernPlural + || classicalPlural != null && classicalPlural.hasAffix(noun); } @Override @@ -144,7 +153,8 @@ public class CategoricalNounInflection implements NounInflection { final int prime = 31; int result = 1; - result = prime * result + (classicalPlural == null ? 0 : classicalPlural.hashCode()); + result = prime * result + + (classicalPlural == null ? 0 : classicalPlural.hashCode()); result = prime * result + (modernPlural == null ? 0 : modernPlural.hashCode()); return result; @@ -152,28 +162,36 @@ public class CategoricalNounInflection implements NounInflection { @Override public boolean equals(final Object obj) { - if (this == obj) return true; + if (this == obj) + return true; - if (obj == null) return false; + if (obj == null) + return false; - if (!(obj instanceof CategoricalNounInflection)) return false; + if (!(obj instanceof CategoricalNounInflection)) + return false; final CategoricalNounInflection other = (CategoricalNounInflection) obj; if (classicalPlural == null) { - if (other.classicalPlural != null) return false; - } else if (!classicalPlural.equals(other.classicalPlural)) return false; + 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 (other.modernPlural != null) + return false; + } else if (!modernPlural.equals(other.modernPlural)) + return false; return true; } @Override public String pluralizeModern(final String singlar) { - if (modernPlural == null) return pluralizeClassical(singlar); + if (modernPlural == null) + return pluralizeClassical(singlar); String actSinglar = singlar; @@ -186,7 +204,8 @@ public class CategoricalNounInflection implements NounInflection { @Override public String pluralizeClassical(final String singlar) { - if (classicalPlural == null) return pluralizeModern(singlar); + if (classicalPlural == null) + return pluralizeModern(singlar); String actSinglar = singlar; diff --git a/src/main/java/bjc/inflexion/nouns/CompoundNounInflection.java b/src/main/java/bjc/inflexion/nouns/CompoundNounInflection.java index bd36202..5d86c5a 100644 --- a/src/main/java/bjc/inflexion/nouns/CompoundNounInflection.java +++ b/src/main/java/bjc/inflexion/nouns/CompoundNounInflection.java @@ -26,11 +26,11 @@ import java.util.regex.Pattern; */ public class CompoundNounInflection implements NounInflection { /* Format for toString. */ - private static final String TOSTRING_FMT = - "CompoundNounInflection [compoundMatcher=%s, singularPattern=%s, modernPluralPattern=%s, classicalPluralPattern=%s, hasPreposition=%s]"; + private static final String TOSTRING_FMT + = "CompoundNounInflection [compoundMatcher=%s, singularPattern=%s, modernPluralPattern=%s, classicalPluralPattern=%s, hasPreposition=%s]"; /* Data stores for use. */ - private final Nouns nunDB; - private final Prepositions pepositionDB; + private final Nouns nunDB; + private final Prepositions pepositionDB; /* The pattern for compound matching. */ private final Pattern cmpoundMatcher; @@ -52,42 +52,43 @@ public class CompoundNounInflection implements NounInflection { * Create a new compound noun inflection. * * @param nounDB - * The database of nouns to lookup. + * The database of nouns to lookup. * * @param prepositionDB - * The database of prepositions to lookup. + * The database of prepositions to lookup. * * @param compoundMatcher - * The matcher for the compound noun. + * The matcher for the compound noun. * * @param singularPattern - * The pattern for a singular form. + * The pattern for a singular form. * * @param modernPluralPattern - * The pattern for a modern plural form. + * The pattern for a modern plural form. * * @param classicalPluralPattern - * The pattern for a classical plural form. - * + * The pattern for a classical plural form. + * * @param hasPreposition - * Whether or not this inflection uses a preposition. + * Whether or not this inflection uses a + * preposition. * * @param hasScrtch - * Whether or not this inflection has a scratch word. + * Whether or not this inflection has a scratch + * word. */ 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; + 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; + haPreposition = hasPreposition; + hasScratch = hasScrtch; } @Override @@ -97,9 +98,11 @@ public class CompoundNounInflection implements NounInflection { if (matcher.matches()) { final Noun actNoun = nunDB.getNoun(matcher.group("noun")); - if (actNoun == null) return false; + if (actNoun == null) + return false; - if (haPreposition) return pepositionDB.isPreposition(matcher.group("preposition")); + if (haPreposition) + return pepositionDB.isPreposition(matcher.group("preposition")); return true; } @@ -110,7 +113,7 @@ public class CompoundNounInflection implements NounInflection { @Override public boolean isSingular(final String noun) { final Matcher matcher = cmpoundMatcher.matcher(noun); - final Noun actNoun = nunDB.getNoun(matcher.group("noun")); + final Noun actNoun = nunDB.getNoun(matcher.group("noun")); return actNoun.isSingular(); } @@ -118,7 +121,7 @@ public class CompoundNounInflection implements NounInflection { @Override public boolean isPlural(final String noun) { final Matcher matcher = cmpoundMatcher.matcher(noun); - final Noun actNoun = nunDB.getNoun(matcher.group("noun")); + final Noun actNoun = nunDB.getNoun(matcher.group("noun")); return actNoun.isPlural(); } @@ -126,15 +129,17 @@ public class CompoundNounInflection implements NounInflection { @Override public String singularize(final String plural) { final Matcher matcher = cmpoundMatcher.matcher(plural); - final Noun actNoun = getNoun(matcher); + final Noun actNoun = getNoun(matcher); if (haPreposition && hasScratch) { - return String.format(sigularPattern, actNoun.singular(), matcher.group("preposition"), - matcher.group("scratch")); + return String.format(sigularPattern, actNoun.singular(), + matcher.group("preposition"), matcher.group("scratch")); } else if (hasScratch) { - return String.format(sigularPattern, actNoun.singular(), matcher.group("scratch")); + return String.format(sigularPattern, actNoun.singular(), + matcher.group("scratch")); } else if (haPreposition) { - return String.format(sigularPattern, actNoun.singular(), matcher.group("preposition")); + return String.format(sigularPattern, actNoun.singular(), + matcher.group("preposition")); } else { return String.format(sigularPattern, actNoun.singular()); } @@ -143,14 +148,14 @@ public class CompoundNounInflection implements NounInflection { @Override public String pluralize(final String singular) { final Matcher matcher = cmpoundMatcher.matcher(singular); - final Noun actNoun = getNoun(matcher); + final Noun actNoun = getNoun(matcher); - final String patt = mdernPluralPattern == null ? clasicalPluralPattern : - mdernPluralPattern; + final String patt + = mdernPluralPattern == null ? clasicalPluralPattern : mdernPluralPattern; if (haPreposition && hasScratch) { return String.format(patt, actNoun.plural(), matcher.group("preposition"), - matcher.group("scratch")); + matcher.group("scratch")); } else if (hasScratch) { return String.format(patt, actNoun.plural(), matcher.group("scratch")); } else if (haPreposition) { @@ -162,21 +167,21 @@ public class CompoundNounInflection implements NounInflection { @Override public String pluralizeModern(final String singular) { - if (mdernPluralPattern == null) return pluralizeClassical(singular); + if (mdernPluralPattern == null) + return pluralizeClassical(singular); final Matcher matcher = cmpoundMatcher.matcher(singular); - final Noun actNoun = getNoun(matcher); + final Noun actNoun = getNoun(matcher); if (haPreposition && hasScratch) { return String.format(mdernPluralPattern, actNoun.modernPlural(), - matcher.group("preposition"), - matcher.group("scratch")); + matcher.group("preposition"), matcher.group("scratch")); } else if (hasScratch) { return String.format(mdernPluralPattern, actNoun.modernPlural(), - matcher.group("scratch")); + matcher.group("scratch")); } else if (haPreposition) { return String.format(mdernPluralPattern, actNoun.modernPlural(), - matcher.group("preposition")); + matcher.group("preposition")); } else { return String.format(mdernPluralPattern, actNoun.modernPlural()); } @@ -184,20 +189,21 @@ public class CompoundNounInflection implements NounInflection { @Override public String pluralizeClassical(final String singular) { - if (clasicalPluralPattern == null) return pluralizeModern(singular); + if (clasicalPluralPattern == null) + return pluralizeModern(singular); final Matcher matcher = cmpoundMatcher.matcher(singular); - final Noun actNoun = getNoun(matcher); + final Noun actNoun = getNoun(matcher); if (haPreposition && hasScratch) { return String.format(clasicalPluralPattern, actNoun.classicalPlural(), - matcher.group("preposition"), matcher.group("scratch")); + matcher.group("preposition"), matcher.group("scratch")); } else if (hasScratch) { return String.format(clasicalPluralPattern, actNoun.classicalPlural(), - matcher.group("scratch")); + matcher.group("scratch")); } else if (haPreposition) { return String.format(clasicalPluralPattern, actNoun.classicalPlural(), - matcher.group("preposition")); + matcher.group("preposition")); } else { return String.format(clasicalPluralPattern, actNoun.classicalPlural()); } @@ -216,51 +222,65 @@ public class CompoundNounInflection implements NounInflection { final int prime = 31; int result = 1; - result = prime * result + (clasicalPluralPattern == null ? 0 : - clasicalPluralPattern.hashCode()); - result = prime * result + (cmpoundMatcher == null ? 0 : cmpoundMatcher.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()); + result = prime * result + + (mdernPluralPattern == null ? 0 : mdernPluralPattern.hashCode()); + result = prime * result + + (sigularPattern == null ? 0 : sigularPattern.hashCode()); return result; } @Override public boolean equals(final Object obj) { - if (this == obj) return true; + if (this == obj) + return true; - if (obj == null) return false; + if (obj == null) + return false; - if (!(obj instanceof CompoundNounInflection)) return false; + if (!(obj instanceof CompoundNounInflection)) + return false; final CompoundNounInflection other = (CompoundNounInflection) obj; if (sigularPattern == null) { - if (other.sigularPattern != null) return false; - } else if (!sigularPattern.equals(other.sigularPattern)) return false; + if (other.sigularPattern != null) + return false; + } else if (!sigularPattern.equals(other.sigularPattern)) + return false; if (clasicalPluralPattern == null) { - if (other.clasicalPluralPattern != null) return false; - } else if (!clasicalPluralPattern.equals(other.clasicalPluralPattern)) return false; + if (other.clasicalPluralPattern != null) + return false; + } else if (!clasicalPluralPattern.equals(other.clasicalPluralPattern)) + return false; - if (haPreposition != other.haPreposition) return false; + if (haPreposition != other.haPreposition) + return false; if (mdernPluralPattern == null) { - if (other.mdernPluralPattern != null) return false; - } else if (!mdernPluralPattern.equals(other.mdernPluralPattern)) return false; + if (other.mdernPluralPattern != null) + return false; + } else if (!mdernPluralPattern.equals(other.mdernPluralPattern)) + return false; if (cmpoundMatcher == null) { - if (other.cmpoundMatcher != null) return false; - } else if (!cmpoundMatcher.equals(other.cmpoundMatcher)) return false; + 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, cmpoundMatcher, sigularPattern, mdernPluralPattern, - clasicalPluralPattern, haPreposition); + return String.format(TOSTRING_FMT, cmpoundMatcher, sigularPattern, + mdernPluralPattern, clasicalPluralPattern, haPreposition); } } diff --git a/src/main/java/bjc/inflexion/nouns/DefaultNounInflection.java b/src/main/java/bjc/inflexion/nouns/DefaultNounInflection.java index 570aa25..13b979d 100644 --- a/src/main/java/bjc/inflexion/nouns/DefaultNounInflection.java +++ b/src/main/java/bjc/inflexion/nouns/DefaultNounInflection.java @@ -48,7 +48,8 @@ public class DefaultNounInflection implements NounInflection { @Override public String pluralize(final String singular) { - if (singular.endsWith("s")) return singular + "es"; + if (singular.endsWith("s")) + return singular + "es"; return singular + "s"; } diff --git a/src/main/java/bjc/inflexion/nouns/InflectionAffix.java b/src/main/java/bjc/inflexion/nouns/InflectionAffix.java index 65c6500..2d4d616 100644 --- a/src/main/java/bjc/inflexion/nouns/InflectionAffix.java +++ b/src/main/java/bjc/inflexion/nouns/InflectionAffix.java @@ -24,10 +24,9 @@ public interface InflectionAffix { * Check if a word has this affix. * * @param word - * The word to check. + * The word to check. * - * @return - * Whether or not the word has the affix. + * @return Whether or not the word has the affix. */ boolean hasAffix(String word); @@ -35,10 +34,9 @@ public interface InflectionAffix { * Remove the affix from a word. * * @param word - * The word to remove the affix from. + * The word to remove the affix from. * - * @return - * The word with the affix removed. + * @return The word with the affix removed. */ String deaffix(String word); @@ -46,10 +44,9 @@ public interface InflectionAffix { * Apply this affix to a word. * * @param word - * The word to apply the affix to. + * The word to apply the affix to. * - * @return - * The word with the affix applied. + * @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 645e73a..9ee35ee 100644 --- a/src/main/java/bjc/inflexion/nouns/InflectionAffixes.java +++ b/src/main/java/bjc/inflexion/nouns/InflectionAffixes.java @@ -25,8 +25,8 @@ 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. + * 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'. */ @@ -46,10 +46,9 @@ public class InflectionAffixes { * Create an affix that's a word by itself. * * @param suffix - * The suffix to use. + * The suffix to use. * - * @return - * A affix that represents the suffix. + * @return A affix that represents the suffix. */ public static InflectionAffix complete(final String suffix) { final Pattern patt = Pattern.compile(String.format(COMPLETE_PATT_FMT, suffix)); @@ -61,10 +60,9 @@ public class InflectionAffixes { * Create an affix that's not a word by itself. * * @param suffix - * The suffix to use. + * The suffix to use. * - * @return - * An affix that represents the suffix. + * @return An affix that represents the suffix. */ public static InflectionAffix incomplete(final String suffix) { final Pattern patt = Pattern.compile(String.format(INCOMPLETE_PATT_FMT, suffix)); diff --git a/src/main/java/bjc/inflexion/nouns/InflectionException.java b/src/main/java/bjc/inflexion/nouns/InflectionException.java index 74a88b6..22b2fc4 100644 --- a/src/main/java/bjc/inflexion/nouns/InflectionException.java +++ b/src/main/java/bjc/inflexion/nouns/InflectionException.java @@ -27,10 +27,10 @@ public class InflectionException extends RuntimeException { * Create a new inflection exception with the given message and cause. * * @param message - * The message of the exception. + * The message of the exception. * * @param cause - * The cause of the exception. + * The cause of the exception. */ public InflectionException(final String message, final Throwable cause) { super(message, cause); @@ -40,7 +40,7 @@ public class InflectionException extends RuntimeException { * Create a new inflection exception with the given message. * * @param message - * The message of the exception. + * The message of the exception. */ 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 b336e85..6b21733 100644 --- a/src/main/java/bjc/inflexion/nouns/IrregularNounInflection.java +++ b/src/main/java/bjc/inflexion/nouns/IrregularNounInflection.java @@ -21,9 +21,9 @@ package bjc.inflexion.nouns; */ public class IrregularNounInflection implements NounInflection { /* Format string for toString. */ - private static final String TOSTRING_FMT = - "IrregularNounInflection [singular=%s, modernPlural=%s," - + " classicalPlural=%s, preferClassical=%s]"; + private static final String TOSTRING_FMT + = "IrregularNounInflection [singular=%s, modernPlural=%s," + + " classicalPlural=%s, preferClassical=%s]"; /* The singular form. */ private final String singular; @@ -40,25 +40,26 @@ public class IrregularNounInflection implements NounInflection { * Create a new irregular noun inflection. * * @param singlar - * The singular form of the noun. + * The singular form of the noun. * * @param modrnPlural - * The modern plural of the noun. + * The modern plural of the noun. * * @param classiclPlural - * The classical plural of the noun. + * The classical plural of the noun. * * @param prefrClassical - * Whether the classical form should be preferred if it is - * available. + * Whether the classical form should be preferred if it is + * available. */ 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"); + 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"); + throw new NullPointerException( + "One of modern/classical plural forms must not be null"); singular = singlar; modernPlural = modrnPlural; @@ -86,8 +87,8 @@ public class IrregularNounInflection implements NounInflection { } else if (matchesPlural(noun)) { return false; } else { - final 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); } @@ -100,8 +101,8 @@ public class IrregularNounInflection implements NounInflection { } else if (matchesPlural(noun)) { return true; } else { - final 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); } @@ -114,9 +115,8 @@ public class IrregularNounInflection implements NounInflection { } else if (matchesPlural(plural)) { return singular; } else { - final 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); } @@ -124,14 +124,13 @@ public class IrregularNounInflection implements NounInflection { @Override public String pluralize(final String singlar) { - if (singlar.equalsIgnoreCase(singlar)) { + if (singular.equalsIgnoreCase(singlar)) { return getPlural(); } else if (matchesPlural(singlar)) { return getPlural(); } else { - final String msg = String.format("Noun '%s' doesn't belong to this inflection '%s'", - singlar, - this); + final String msg = String.format( + "Noun '%s' doesn't belong to this inflection '%s'", singlar, this); throw new InflectionException(msg); } @@ -140,7 +139,8 @@ public class IrregularNounInflection implements NounInflection { /* Get the plural form. */ private String getPlural() { if (preferClassical) { - if (classicalPlural == null) return modernPlural; + if (classicalPlural == null) + return modernPlural; return classicalPlural; } else if (modernPlural == null) { @@ -152,13 +152,14 @@ public class IrregularNounInflection implements NounInflection { /* Check if something matches the plural forms. */ private boolean matchesPlural(final String noun) { - return noun.equalsIgnoreCase(modernPlural) || noun.equalsIgnoreCase(classicalPlural); + return noun.equalsIgnoreCase(modernPlural) + || noun.equalsIgnoreCase(classicalPlural); } @Override public String toString() { return String.format(TOSTRING_FMT, singular, modernPlural, classicalPlural, - preferClassical); + preferClassical); } @Override @@ -166,7 +167,8 @@ public class IrregularNounInflection implements NounInflection { final int prime = 31; int result = 1; - result = prime * result + (classicalPlural == null ? 0 : classicalPlural.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()); @@ -175,39 +177,50 @@ public class IrregularNounInflection implements NounInflection { @Override public boolean equals(final Object obj) { - if (this == obj) return true; + if (this == obj) + return true; - if (obj == null) return false; + if (obj == null) + return false; - if (!(obj instanceof IrregularNounInflection)) return false; + if (!(obj instanceof IrregularNounInflection)) + return false; final IrregularNounInflection other = (IrregularNounInflection) obj; if (singular == null) { - if (other.singular != null) return false; - } else if (!singular.equals(other.singular)) return false; + 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 (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 (other.modernPlural != null) + return false; + } else if (!modernPlural.equals(other.modernPlural)) + return false; return true; } @Override public String pluralizeModern(final String singlar) { - if (modernPlural == null) return pluralizeClassical(singlar); + if (modernPlural == null) + return pluralizeClassical(singlar); return modernPlural; } @Override public String pluralizeClassical(final String singlar) { - if (classicalPlural == null) return pluralizeModern(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 bfb7bb9..ae7e2ae 100644 --- a/src/main/java/bjc/inflexion/nouns/Noun.java +++ b/src/main/java/bjc/inflexion/nouns/Noun.java @@ -29,10 +29,10 @@ public class Noun { * Create a new noun from a word and inflection. * * @param wrd - * The word for the noun. + * The word for the noun. * * @param inflction - * The inflection for the word. + * The inflection for the word. */ public Noun(final String wrd, final NounInflection inflction) { word = wrd; @@ -42,8 +42,7 @@ public class Noun { /** * Get the input noun. * - * @return - * The noun, as input. + * @return The noun, as input. */ public String getWord() { return word; @@ -52,8 +51,7 @@ public class Noun { /** * Get the inflection for this noun. * - * @return - * The inflection for this noun. + * @return The inflection for this noun. */ public NounInflection getInflection() { return inflection; @@ -62,8 +60,7 @@ public class Noun { /** * Check if this noun is singular. * - * @return - * Whether or not the noun is singular. + * @return Whether or not the noun is singular. */ public boolean isSingular() { return inflection.isSingular(word); @@ -72,40 +69,44 @@ public class Noun { /** * Check if this noun is plural. * - * @return - * Whether or not this noun is plural. + * @return Whether or not this noun is plural. */ public boolean isPlural() { return inflection.isPlural(word); } /** - * Check whether or not this noun is uninflected (does not change in singular/plural). + * Check whether or not this noun is uninflected (does not change in + * singular/plural). + * * @return Whether or not the noun is uninflected. */ public boolean isUninflected() { String singlar = singular(); - - if (singlar.equals(modernPlural()) || singlar.equals(classicalPlural())) return true; - + + if (singlar.equals(modernPlural()) || singlar.equals(classicalPlural())) + return true; + return false; } - + /** * Check if this noun has differing modern/classical plural forms. + * * @return Whether this noun has differing plural forms. */ public boolean isDifferingPlural() { return modernPlural().equals(classicalPlural()); } + /** * Get the singular form of this noun. * - * @return - * The singular form of this noun. + * @return The singular form of this noun. */ public String singular() { - if (isSingular()) return word; + if (isSingular()) + return word; return inflection.singularize(word); } @@ -113,11 +114,11 @@ public class Noun { /** * Get the plural form of this noun. * - * @return - * The plural form of this noun. + * @return The plural form of this noun. */ public String plural() { - if (isPlural()) return word; + if (isPlural()) + return word; return inflection.pluralize(word); } @@ -130,8 +131,7 @@ public class Noun { /** * Get the modern plural form of this noun. * - * @return - * The modern plural form of this noun. + * @return The modern plural form of this noun. */ public String modernPlural() { if (isPlural()) { @@ -148,8 +148,7 @@ public class Noun { /** * Get the classical plural form of this noun. * - * @return - * The classical plural form of this noun. + * @return The classical plural form of this noun. */ public String classicalPlural() { if (isPlural()) { diff --git a/src/main/java/bjc/inflexion/nouns/NounInflection.java b/src/main/java/bjc/inflexion/nouns/NounInflection.java index 978efdb..4341183 100644 --- a/src/main/java/bjc/inflexion/nouns/NounInflection.java +++ b/src/main/java/bjc/inflexion/nouns/NounInflection.java @@ -25,10 +25,9 @@ public interface NounInflection { * Check if a noun matches this inflection. * * @param noun - * The noun to check on this inflection. + * The noun to check on this inflection. * - * @return - * Whether or not the noun belongs to the inflection. + * @return Whether or not the noun belongs to the inflection. */ public boolean matches(String noun); @@ -36,13 +35,12 @@ public interface NounInflection { * Check if a noun for this inflection is singular or not. * * @param noun - * The noun to check for singularity. + * The noun to check for singularity. * - * @return - * Whether or not the noun is singular. + * @return Whether or not the noun is singular. * * @throws InflectionException - * If the noun isn't part of this inflection. + * If the noun isn't part of this inflection. */ public boolean isSingular(String noun); @@ -50,13 +48,12 @@ public interface NounInflection { * Check if a noun for this inflection is plural or not. * * @param noun - * The noun to check for plurality. + * The noun to check for plurality. * - * @return - * Whether or not the noun is plural. + * @return Whether or not the noun is plural. * * @throws InflectionException - * If the noun isn't part of this inflection. + * If the noun isn't part of this inflection. */ public boolean isPlural(String noun); @@ -64,13 +61,12 @@ public interface NounInflection { * Convert a singular noun to a plural noun. * * @param plural - * The plural noun to inflect to a singular form. + * The plural noun to inflect to a singular form. * - * @return - * The singular form of the noun. + * @return The singular form of the noun. * * @throws InflectionException - * If the noun isn't part of the inflection. + * If the noun isn't part of the inflection. */ public String singularize(String plural); @@ -78,13 +74,12 @@ public interface NounInflection { * Convert a singular noun to a plural noun. * * @param singular - * The singular noun to inflect to a plural form. + * The singular noun to inflect to a plural form. * - * @return - * The plural form of the noun. + * @return The plural form of the noun. * * @throws InflectionException - * If the noun isn't part of the inflection. + * If the noun isn't part of the inflection. */ public String pluralize(String singular); @@ -92,13 +87,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. + * The singular noun to inflect to a modern plural form. * - * @return - * The modern plural form of the noun. + * @return The modern plural form of the noun. * * @throws InflectionException - * If the noun isn't part of the inflection. + * If the noun isn't part of the inflection. */ public String pluralizeModern(String singular); @@ -106,13 +100,12 @@ public interface NounInflection { * Convert a singular noun to a classical plural noun. * * @param singular - * The singular noun to inflect to a classical plural form. + * The singular noun to inflect to a classical plural form. * - * @return - * The classical plural form of the noun. + * @return The classical plural form of the noun. * * @throws InflectionException - * If the noun isn't part of the inflection. + * If the noun isn't part of the inflection. */ public String pluralizeClassical(String singular); } diff --git a/src/main/java/bjc/inflexion/nouns/Nouns.java b/src/main/java/bjc/inflexion/nouns/Nouns.java index 6a36752..086501a 100644 --- a/src/main/java/bjc/inflexion/nouns/Nouns.java +++ b/src/main/java/bjc/inflexion/nouns/Nouns.java @@ -33,35 +33,35 @@ import java.util.regex.Pattern; */ public class Nouns { /* The default inflection. */ - private static final DefaultNounInflection DEFAULT_INFLECTION = new - DefaultNounInflection(); + private static final DefaultNounInflection DEFAULT_INFLECTION + = new DefaultNounInflection(); /* Database of prepositions. */ private final Prepositions prepositionDB; - - /* User defined irregular inflections. */ - private final Map<String, NounInflection> userIrregulars; + + /* User defined irregular inflections. */ + private final Map<String, NounInflection> userIrregulars; /* User defined categorical inflections. */ - private final List<NounInflection> userInflections; + private final List<NounInflection> userInflections; - /* Predefined irregular inflections. */ - private final Map<String, NounInflection> predefinedIrregulars; + /* Predefined irregular inflections. */ + private final Map<String, NounInflection> predefinedIrregulars; /* Predefined categorical inflections. */ - private final List<NounInflection> predefinedInflections; + private final List<NounInflection> predefinedInflections; /** * Create a new empty noun DB. * * @param prepDB - * The source for prepositions. + * The source for prepositions. */ public Nouns(final Prepositions prepDB) { prepositionDB = prepDB; - userIrregulars = new HashMap<>(); + userIrregulars = new HashMap<>(); userInflections = new LinkedList<>(); - predefinedIrregulars = new HashMap<>(); + predefinedIrregulars = new HashMap<>(); predefinedInflections = new LinkedList<>(); } @@ -69,19 +69,20 @@ public class Nouns { * Retrieve a noun with its inflection from the database of inflections. * * @param noun - * The noun to retrieve. + * The noun to retrieve. * - * @return - * The noun with its inflection. + * @return The noun with its inflection. * * @throws InflectionException - * If the noun matched no inflection. + * If the noun matched no inflection. */ public Noun getNoun(final String noun) { - if (userIrregulars.containsKey(noun)) return new Noun(noun, userIrregulars.get(noun)); + if (userIrregulars.containsKey(noun)) + return new Noun(noun, userIrregulars.get(noun)); for (final NounInflection inflect : userInflections) { - if (inflect.matches(noun)) return new Noun(noun, inflect); + if (inflect.matches(noun)) + return new Noun(noun, inflect); } if (predefinedIrregulars.containsKey(noun)) { @@ -89,7 +90,8 @@ public class Nouns { } for (final NounInflection inflect : predefinedInflections) { - if (inflect.matches(noun)) return new Noun(noun, inflect); + if (inflect.matches(noun)) + return new Noun(noun, inflect); } return new Noun(noun, DEFAULT_INFLECTION); @@ -99,7 +101,7 @@ public class Nouns { * Load the contents of the stream into this DB. * * @param stream - * The stream to load from. + * The stream to load from. */ public void loadFromStream(final InputStream stream) { try (Scanner scn = new Scanner(stream)) { @@ -133,9 +135,9 @@ public class Nouns { } final String singular = parts[0].trim(); - final String plural = parts[1].trim(); + final String plural = parts[1].trim(); - String modernPlural = ""; + String modernPlural = ""; String classicalPlural = ""; if (plural.contains("|")) { @@ -144,7 +146,7 @@ public class Nouns { if (plurals.length == 1) { modernPlural = plurals[0].trim(); } else { - modernPlural = plurals[0].trim(); + modernPlural = plurals[0].trim(); classicalPlural = plurals[1].trim(); } @@ -156,7 +158,7 @@ public class Nouns { classicalPlural = null; } } else { - modernPlural = plural; + modernPlural = plural; classicalPlural = null; } @@ -175,37 +177,32 @@ public class Nouns { * Handle a compound inflection. */ private void handleCompoundPlural(final String singular, final String modernPlural, - final String classicalPlural) { - String actSingular = singular; - String actModern = modernPlural == null ? "" : modernPlural; + final String classicalPlural) { + String actSingular = singular; + String actModern = modernPlural == null ? "" : modernPlural; String actClassical = classicalPlural == null ? "" : classicalPlural; - final String singularPatt = - actSingular.replaceAll(Pattern.quote("(SING)"), - "(?<noun>\\\\w+)"); + final String singularPatt + = actSingular.replaceAll(Pattern.quote("(SING)"), "(?<noun>\\\\w+)"); - final String modernPatt = - actModern.replaceAll(Pattern.quote("(PL)"), - "(?<noun>\\\\w+)"); + final String modernPatt + = actModern.replaceAll(Pattern.quote("(PL)"), "(?<noun>\\\\w+)"); - final String classicalPatt = - actClassical.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"); + actSingular = actSingular.replaceAll(Pattern.quote("(SING)"), "%1\\$s"); + actModern = actModern.replaceAll(Pattern.quote("(PL)"), "%1\\$s"); actClassical = actClassical.replaceAll(Pattern.quote("(PL)"), "%1\\$s"); final List<CompoundNounInflection> inflections = new ArrayList<>(3); if (singular.contains("(PREP)")) { - handleCompoundPreposition(actSingular, actModern, - actClassical, singularPatt, modernPatt, - classicalPatt, inflections); + handleCompoundPreposition(actSingular, actModern, actClassical, singularPatt, + modernPatt, classicalPatt, inflections); } else { - handleCompound(actSingular, actModern, actClassical, - singularPatt, modernPatt, classicalPatt, - inflections); + handleCompound(actSingular, actModern, actClassical, singularPatt, modernPatt, + classicalPatt, inflections); } for (final NounInflection inf : inflections) { @@ -216,64 +213,55 @@ public class Nouns { /* * Handle a compound inflection. */ - 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) { + 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("*")) { - final String singularPatt = - singularPtt.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 modernPatt + = modernPtt.replaceAll(Pattern.quote("*"), "(?<scratch>\\\\w+)"); - final String classicalPatt = - classicalPtt.replaceAll(Pattern.quote("*"), - "(?<scratch>\\\\w+)"); + final String classicalPatt + = classicalPtt.replaceAll(Pattern.quote("*"), "(?<scratch>\\\\w+)"); - 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"); + 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); + handleNonpluralCompound(actSingular, actModern, actClassical, singularPatt, + modernPatt, classicalPatt, inflections, true); } else { - handleNonpluralCompound(actSinglar, actModrn, - actClasscal, singularPtt, modernPtt, - classicalPtt, inflections, false); + handleNonpluralCompound(actSinglar, actModrn, actClasscal, singularPtt, + modernPtt, classicalPtt, inflections, false); } } /* Handle a non-plural compound inflection. */ - 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; + 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; final Pattern singPt = Pattern.compile(singularPatt); - final CompoundNounInflection singularInflection = new - CompoundNounInflection(this, prepositionDB, singPt, - actSinglar, actModern, actClassical, - false, hasScratch); + final CompoundNounInflection singularInflection + = new CompoundNounInflection(this, prepositionDB, singPt, actSinglar, + actModern, actClassical, false, hasScratch); inflections.add(singularInflection); if (!modernPatt.equals("")) { final Pattern modPt = Pattern.compile(modernPatt); - final CompoundNounInflection modernInflection = new - CompoundNounInflection(this, prepositionDB, - modPt, actSinglar, actModern, - actClassical, false, - hasScratch); + final CompoundNounInflection modernInflection + = new CompoundNounInflection(this, prepositionDB, modPt, actSinglar, + actModern, actClassical, false, hasScratch); inflections.add(modernInflection); } @@ -281,83 +269,74 @@ public class Nouns { if (!classicalPatt.equals("")) { final Pattern clasPt = Pattern.compile(classicalPatt); - final CompoundNounInflection classicalInflection = new - CompoundNounInflection(this, prepositionDB, - clasPt, actSinglar, actModern, - actClassical, false, - hasScratch); + final CompoundNounInflection classicalInflection + = new CompoundNounInflection(this, prepositionDB, clasPt, actSinglar, + actModern, actClassical, false, hasScratch); inflections.add(classicalInflection); } } /* - * Handle a compound plural with a preposition. */ - 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+)"); - - String actSingular = actSinglar.replaceAll(Pattern.quote("(PREP)"), "%2\\$s"); - String actModern = actModrn.replaceAll(Pattern.quote("(PREP)"), "%2\\$s"); + * Handle a compound plural with a preposition. + */ + 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+)"); + + String actSingular = actSinglar.replaceAll(Pattern.quote("(PREP)"), "%2\\$s"); + String actModern = actModrn.replaceAll(Pattern.quote("(PREP)"), "%2\\$s"); String actClassical = actClasscal.replaceAll(Pattern.quote("(PREP)"), "%2\\$s"); if (singularPatt.contains("*")) { - singularPatt = singularPatt.replaceAll(Pattern.quote("*"), "(?<scratch>\\\\w+)"); - modernPatt = modernPatt.replaceAll(Pattern.quote("*"), "(?<scratch>\\\\w+)"); - classicalPatt = classicalPatt.replaceAll(Pattern.quote("*"), "(?<scratch>\\\\w+)"); - - actSingular = actSingular.replaceAll(Pattern.quote("*"), "%3\\$s"); - actModern = actModern.replaceAll(Pattern.quote("*"), "%3\\$s"); + singularPatt + = singularPatt.replaceAll(Pattern.quote("*"), "(?<scratch>\\\\w+)"); + modernPatt = modernPatt.replaceAll(Pattern.quote("*"), "(?<scratch>\\\\w+)"); + classicalPatt + = classicalPatt.replaceAll(Pattern.quote("*"), "(?<scratch>\\\\w+)"); + + actSingular = actSingular.replaceAll(Pattern.quote("*"), "%3\\$s"); + actModern = actModern.replaceAll(Pattern.quote("*"), "%3\\$s"); actClassical = actClassical.replaceAll(Pattern.quote("*"), "%3\\$s"); - actModern = actModern.equals("") ? null : actModern; + actModern = actModern.equals("") ? null : actModern; actClassical = actClassical.equals("") ? null : actClassical; - addCompoundInflections(actSingular, actModern, - actClassical, singularPatt, modernPatt, - classicalPatt, inflections, true); + addCompoundInflections(actSingular, actModern, actClassical, singularPatt, + modernPatt, classicalPatt, inflections, true); } else { - addCompoundInflections(actSingular, actModern, - actClassical, singularPatt, modernPatt, - classicalPatt, inflections, false); + addCompoundInflections(actSingular, actModern, actClassical, singularPatt, + modernPatt, classicalPatt, inflections, false); } } /* Do adding a compound inflection. */ - 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) { + 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) { Pattern singPt = Pattern.compile(singularPatt); - final CompoundNounInflection singularInflection = new - CompoundNounInflection(this, prepositionDB, singPt, - actSingular, actModern, actClassical, - true, hasScratch); + final CompoundNounInflection singularInflection + = new CompoundNounInflection(this, prepositionDB, singPt, actSingular, + actModern, actClassical, true, hasScratch); inflections.add(singularInflection); if (!modernPatt.equals("")) { Pattern modPt = Pattern.compile(modernPatt); - final CompoundNounInflection modernInflection = new - CompoundNounInflection(this, prepositionDB, - modPt, actSingular, actModern, - actClassical, true, hasScratch); + final CompoundNounInflection modernInflection + = new CompoundNounInflection(this, prepositionDB, modPt, actSingular, + actModern, actClassical, true, hasScratch); inflections.add(modernInflection); } @@ -365,21 +344,20 @@ public class Nouns { if (!classicalPatt.equals("")) { Pattern clasPt = Pattern.compile(classicalPatt); - final CompoundNounInflection classicalInflection = new - CompoundNounInflection(this, prepositionDB, - clasPt, actSingular, actModern, - actClassical, true, hasScratch); + final CompoundNounInflection classicalInflection + = new CompoundNounInflection(this, prepositionDB, clasPt, actSingular, + actModern, actClassical, true, hasScratch); inflections.add(classicalInflection); } } /* Handle an incomplete plural. */ - private void handleIncompletePlural(final String singular, final String - modernPlural, final String classicalPlural) { + private void handleIncompletePlural(final String singular, final String modernPlural, + final String classicalPlural) { final InflectionAffix singularAffix = incomplete(singular.substring(1)); - InflectionAffix modernAffix = null; + InflectionAffix modernAffix = null; InflectionAffix classicalAffix = null; if (modernPlural != null) { @@ -390,19 +368,18 @@ public class Nouns { classicalAffix = incomplete(classicalPlural.substring(1)); } - final CategoricalNounInflection inflection = new - CategoricalNounInflection(singularAffix, modernAffix, - classicalAffix); + final CategoricalNounInflection inflection = new CategoricalNounInflection( + singularAffix, modernAffix, classicalAffix); predefinedInflections.add(inflection); } /* Handle a complete plural. */ - private void handleCompletePlural(final String singular, final String - modernPlural, final String classicalPlural) { + private void handleCompletePlural(final String singular, final String modernPlural, + final String classicalPlural) { final InflectionAffix singularAffix = complete(singular.substring(1)); - InflectionAffix modernAffix = null; + InflectionAffix modernAffix = null; InflectionAffix classicalAffix = null; if (modernPlural != null) { @@ -413,19 +390,17 @@ public class Nouns { classicalAffix = complete(classicalPlural.substring(1)); } - final CategoricalNounInflection inflection = new - CategoricalNounInflection(singularAffix, modernAffix, - classicalAffix); + final CategoricalNounInflection inflection = new CategoricalNounInflection( + singularAffix, modernAffix, classicalAffix); predefinedInflections.add(inflection); } /* Handle an irregular plural. */ - private void handleIrregularPlural(final String singular, final String - modernPlural, final String classicalPlural) { - final IrregularNounInflection inflection = new - IrregularNounInflection(singular, modernPlural, - classicalPlural, false); + 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); @@ -435,7 +410,8 @@ public class Nouns { predefinedIrregulars.put(modernPlural, inflection); } - if (classicalPlural != null && !predefinedIrregulars.containsKey(classicalPlural)) { + if (classicalPlural != null + && !predefinedIrregulars.containsKey(classicalPlural)) { predefinedIrregulars.put(classicalPlural, inflection); } } diff --git a/src/main/java/bjc/inflexion/nouns/Prepositions.java b/src/main/java/bjc/inflexion/nouns/Prepositions.java index 9564baf..96f6108 100644 --- a/src/main/java/bjc/inflexion/nouns/Prepositions.java +++ b/src/main/java/bjc/inflexion/nouns/Prepositions.java @@ -37,10 +37,9 @@ public class Prepositions { * Check if a word is a preposition. * * @param word - * The word as a preposition. + * The word as a preposition. * - * @return - * Whether or not the word is a preposition. + * @return Whether or not the word is a preposition. */ public boolean isPreposition(final String word) { return prepositions.contains(word); @@ -50,7 +49,7 @@ public class Prepositions { * Load the contents of the stream into this DB. * * @param stream - * The stream to load from. + * The stream to load from. */ public void loadFromStream(final InputStream stream) { try (Scanner scn = new Scanner(stream)) { diff --git a/src/main/java/bjc/inflexion/nouns/SimpleInflectionAffix.java b/src/main/java/bjc/inflexion/nouns/SimpleInflectionAffix.java index 93a22e6..278ad4e 100644 --- a/src/main/java/bjc/inflexion/nouns/SimpleInflectionAffix.java +++ b/src/main/java/bjc/inflexion/nouns/SimpleInflectionAffix.java @@ -24,8 +24,8 @@ import java.util.regex.Pattern; */ public class SimpleInflectionAffix implements InflectionAffix { /* Format string for toString. */ - private static final String TOSTRING_FMT = - "SimpleInflectionAffix [affixTemplate=%s, affixMatcher=%s]"; + private static final String TOSTRING_FMT + = "SimpleInflectionAffix [affixTemplate=%s, affixMatcher=%s]"; /* Affix template. */ private final String affixTmplate; @@ -36,13 +36,13 @@ public class SimpleInflectionAffix implements InflectionAffix { * 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. + * 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'. + * 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(final String affixTemplate, final Pattern affixMatcher) { affixTmplate = affixTemplate; @@ -85,21 +85,28 @@ public class SimpleInflectionAffix implements InflectionAffix { @Override public boolean equals(final Object obj) { - if (this == obj) return true; + if (this == obj) + return true; - if (obj == null) return false; + if (obj == null) + return false; - if (!(obj instanceof SimpleInflectionAffix)) return false; + if (!(obj instanceof SimpleInflectionAffix)) + return false; final SimpleInflectionAffix other = (SimpleInflectionAffix) obj; if (affixTmplate == null) { - if (other.affixTmplate != null) return false; - } else if (!affixTmplate.equals(other.affixTmplate)) return false; + if (other.affixTmplate != null) + return false; + } else if (!affixTmplate.equals(other.affixTmplate)) + return false; if (affixMtcher == null) { - if (other.affixMtcher != null) return false; - } else if (!affixMtcher.equals(other.affixMtcher)) return false; + if (other.affixMtcher != null) + return false; + } else if (!affixMtcher.equals(other.affixMtcher)) + return false; return true; } |
