summaryrefslogtreecommitdiff
path: root/src/main/java/bjc/inflexion/InflectionML.java
diff options
context:
space:
mode:
authorBenjamin J. Culkin <bjculkin@mix.wvu.edu>2020-09-10 17:12:59 -0300
committerBenjamin J. Culkin <bjculkin@mix.wvu.edu>2020-09-10 17:12:59 -0300
commit229054f4839ad99c8c9fc757cce7edc0d2ca3cf1 (patch)
treef9de568967b82c46f6d22eda9c843529b6045b5d /src/main/java/bjc/inflexion/InflectionML.java
parentcb45132debdbce593a235323e9155b5c47906558 (diff)
parente71ef0d03e87df19900db8328cda68d38d523b0b (diff)
Merge branch 'master' of https://github.com/bculkin2442/Inflexion
Diffstat (limited to 'src/main/java/bjc/inflexion/InflectionML.java')
-rw-r--r--src/main/java/bjc/inflexion/InflectionML.java39
1 files changed, 26 insertions, 13 deletions
diff --git a/src/main/java/bjc/inflexion/InflectionML.java b/src/main/java/bjc/inflexion/InflectionML.java
index f5fbb02..34b534a 100644
--- a/src/main/java/bjc/inflexion/InflectionML.java
+++ b/src/main/java/bjc/inflexion/InflectionML.java
@@ -13,6 +13,8 @@
*/
package bjc.inflexion;
+import java.io.IOException;
+import java.io.InputStream;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
@@ -31,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.
*/
@@ -47,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+)\\}");
@@ -57,17 +60,26 @@ public class InflectionML {
/* Load DBs from files. */
static {
final Prepositions prepositionDB = new Prepositions();
- prepositionDB.loadFromStream(InflectionML.class.getResourceAsStream("/prepositions.txt"));
+ try (InputStream strim
+ = InflectionML.class.getResourceAsStream("/prepositions.txt")) {
+ prepositionDB.loadFromStream(strim);
+ } catch (IOException ioex) {
+ ioex.printStackTrace();
+ }
nounDB = new Nouns(prepositionDB);
- nounDB.loadFromStream(InflectionML.class.getResourceAsStream("/nouns.txt"));
+ try (InputStream strim = InflectionML.class.getResourceAsStream("/nouns.txt")) {
+ nounDB.loadFromStream(strim);
+ } catch (IOException ioex) {
+ ioex.printStackTrace();
+ }
}
/**
* Apply inflection to marked forms in the string.
*
* @param form
- * The string to inflect.
+ * The string to inflect.
*
* @return The inflected string.
*/
@@ -154,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")) {
@@ -228,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')) {
@@ -239,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);
@@ -248,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":