diff options
Diffstat (limited to 'src/main/java/bjc/inflexion/InflectionML.java')
| -rw-r--r-- | src/main/java/bjc/inflexion/InflectionML.java | 39 |
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": |
