summaryrefslogtreecommitdiff
path: root/src/main/java/bjc/inflexion
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/java/bjc/inflexion')
-rw-r--r--src/main/java/bjc/inflexion/CardinalState.java25
-rw-r--r--src/main/java/bjc/inflexion/EnglishUtils.java29
-rw-r--r--src/main/java/bjc/inflexion/InflectionML.java27
-rw-r--r--src/main/java/bjc/inflexion/InflectionString.java294
-rw-r--r--src/main/java/bjc/inflexion/NumberUtils.java170
-rw-r--r--src/main/java/bjc/inflexion/QueuedIterator.java59
-rw-r--r--src/main/java/bjc/inflexion/nouns/CategoricalNounInflection.java81
-rw-r--r--src/main/java/bjc/inflexion/nouns/CompoundNounInflection.java156
-rw-r--r--src/main/java/bjc/inflexion/nouns/DefaultNounInflection.java3
-rw-r--r--src/main/java/bjc/inflexion/nouns/InflectionAffix.java15
-rw-r--r--src/main/java/bjc/inflexion/nouns/InflectionAffixes.java14
-rw-r--r--src/main/java/bjc/inflexion/nouns/InflectionException.java6
-rw-r--r--src/main/java/bjc/inflexion/nouns/IrregularNounInflection.java87
-rw-r--r--src/main/java/bjc/inflexion/nouns/Noun.java49
-rw-r--r--src/main/java/bjc/inflexion/nouns/NounInflection.java47
-rw-r--r--src/main/java/bjc/inflexion/nouns/Nouns.java286
-rw-r--r--src/main/java/bjc/inflexion/nouns/Prepositions.java7
-rw-r--r--src/main/java/bjc/inflexion/nouns/SimpleInflectionAffix.java35
18 files changed, 738 insertions, 652 deletions
diff --git a/src/main/java/bjc/inflexion/CardinalState.java b/src/main/java/bjc/inflexion/CardinalState.java
index b9867f7..fe42b41 100644
--- a/src/main/java/bjc/inflexion/CardinalState.java
+++ b/src/main/java/bjc/inflexion/CardinalState.java
@@ -7,21 +7,21 @@ import java.util.function.LongPredicate;
/*
* @TODO 2/12/18 Ben Culkin :AdditionalCardinals
- *
+ *
* Add some built-in implementations for various things.
*
* By this, I mean for various unit scales, like custom and metric weights
*/
/**
* Customizations for number cardinalization.
- *
+ *
* @author EVE
*
*/
public class CardinalState {
/**
* Alias type for converting numbers to cardinals.
- *
+ *
* @author EVE
*
*/
@@ -44,31 +44,32 @@ public class CardinalState {
/**
* Create a new set of cardinalization customizations.
- *
+ *
* @param customNumbers
- * The custom numbers to use.
+ * The custom numbers to use.
* @param customScales
- * The custom scales to use.
+ * The custom scales to use.
*/
- public CardinalState(Map<Long, String> customNumbers, Map<LongPredicate, Cardinalizer> customScales) {
+ public CardinalState(Map<Long, String> customNumbers,
+ Map<LongPredicate, Cardinalizer> customScales) {
this.customNumbers = customNumbers;
this.customScales = customScales;
}
/**
* Handle a custom cardinal number
- *
+ *
* @param number
- * The number to handle
+ * The number to handle
* @return The number as a cardinal, or null if we don't handle it.
*/
public String handleCustom(long number) {
- if(customNumbers.containsKey(number)) {
+ if (customNumbers.containsKey(number)) {
return customNumbers.get(number);
}
- for(Entry<LongPredicate, Cardinalizer> ent : customScales.entrySet()) {
- if(ent.getKey().test(number)) {
+ for (Entry<LongPredicate, Cardinalizer> ent : customScales.entrySet()) {
+ if (ent.getKey().test(number)) {
return ent.getValue().apply(number, this);
}
}
diff --git a/src/main/java/bjc/inflexion/EnglishUtils.java b/src/main/java/bjc/inflexion/EnglishUtils.java
index cee804d..0fafe86 100644
--- a/src/main/java/bjc/inflexion/EnglishUtils.java
+++ b/src/main/java/bjc/inflexion/EnglishUtils.java
@@ -24,7 +24,9 @@ import java.util.regex.Pattern;
public class EnglishUtils {
/**
* Pick an indefinite article ('a' or 'an') for a phrase.
- * @param phrase The phrase to pick an article for.
+ *
+ * @param phrase
+ * The phrase to pick an article for.
* @return The article to use for the phrase.
*/
public static String pickIndefinite(String phrase) {
@@ -36,10 +38,10 @@ public class EnglishUtils {
return "a";
}
- // Getting the first word
+ // Getting the first word
pattern = Pattern.compile("(\\w+)\\s*.*");
matcher = pattern.matcher(phrase);
- if(matcher.matches() == true) {
+ if (matcher.matches() == true) {
word = matcher.group(1);
} else {
return "an";
@@ -48,37 +50,42 @@ public class EnglishUtils {
lowercaseWord = word.toLowerCase();
// Specific start of words that should be preceded by 'an'
- String [] altCases = { "euler", "heir", "honest", "hono" };
+ String[] altCases = {
+ "euler", "heir", "honest", "hono"
+ };
for (String altCase : altCases) {
if (lowercaseWord.startsWith(altCase) == true) {
return "an";
}
}
- if (lowercaseWord.startsWith("hour") == true && lowercaseWord.startsWith("houri") == false) {
+ if (lowercaseWord.startsWith("hour") == true
+ && lowercaseWord.startsWith("houri") == false) {
return "an";
}
-
// Single letter word which should be preceded by 'an'
if (lowercaseWord.length() == 1) {
if ("aedhilmnorsx".indexOf(lowercaseWord) >= 0) {
return "an";
}
-
+
return "a";
}
// Capital words which should likely be preceded by 'an'
- if (word.matches("(?!FJO|[HLMNS]Y.|RY[EO]|SQU|(F[LR]?|[HL]|MN?|N|RH?|S[CHKLMNPTVW]?|X(YL)?)[AEIOU])[FHLMNRSX][A-Z]")) {
+ if (word.matches(
+ "(?!FJO|[HLMNS]Y.|RY[EO]|SQU|(F[LR]?|[HL]|MN?|N|RH?|S[CHKLMNPTVW]?|X(YL)?)[AEIOU])[FHLMNRSX][A-Z]")) {
return "an";
}
// Special cases where a word that begins with a vowel should be preceded by 'a'
- String [] regexes = { "^e[uw]", "^onc?e\\b", "^uni([^nmd]|mo)", "^u[bcfhjkqrst][aeiou]" };
+ String[] regexes = {
+ "^e[uw]", "^onc?e\\b", "^uni([^nmd]|mo)", "^u[bcfhjkqrst][aeiou]"
+ };
for (String regex : regexes) {
- if (lowercaseWord.matches(regex+".*") == true) {
+ if (lowercaseWord.matches(regex + ".*") == true) {
return "a";
}
}
@@ -90,7 +97,7 @@ public class EnglishUtils {
if ("aedhilmnorsx".indexOf(lowercaseWord.substring(0, 1)) >= 0) {
return "an";
}
-
+
return "a";
}
diff --git a/src/main/java/bjc/inflexion/InflectionML.java b/src/main/java/bjc/inflexion/InflectionML.java
index e92e171..34b534a 100644
--- a/src/main/java/bjc/inflexion/InflectionML.java
+++ b/src/main/java/bjc/inflexion/InflectionML.java
@@ -33,9 +33,9 @@ import bjc.inflexion.nouns.Prepositions;
/*
* @TODO 10/11/17 Ben Culkin :InflectionML
- *
+ *
* Complete the implementation of this from the documentation for Lingua::EN:Inflexion.
- *
+ *
* ADDENDA 10/25/18
* Everything that doesn't require doing verbs is done.
*/
@@ -49,7 +49,8 @@ public class InflectionML {
private static final List<String> ESUB_OPT = Arrays.asList("a", "s", "w");
/* The regex that marks an inflection form. */
- private static Pattern FORM_MARKER = Pattern.compile("<(?<command>[#N])(?<options>[^:]*):(?<text>[^>]*)>");
+ private static Pattern FORM_MARKER
+ = Pattern.compile("<(?<command>[#N])(?<options>[^:]*):(?<text>[^>]*)>");
private static Pattern AN_MARKER = Pattern.compile("\\{an(\\d+)\\}");
@@ -59,7 +60,8 @@ public class InflectionML {
/* Load DBs from files. */
static {
final Prepositions prepositionDB = new Prepositions();
- try (InputStream strim = InflectionML.class.getResourceAsStream("/prepositions.txt")) {
+ try (InputStream strim
+ = InflectionML.class.getResourceAsStream("/prepositions.txt")) {
prepositionDB.loadFromStream(strim);
} catch (IOException ioex) {
ioex.printStackTrace();
@@ -77,7 +79,7 @@ public class InflectionML {
* Apply inflection to marked forms in the string.
*
* @param form
- * The string to inflect.
+ * The string to inflect.
*
* @return The inflected string.
*/
@@ -164,9 +166,8 @@ public class InflectionML {
switch (command) {
case "#":
/*
- * @NOTE These should maybe be moved into their
- * own function. This will also allow the use of
- * custom inflection forms.
+ * @NOTE These should maybe be moved into their own function. This will
+ * also allow the use of custom inflection forms.
*/
try {
if (optionSet.contains("e")) {
@@ -238,7 +239,8 @@ public class InflectionML {
rep = NumberUtils.toOrdinal(curCount, numOpts.get('o'),
false);
} else {
- rep = NumberUtils.toOrdinal(curCount, numOpts.get('o'), false);
+ rep = NumberUtils.toOrdinal(curCount, numOpts.get('o'),
+ false);
}
if (curCount < numOpts.get('o')) {
@@ -249,7 +251,8 @@ public class InflectionML {
}
if (optionSet.contains("f") && shouldOverride) {
- rep = NumberUtils.summarizeNumber(curCount, numOpts.get('f') != 0);
+ rep = NumberUtils.summarizeNumber(curCount,
+ numOpts.get('f') != 0);
}
numOpts.put('o', Integer.MAX_VALUE);
@@ -258,8 +261,8 @@ public class InflectionML {
formMatcher.appendReplacement(formBuffer, rep);
} catch (final NumberFormatException nfex) {
- throw new InflectionException("Count setter must take a number as a parameter",
- nfex);
+ throw new InflectionException(
+ "Count setter must take a number as a parameter", nfex);
}
break;
case "N":
diff --git a/src/main/java/bjc/inflexion/InflectionString.java b/src/main/java/bjc/inflexion/InflectionString.java
index 7310374..30ac60a 100644
--- a/src/main/java/bjc/inflexion/InflectionString.java
+++ b/src/main/java/bjc/inflexion/InflectionString.java
@@ -39,15 +39,15 @@ import bjc.inflexion.nouns.Prepositions;
/**
* A compiled inflection markup string
- *
+ *
* @author bjculkin
*
*/
public class InflectionString {
/**
- * Exception thrown if the string we are attempting to compile has
- * invalid syntax.
- *
+ * Exception thrown if the string we are attempting to compile has invalid
+ * syntax.
+ *
* @author bjculkin
*
*/
@@ -66,11 +66,11 @@ public class InflectionString {
/**
* Create a new format exception.
- *
+ *
* @param inp
- * The string we are attempting to compile
+ * The string we are attempting to compile
* @param parseErrors
- * The errors we encountered parsing the string.
+ * The errors we encountered parsing the string.
*/
public InflectionFormatException(String inp, List<String> parseErrors) {
this.inp = inp;
@@ -80,15 +80,16 @@ public class InflectionString {
/*
* (non-Javadoc)
- *
+ *
* @see java.lang.Throwable#toString()
*/
@Override
public String toString() {
boolean doBrief = false;
- if (doBrief) return String.format("Encountered errors attempting to parse string %s",
- parseErrors.size(), inp);
+ if (doBrief)
+ return String.format("Encountered errors attempting to parse string %s",
+ parseErrors.size(), inp);
StringBuilder sb = new StringBuilder(parseErrors.size());
sb.append("Encountered errors attempting to parse the following string:\n\t");
@@ -109,14 +110,14 @@ public class InflectionString {
/**
* Represents a directive in a inflection string.
- *
+ *
* @author bjculkin
*
*/
public static final class InflectionDirective {
/**
* The type of the directive in the inflection string.
- *
+ *
* @author bjculkin
*
*/
@@ -145,7 +146,7 @@ public class InflectionString {
/**
* Empty base class for directive options.
- *
+ *
* @author bjculkin
*
*/
@@ -155,112 +156,108 @@ public class InflectionString {
/**
* Options for a numeric directive.
- *
+ *
* @author bjculkin
*
*/
public static class NumericOptions extends Options {
/**
- * Increment the numeric value before doing anything
- * with it.
- *
+ * Increment the numeric value before doing anything with it.
+ *
* Corresponds to the 'i' option.
*/
public boolean increment;
/**
* Amount to increase the value by.
- *
+ *
* Attached to the 'i' option.
*/
public int incrementAmt = 1;
/**
* Treat zero as singular.
- *
- * Doesn't correspond directly to the 's' option, but
- * splitting between singular zero and using 'no' for
- * zero is useful.
+ *
+ * Doesn't correspond directly to the 's' option, but splitting between
+ * singular zero and using 'no' for zero is useful.
*/
public boolean singular;
/**
* Print zero as 'no'.
- *
+ *
* Corresponds to 'n' option.
*/
public boolean zeroNo;
/**
* Print 'a'/'an' for one.
- *
+ *
* Corresponds to 'a' option.
*/
public boolean article;
/**
* Don't print any text.
- *
+ *
* Corresponds to 'd' option.
*/
public boolean nonPrint;
/**
* Print the number as a cardinal.
- *
+ *
* Corresponds to 'w' option.
*/
public boolean cardinal;
/**
- * Threshold for when to stop printing the number as a
- * cardinal.
- *
+ * Threshold for when to stop printing the number as a cardinal.
+ *
* Attached to the 'w' and 'o' options.
*/
public int cardinalThresh = 11;
/**
* Print the number as an ordinal.
- *
+ *
* Corresponds to the 'o' option.
*/
public boolean ordinal;
/**
- * Threshold for when to stop printing the number as an
- * ordinal.
- *
- * If the current count is greater than
- * 'cardinalThresh', ordinals like 1st and 2nd will be
- * printed instead of first and second.
- *
+ * Threshold for when to stop printing the number as an ordinal.
+ *
+ * If the current count is greater than 'cardinalThresh', ordinals like 1st
+ * and 2nd will be printed instead of first and second.
+ *
* Attached to the 'o' option.
*/
public int ordinalThresh = Integer.MAX_VALUE;
/**
* Summarize a number.
- *
+ *
* Corresponds to the 'f' option.
*/
public boolean summarize;
/**
- * Mark the summarization as occurring at the end of the
- * string, regardless of its current position.
+ * Mark the summarization as occurring at the end of the string, regardless of
+ * its current position.
*/
public boolean atEnd = false;
/**
* Create a new set of numeric options from a string.
- *
+ *
* @param options
- * The string to create options from.
+ * The string to create options from.
* @param curPos
- * The current position into the string.
+ * The current position into the string.
* @param parseErrors
- * The current list of parsing errors.
+ * The current list of parsing errors.
*/
public NumericOptions(String options, int curPos, List<String> parseErrors) {
- if (options.equals("")) return;
+ if (options.equals(""))
+ return;
char prevOption = ' ';
StringBuilder currNum = new StringBuilder();
@@ -342,8 +339,8 @@ public class InflectionString {
public NumericOptions() {
}
- private void parseNumericParam(int curPos, List<String> parseErrors, char prevOption,
- StringBuilder currNum, int i) {
+ private void parseNumericParam(int curPos, List<String> parseErrors,
+ char prevOption, StringBuilder currNum, int i) {
int nVal = 0;
try {
nVal = Integer.parseInt(currNum.toString());
@@ -388,7 +385,7 @@ public class InflectionString {
/**
* Options for a noun directive.
- *
+ *
* @author bjculkin
*
*/
@@ -410,16 +407,17 @@ public class InflectionString {
/**
* Create a new set of noun options from a string.
- *
+ *
* @param options
- * The string to create options from.
+ * The string to create options from.
* @param curPos
- * The current position into the string.
+ * The current position into the string.
* @param parseErrors
- * The current list of parsing errors.
+ * The current list of parsing errors.
*/
public NounOptions(String options, int curPos, List<String> parseErrors) {
- if (options.equals("")) return;
+ if (options.equals(""))
+ return;
boolean doingCaseFolding = false;
@@ -463,8 +461,10 @@ public class InflectionString {
}
// Emit error message
- private static String error(String dir, int curPos, int i, String msg, Object... props) {
- return String.format("%s (at position %d in %s directive starting at position %d)",
+ private static String error(String dir, int curPos, int i, String msg,
+ Object... props) {
+ return String.format(
+ "%s (at position %d in %s directive starting at position %d)",
String.format(msg, props), curPos + i, dir, curPos);
}
@@ -475,22 +475,20 @@ public class InflectionString {
/**
* The string value of the directive.
- *
- * Currently, set for literals and variable references, as well
- * as nouns.
+ *
+ * Currently, set for literals and variable references, as well as nouns.
*/
public String litString;
/**
* The integer value of the directive.
- *
+ *
* Currently set for numeric values.
*/
public int numNumber;
/**
- * Is this directives body referencing a variable instead of a
- * literal?
+ * Is this directives body referencing a variable instead of a literal?
*/
public boolean isVRef = false;
@@ -506,9 +504,9 @@ public class InflectionString {
/**
* Create a new inflection directive.
- *
+ *
* @param type
- * The type of the directive.
+ * The type of the directive.
*/
public InflectionDirective(DirectiveType type) {
this.type = type;
@@ -522,11 +520,11 @@ public class InflectionString {
/**
* Create a new inflection directive.
- *
+ *
* @param type
- * The type of the directive.
+ * The type of the directive.
* @param strang
- * The string value for the directive.
+ * The string value for the directive.
*/
public InflectionDirective(DirectiveType type, String strang) {
this.type = type;
@@ -552,18 +550,19 @@ public class InflectionString {
break;
default:
throw new IllegalArgumentException(
- "Unhandled or wrong arguments (1 string) for directive type " + type);
+ "Unhandled or wrong arguments (1 string) for directive type "
+ + type);
}
}
/**
* Create a new inflection directive.
- *
+ *
* @param type
- * The type of the directive.
+ * The type of the directive.
* @param num
- * The number value for the directive.
+ * The number value for the directive.
*/
public InflectionDirective(DirectiveType type, int num) {
this.type = type;
@@ -575,20 +574,22 @@ public class InflectionString {
break;
default:
throw new IllegalArgumentException(
- "Unhandled or wrong arguments (1 number) for directive type " + type);
+ "Unhandled or wrong arguments (1 number) for directive type "
+ + type);
}
}
/**
* Create a new inflection directive.
- *
+ *
* @param type
* The type of the directive.
* @param listDir
* The directive list value for the directive.
*/
- public InflectionDirective(DirectiveType type, List<InflectionDirective> listDir) {
+ public InflectionDirective(DirectiveType type,
+ List<InflectionDirective> listDir) {
this.type = type;
switch (type) {
@@ -605,9 +606,9 @@ public class InflectionString {
/**
* Create a new literal directive.
- *
+ *
* @param strang
- * The literal string the directive represents.
+ * The literal string the directive represents.
* @return A literal directive for the given string.
*/
public static InflectionDirective literal(String strang) {
@@ -616,10 +617,9 @@ public class InflectionString {
/**
* Create a new variable directive.
- *
+ *
* @param strang
- * The name of the variable to interpolate into
- * the string.
+ * The name of the variable to interpolate into the string.
* @return A directive that says to interpolate the given value.
*/
public static InflectionDirective variable(String strang) {
@@ -628,11 +628,10 @@ public class InflectionString {
/**
* Create a new numeric directive.
- *
+ *
* @param num
- * The value of the directive,
- * @return A directive that sets the current number to the
- * specific value.
+ * The value of the directive,
+ * @return A directive that sets the current number to the specific value.
*/
public static InflectionDirective numeric(int num) {
return new InflectionDirective(DirectiveType.NUMERIC, num);
@@ -640,12 +639,10 @@ public class InflectionString {
/**
* Create a new numeric directive.
- *
+ *
* @param strang
- * The name of a variable that holds the value of
- * the directive,
- * @return A directive that sets the current number to the
- * specific value.
+ * The name of a variable that holds the value of the directive,
+ * @return A directive that sets the current number to the specific value.
*/
public static InflectionDirective numeric(String strang) {
return new InflectionDirective(DirectiveType.NUMERIC, strang);
@@ -653,10 +650,9 @@ public class InflectionString {
/**
* Create a new noun directive.
- *
+ *
* @param strang
- * The noun, or the name of the variable for the
- * noun.
+ * The noun, or the name of the variable for the noun.
* @return A directive that inflects the specified noun.
*/
public static InflectionDirective noun(String strang) {
@@ -665,9 +661,9 @@ public class InflectionString {
/**
* Create a sequenced set of directives.
- *
+ *
* @param list
- * The directives to sequence.
+ * The directives to sequence.
* @return A sequence directive.
*/
public static InflectionDirective seq(List<InflectionDirective> list) {
@@ -676,9 +672,9 @@ public class InflectionString {
/**
* Create a sequenced set of directives.
- *
+ *
* @param arr
- * The directives to sequence.
+ * The directives to sequence.
* @return A sequence directive.
*/
public static InflectionDirective seq(InflectionDirective... arr) {
@@ -687,14 +683,15 @@ public class InflectionString {
/**
* Set the numeric options for this directive.
- *
+ *
* @param numOpts
* The numeric options of the directive.
* @return The directive.
*/
public InflectionDirective options(NumericOptions numOpts) {
- if (type != DirectiveType.NUMERIC) throw new IllegalArgumentException(
- "Directive type " + type + " does not take numeric options");
+ if (type != DirectiveType.NUMERIC)
+ throw new IllegalArgumentException(
+ "Directive type " + type + " does not take numeric options");
this.opts = numOpts;
return this;
@@ -702,14 +699,15 @@ public class InflectionString {
/**
* Set the noun options for this directive.
- *
+ *
* @param nounOpts
- * The noun options of the directive.
+ * The noun options of the directive.
* @return The directive.
*/
public InflectionDirective options(NounOptions nounOpts) {
- if (type != DirectiveType.NOUN) throw new IllegalArgumentException(
- "Directive type " + type + " does not take noun options");
+ if (type != DirectiveType.NOUN)
+ throw new IllegalArgumentException(
+ "Directive type " + type + " does not take noun options");
this.opts = nounOpts;
return this;
@@ -718,6 +716,7 @@ public class InflectionString {
/**
* Performs the parsing of directives from a string.
+ *
* @author bjculkin
*/
public class DirectiveIterator implements Iterator<String> {
@@ -728,7 +727,7 @@ public class InflectionString {
* Create a new directive iterator over a string.
*
* @param strang
- * The string to parse directives from.
+ * The string to parse directives from.
*/
public DirectiveIterator(String strang) {
this.strang = strang;
@@ -741,10 +740,11 @@ public class InflectionString {
@Override
public String next() {
- if (!hasNext()) return null;
+ if (!hasNext())
+ return null;
// Directive nesting level
- int level = 0;
+ int level = 0;
int prevPos = pos;
char prevChar = ' ';
@@ -752,7 +752,8 @@ public class InflectionString {
for (; pos < strang.length(); pos++) {
// Backslash escapes a character
- if (prevChar == '\\') continue;
+ if (prevChar == '\\')
+ continue;
char c = strang.charAt(pos);
switch (c) {
@@ -767,8 +768,12 @@ public class InflectionString {
break;
case '>':
// :ErrorHandling 11/19/18
- if (level == 0) throw new IllegalArgumentException(
- "Attempted to close inflection directive without one open at position " + prevPos + " in string '" + strang + "', current token is '" + strang.substring(prevPos, pos) + "'");
+ if (level == 0)
+ throw new IllegalArgumentException(
+ "Attempted to close inflection directive without one open at position "
+ + prevPos + " in string '" + strang
+ + "', current token is '"
+ + strang.substring(prevPos, pos) + "'");
// Denest a level
level = Math.max(0, level - 1);
// Stop parsing at the end of a
@@ -783,16 +788,19 @@ public class InflectionString {
break;
case '$':
// Ignore v-refs when inside a directive
- if (level > 0) break;
+ if (level > 0)
+ break;
// Stop parsing if this isn't at the
// start of a string
- if (prevPos != pos) return strang.substring(prevPos, pos);
+ if (prevPos != pos)
+ return strang.substring(prevPos, pos);
parsingVar = true;
break;
case ' ':
// If we're parsing a v-ref, this
// finishes it.
- if (parsingVar) return strang.substring(prevPos, pos);
+ if (parsingVar)
+ return strang.substring(prevPos, pos);
break;
default:
// Do nothing for ordinary characters
@@ -800,14 +808,17 @@ public class InflectionString {
}
}
- /* @TODO 11/19/18 Ben Culkin :ErrorHandling
- * Do something better than this exception, if possible.
+ /*
+ * @TODO 11/19/18 Ben Culkin :ErrorHandling Do something better than this
+ * exception, if possible.
*
- * In the rest of the inflection string code, we use the
- * whole 'list of errors/warnings' thing. Is there a way
- * to do something similiar here?
+ * In the rest of the inflection string code, we use the whole 'list of
+ * errors/warnings' thing. Is there a way to do something similiar here?
*/
- if (level > 0) throw new IllegalArgumentException("Unclosed inflection directive, starting at position " + prevPos + " in string '" + strang + "'");
+ if (level > 0)
+ throw new IllegalArgumentException(
+ "Unclosed inflection directive, starting at position " + prevPos
+ + " in string '" + strang + "'");
return strang.substring(prevPos, pos);
}
@@ -827,7 +838,8 @@ public class InflectionString {
/* Load DBs from files. */
static {
final Prepositions prepositionDB = new Prepositions();
- try (InputStream strim = InflectionML.class.getResourceAsStream("/prepositions.txt")) {
+ try (InputStream strim
+ = InflectionML.class.getResourceAsStream("/prepositions.txt")) {
prepositionDB.loadFromStream(strim);
} catch (IOException ioex) {
ioex.printStackTrace();
@@ -860,9 +872,9 @@ public class InflectionString {
/**
* Create a new compiled inflection string.
- *
+ *
* @param inp
- * The string to compile.
+ * The string to compile.
*/
public InflectionString(String inp) {
this();
@@ -886,15 +898,17 @@ public class InflectionString {
String dirBody = strang.substring(2, strang.length() - 1);
int idx = dirBody.indexOf(":");
- if (idx == -1) parseErrors.add(error(strang, curPos, "Missing body for %c directive",
- strang.charAt(1)));
+ if (idx == -1)
+ parseErrors.add(error(strang, curPos, "Missing body for %c directive",
+ strang.charAt(1)));
String options = dirBody.substring(0, idx);
dirBody = dirBody.substring(idx + 1);
switch (strang.charAt(1)) {
case '#': {
- NumericOptions numOpts = new NumericOptions(options, curPos, parseErrors);
+ NumericOptions numOpts
+ = new NumericOptions(options, curPos, parseErrors);
if (dirBody.startsWith("$")) {
dir = numeric(dirBody.substring(1));
@@ -933,27 +947,29 @@ public class InflectionString {
dir = literal(strang);
}
- if (dir != null) dirs.add(dir);
+ if (dir != null)
+ dirs.add(dir);
// Bump forward position.
curPos += strang.length();
}
- if (!parseErrors.isEmpty()) throw new InflectionFormatException(inp, parseErrors);
+ if (!parseErrors.isEmpty())
+ throw new InflectionFormatException(inp, parseErrors);
}
// Emit an error message
private static String error(String substr, int curPos, String msg, Object... props) {
- return String.format("%s (starting at position %d inside part %s)", String.format(msg, props), curPos,
- substr);
+ return String.format("%s (starting at position %d inside part %s)",
+ String.format(msg, props), curPos, substr);
}
/**
* Execute inflection of the string.
- *
+ *
* @param vars
- * The variables to insert into the string.
- *
+ * The variables to insert into the string.
+ *
* @return The inflected form of the string.
*/
public String inflect(Object... vars) {
@@ -969,10 +985,10 @@ public class InflectionString {
/**
* Execute inflection of the string.
- *
+ *
* @param vars
- * The variables to insert into the string.
- *
+ * The variables to insert into the string.
+ *
* @return The inflected form of the string.
*/
public String inflect(Map<String, Object> vars) {
@@ -1024,7 +1040,8 @@ public class InflectionString {
NumericOptions opts = (NumericOptions) dir.opts;
String rep = Integer.toString(curNum);
- if (opts.increment) curNum += opts.incrementAmt;
+ if (opts.increment)
+ curNum += opts.incrementAmt;
if (curNum == 1) {
inflectSingular = true;
} else if (curNum == 0 && opts.singular) {
@@ -1033,7 +1050,8 @@ public class InflectionString {
inflectSingular = false;
}
- if (opts.zeroNo && curNum == 0) rep = "no";
+ if (opts.zeroNo && curNum == 0)
+ rep = "no";
if (opts.article && curNum == 1) {
anNum += 1;
@@ -1042,7 +1060,8 @@ public class InflectionString {
pendingAn = true;
}
- if (opts.nonPrint) break;
+ if (opts.nonPrint)
+ break;
boolean override = true;
if (rep.equals("no") || rep.matches("\\{an\\d+\\}")) {
@@ -1124,7 +1143,8 @@ public class InflectionString {
itrDirs.before(dir.listDir);
break;
default:
- throw new IllegalArgumentException("Unhandled directive type " + dir.type);
+ throw new IllegalArgumentException(
+ "Unhandled directive type " + dir.type);
}
}
@@ -1147,7 +1167,7 @@ public class InflectionString {
public String toString() {
if (rawString != null)
return rawString;
-
+
return super.toString();
}
}
diff --git a/src/main/java/bjc/inflexion/NumberUtils.java b/src/main/java/bjc/inflexion/NumberUtils.java
index 3a0200d..f7ed9e5 100644
--- a/src/main/java/bjc/inflexion/NumberUtils.java
+++ b/src/main/java/bjc/inflexion/NumberUtils.java
@@ -2,26 +2,26 @@ package bjc.inflexion;
/**
* A variety of functions for doing useful stuff with numbers.
- *
+ *
* @author EVE
*
*/
public class NumberUtils {
/*
* @TODO 2/12/18 Ben Culkin :RomanExpansion
- *
- * Use U+305 for large roman numerals, as well as excels 'concise'
- * numerals (as implemented by roman()).
+ *
+ * Use U+305 for large roman numerals, as well as excels 'concise' numerals (as
+ * implemented by roman()).
*/
/**
* Convert a number into a roman numeral.
- *
+ *
* @param number
* The number to convert.
* @param classic
- * Whether to use classic roman numerals (use IIII
- * instead of IV, and such).
+ * Whether to use classic roman numerals (use IIII instead of IV,
+ * and such).
* @return The number as a roman numeral.
*/
public static String toRoman(long number, boolean classic) {
@@ -29,7 +29,9 @@ public class NumberUtils {
long currNumber = number;
- if (currNumber == 0) { return "N"; }
+ if (currNumber == 0) {
+ return "N";
+ }
if (currNumber < 0) {
currNumber *= -1;
@@ -130,9 +132,13 @@ public class NumberUtils {
return work.toString();
}
- private static String[] summaryNums = new String[] { "no", "one", "a couple of", "a few", "several" };
+ private static String[] summaryNums = new String[] {
+ "no", "one", "a couple of", "a few", "several"
+ };
- private static String[] summaryNumsEnd = new String[] { "none", "one", "a couple", "a few", "several" };
+ private static String[] summaryNumsEnd = new String[] {
+ "none", "one", "a couple", "a few", "several"
+ };
private static int[] summaryMap = new int[] {
/* no */
@@ -144,22 +150,24 @@ public class NumberUtils {
/* a few */
3, 3, 3,
/* several */
- 4, 4, 4, 4 };
+ 4, 4, 4, 4
+ };
/**
* Summarize an integer.
*
* @param num
- * The number to summarize.
+ * The number to summarize.
*
* @param atEnd
- * Whether or not the integer is at the end of a string.
+ * Whether or not the integer is at the end of a string.
*
* @return A string summarizing the integer.
*/
public static String summarizeNumber(final long num, final boolean atEnd) {
if (num >= 0 && num < 10) {
- if (atEnd) return summaryNumsEnd[summaryMap[(int) num]];
+ if (atEnd)
+ return summaryNumsEnd[summaryMap[(int) num]];
return summaryNums[summaryMap[(int) num]];
}
@@ -169,53 +177,59 @@ public class NumberUtils {
/**
* Convert a number into a cardinal number, up to a threshold.
- *
+ *
* @param number
- * The number to convert
+ * The number to convert
* @param thresh
- * The threshold to stop at.
+ * The threshold to stop at.
* @return The number as a cardinal.
*/
public static String toCardinal(long number, long thresh) {
- if (number < thresh) return toCardinal(number, null);
+ if (number < thresh)
+ return toCardinal(number, null);
return Long.toString(number);
}
/**
* Convert a number into a cardinal number.
- *
+ *
* @param number
- * The number to convert
+ * The number to convert
* @return The number as a cardinal.
*/
public static String toCardinal(long number) {
return toCardinal(number, null);
}
- private static String[] cardinals = new String[] { "zero", "one", "two", "three", "four", "five", "six",
- "seven", "eight", "nine", "ten", "eleven", "twelve", "thirteen", "fourteen", "fifteen",
- "sixteen", "seventeen", "eighteen", "nineteen", "twenty", };
+ private static String[] cardinals = new String[] {
+ "zero", "one", "two", "three", "four", "five", "six", "seven", "eight",
+ "nine", "ten", "eleven", "twelve", "thirteen", "fourteen", "fifteen",
+ "sixteen", "seventeen", "eighteen", "nineteen", "twenty",
+ };
/**
* Convert a number into a cardinal number.
- *
+ *
* @param number
- * The number to convert to a cardinal.
+ * The number to convert to a cardinal.
* @param custom
- * The customizations to use.
+ * The customizations to use.
* @return The number as a cardinal.
*/
public static String toCardinal(long number, CardinalState custom) {
if (custom != null) {
String res = custom.handleCustom(number);
- if (res != null) return res;
+ if (res != null)
+ return res;
}
- if (number < 0) return "negative " + toCardinal(number * -1, custom);
+ if (number < 0)
+ return "negative " + toCardinal(number * -1, custom);
- if (number <= 20) return cardinals[(int) number];
+ if (number <= 20)
+ return cardinals[(int) number];
if (number < 100) {
if (number % 10 == 0) {
@@ -252,7 +266,8 @@ public class NumberUtils {
long numHundreds = number / 100;
long rest = number % 100;
- return toCardinal(numHundreds, custom) + " hundred and " + toCardinal(rest, custom);
+ return toCardinal(numHundreds, custom) + " hundred and "
+ + toCardinal(rest, custom);
}
long MILLION = (long) (Math.pow(10, 6));
@@ -260,7 +275,8 @@ public class NumberUtils {
long numThousands = number / 1000;
long rest = number % 1000;
- return toCardinal(numThousands, custom) + " thousand, " + toCardinal(rest, custom);
+ return toCardinal(numThousands, custom) + " thousand, "
+ + toCardinal(rest, custom);
}
long BILLION = (long) (Math.pow(10, 9));
@@ -268,7 +284,8 @@ public class NumberUtils {
long numMillions = number / MILLION;
long rest = number % MILLION;
- return toCardinal(numMillions, custom) + " million, " + toCardinal(rest, custom);
+ return toCardinal(numMillions, custom) + " million, "
+ + toCardinal(rest, custom);
}
long TRILLION = (long) (Math.pow(10, 12));
@@ -276,7 +293,8 @@ public class NumberUtils {
long numBillions = number / BILLION;
long rest = number % BILLION;
- return toCardinal(numBillions, custom) + " billion, " + toCardinal(rest, custom);
+ return toCardinal(numBillions, custom) + " billion, "
+ + toCardinal(rest, custom);
}
throw new IllegalArgumentException(
@@ -285,11 +303,11 @@ public class NumberUtils {
/**
* Convert a number into an ordinal, up to a certain value.
- *
+ *
* @param number
- * The number to convert to an ordinal.
+ * The number to convert to an ordinal.
* @param thresh
- * The threshold value to stop converting at.
+ * The threshold value to stop converting at.
* @return The number as an ordinal.
*/
public static String toOrdinal(long number, long thresh) {
@@ -298,27 +316,28 @@ public class NumberUtils {
/**
* Convert a number into an ordinal, up to a certain value.
- *
+ *
* @param number
- * The number to convert to an ordinal.
+ * The number to convert to an ordinal.
* @param thresh
- * The threshold value to stop converting at.
+ * The threshold value to stop converting at.
* @param longForm
- * Whether or not to use long-form ordinals (zeroth,
- * first, etc.) instead of (0th, 1st, etc.)
+ * Whether or not to use long-form ordinals (zeroth, first,
+ * etc.) instead of (0th, 1st, etc.)
* @return The number as an ordinal.
*/
public static String toOrdinal(long number, long thresh, boolean longForm) {
- if (number < thresh) return toOrdinal(number, longForm);
+ if (number < thresh)
+ return toOrdinal(number, longForm);
return Long.toString(number);
}
/**
* Convert a number into an ordinal.
- *
+ *
* @param number
- * The number to convert to an ordinal.
+ * The number to convert to an ordinal.
* @return The number as an ordinal.
*/
public static String toOrdinal(long number) {
@@ -327,16 +346,18 @@ public class NumberUtils {
/**
* Convert a number into an ordinal.
- *
+ *
* @param number
- * The number to convert to an ordinal.
+ * The number to convert to an ordinal.
* @param longForm
- * Whether or not to use long-form ordinals (zeroth,
- * first, etc.) instead of (0th, 1st, etc.)
+ * Whether or not to use long-form ordinals (zeroth, first,
+ * etc.) instead of (0th, 1st, etc.)
* @return The number as an ordinal.
*/
public static String toOrdinal(long number, boolean longForm) {
- if (number < 0) { return "minus " + toOrdinal(number, longForm); }
+ if (number < 0) {
+ return "minus " + toOrdinal(number, longForm);
+ }
if (longForm) {
if (number < 20) {
@@ -415,7 +436,8 @@ public class NumberUtils {
}
long numPostfix = number % 10;
- return toCardinal(number - numPostfix) + "-" + toOrdinal(numPostfix, longForm);
+ return toCardinal(number - numPostfix) + "-"
+ + toOrdinal(numPostfix, longForm);
}
}
@@ -423,7 +445,9 @@ public class NumberUtils {
long tens = procNum / 10;
long ones = procNum % 10;
- if (tens == 1) { return Long.toString(number) + "th"; }
+ if (tens == 1) {
+ return Long.toString(number) + "th";
+ }
switch ((int) ones) {
case 1:
@@ -462,27 +486,30 @@ public class NumberUtils {
/**
* Convert a number into a commafied string.
- *
+ *
* @param val
- * The number to convert.
+ * The number to convert.
* @param mincols
- * The minimum number of columns to use.
+ * The minimum number of columns to use.
* @param padchar
- * The padding char to use.
+ * The padding char to use.
* @param commaInterval
- * The interval to place commas at.
+ * The interval to place commas at.
* @param commaChar
- * The character to use as a comma
+ * The character to use as a comma
* @param signed
- * Whether or not to always display a sign
+ * Whether or not to always display a sign
* @param radix
- * The radix to use
+ * The radix to use
* @return The number as a commafied string.
*/
- public static String toCommaString(long val, int mincols, char padchar, int commaInterval, char commaChar,
- boolean signed, int radix) {
- if (radix > radixChars.length) { throw new IllegalArgumentException(String.format(
- "Radix %d is larger than largest supported radix %d", radix, radixChars.length)); }
+ public static String toCommaString(long val, int mincols, char padchar,
+ int commaInterval, char commaChar, boolean signed, int radix) {
+ if (radix > radixChars.length) {
+ throw new IllegalArgumentException(
+ String.format("Radix %d is larger than largest supported radix %d",
+ radix, radixChars.length));
+ }
StringBuilder work = new StringBuilder();
@@ -512,7 +539,8 @@ public class NumberUtils {
if (isNeg)
work.append("-");
- else if (signed) work.append("+");
+ else if (signed)
+ work.append("+");
work.reverse();
@@ -521,8 +549,7 @@ public class NumberUtils {
*
* Should we have some way to specify how to pad?
*
- * By this, I mean specify padding direction (left, right,
- * balanced...)
+ * By this, I mean specify padding direction (left, right, balanced...)
*/
StringBuilder pad = new StringBuilder();
@@ -536,9 +563,9 @@ public class NumberUtils {
// behavior, or if something is wrong with the
// example case in the menu
// if (commaInterval != 0 && padCount != 0) {
- // if (Character.isDigit(padchar) && padCount % commaInterval == 0)
- // pad.append(commaChar);
- // else
+ // if (Character.isDigit(padchar) && padCount % commaInterval == 0)
+ // pad.append(commaChar);
+ // else
pad.append(padchar);
// }
@@ -551,7 +578,7 @@ public class NumberUtils {
/**
* Convert a number to a normal commafied string.
- *
+ *
* @param val
* The value to convert.
* @param mincols
@@ -564,7 +591,8 @@ public class NumberUtils {
* The radix to use.
* @return The number as a normal commafied string.
*/
- public static String toNormalString(long val, int mincols, char padchar, boolean signed, int radix) {
+ public static String toNormalString(long val, int mincols, char padchar,
+ boolean signed, int radix) {
return toCommaString(val, mincols, padchar, 0, ',', signed, radix);
}
}
diff --git a/src/main/java/bjc/inflexion/QueuedIterator.java b/src/main/java/bjc/inflexion/QueuedIterator.java
index ab4a447..0dc98a1 100644
--- a/src/main/java/bjc/inflexion/QueuedIterator.java
+++ b/src/main/java/bjc/inflexion/QueuedIterator.java
@@ -6,10 +6,11 @@ import java.util.Iterator;
/**
* An iterator that supports queuing elements after/before the current iterator;
- *
+ *
* @author bjculkin
*
- * @param <E> The type of element this iterator iterates over
+ * @param <E>
+ * The type of element this iterator iterates over
*/
public class QueuedIterator<E> implements Iterator<E> {
private Iterator<E> cur;
@@ -18,7 +19,7 @@ public class QueuedIterator<E> implements Iterator<E> {
/**
* Static method for constructing iterators.
- *
+ *
* @return A queued iterator.
*/
public static <E> QueuedIterator<E> queued() {
@@ -27,9 +28,9 @@ public class QueuedIterator<E> implements Iterator<E> {
/**
* Static method for constructing iterators.
- *
+ *
* @param itrs
- * The iterators to use.
+ * The iterators to use.
* @return A queued iterator over the provided iterators.
*/
@SafeVarargs
@@ -39,9 +40,9 @@ public class QueuedIterator<E> implements Iterator<E> {
/**
* Static method for constructing iterators.
- *
+ *
* @param itrs
- * The iterables to use.
+ * The iterables to use.
* @return A queued iterator over the provided iterables.
*/
@SafeVarargs
@@ -58,9 +59,9 @@ public class QueuedIterator<E> implements Iterator<E> {
/**
* Create a new queued iterator with a set of initial sources.
- *
+ *
* @param inits
- * The set of initial iterators to use.
+ * The set of initial iterators to use.
*/
@SafeVarargs
public QueuedIterator(Iterator<E>... inits) {
@@ -73,9 +74,9 @@ public class QueuedIterator<E> implements Iterator<E> {
/**
* Create a new queued iterator with a set of initial sources.
- *
+ *
* @param inits
- * The set of initial iterables to use.
+ * The set of initial iterables to use.
*/
@SafeVarargs
public QueuedIterator(Iterable<E>... inits) {
@@ -88,9 +89,9 @@ public class QueuedIterator<E> implements Iterator<E> {
/**
* Add a new iterator who we will iterate through first.
- *
+ *
* @param itr
- * The iterator to go through first.
+ * The iterator to go through first.
*/
public void before(Iterator<E> itr) {
pending.push(cur);
@@ -100,38 +101,39 @@ public class QueuedIterator<E> implements Iterator<E> {
/**
* Add a new iterable who we will iterate through first.
- *
+ *
* @param itr
- * The iterable to go through first.
+ * The iterable to go through first.
*/
public void before(Iterable<E> itr) {
before(itr.iterator());
}
-
+
/**
* Add a new iterator who we will iterate through next.
- *
+ *
* @param itr
- * The iterator to go through next.
+ * The iterator to go through next.
*/
public void after(Iterator<E> itr) {
pending.push(itr);
}
+
/**
* Add a new iterable who we will iterate through next.
- *
+ *
* @param itr
- * The iterable to go through next.
+ * The iterable to go through next.
*/
public void after(Iterable<E> itr) {
after(itr.iterator());
}
-
+
/**
* Add a new iterator who we will iterate through last.
- *
+ *
* @param itr
- * The iterator to go through last.
+ * The iterator to go through last.
*/
public void last(Iterator<E> itr) {
pending.add(itr);
@@ -139,17 +141,19 @@ public class QueuedIterator<E> implements Iterator<E> {
/**
* Add a new iterable who we will iterate through last.
- *
+ *
* @param itr
- * The iterable to go through last.
+ * The iterable to go through last.
*/
public void last(Iterable<E> itr) {
last(itr.iterator());
}
+
@Override
public boolean hasNext() {
while (cur == null || !cur.hasNext()) {
- if (pending.isEmpty()) return false;
+ if (pending.isEmpty())
+ return false;
cur = pending.pop();
}
@@ -160,7 +164,8 @@ public class QueuedIterator<E> implements Iterator<E> {
@Override
public E next() {
while (cur == null || !cur.hasNext()) {
- if (pending.isEmpty()) return null;
+ if (pending.isEmpty())
+ return null;
cur = pending.pop();
}
diff --git a/src/main/java/bjc/inflexion/nouns/CategoricalNounInflection.java b/src/main/java/bjc/inflexion/nouns/CategoricalNounInflection.java
index 9fafcff..eb5e4ea 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 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 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..6dbd353 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);
}
@@ -129,9 +129,8 @@ public class IrregularNounInflection implements NounInflection {
} 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;
}