diff options
| author | Benjamin J. Culkin <bjculkin@mix.wvu.edu> | 2020-09-10 17:12:59 -0300 |
|---|---|---|
| committer | Benjamin J. Culkin <bjculkin@mix.wvu.edu> | 2020-09-10 17:12:59 -0300 |
| commit | 229054f4839ad99c8c9fc757cce7edc0d2ca3cf1 (patch) | |
| tree | f9de568967b82c46f6d22eda9c843529b6045b5d /src/examples | |
| parent | cb45132debdbce593a235323e9155b5c47906558 (diff) | |
| parent | e71ef0d03e87df19900db8328cda68d38d523b0b (diff) | |
Merge branch 'master' of https://github.com/bculkin2442/Inflexion
Diffstat (limited to 'src/examples')
| -rw-r--r-- | src/examples/java/bjc/inflexion/examples/IndefTester.java | 7 | ||||
| -rw-r--r-- | src/examples/java/bjc/inflexion/examples/InflexionTester.java | 47 |
2 files changed, 34 insertions, 20 deletions
diff --git a/src/examples/java/bjc/inflexion/examples/IndefTester.java b/src/examples/java/bjc/inflexion/examples/IndefTester.java index e22737c..6172eca 100644 --- a/src/examples/java/bjc/inflexion/examples/IndefTester.java +++ b/src/examples/java/bjc/inflexion/examples/IndefTester.java @@ -6,13 +6,16 @@ import bjc.inflexion.EnglishUtils; /** * Test class for checking indefinite articles + * * @author bjculkin * */ public class IndefTester { /** * Main method. - * @param args Unused CLI args. + * + * @param args + * Unused CLI args. */ public static void main(String[] args) { Scanner scn = new Scanner(System.in); @@ -20,7 +23,7 @@ public class IndefTester { System.out.print("Enter word: "); String word = scn.nextLine().trim(); - while(!word.equals("")) { + while (!word.equals("")) { System.out.printf("\t%s %s\n", EnglishUtils.pickIndefinite(word), word); System.out.print("Enter word: "); diff --git a/src/examples/java/bjc/inflexion/examples/InflexionTester.java b/src/examples/java/bjc/inflexion/examples/InflexionTester.java index ff5dcd7..bf0452c 100644 --- a/src/examples/java/bjc/inflexion/examples/InflexionTester.java +++ b/src/examples/java/bjc/inflexion/examples/InflexionTester.java @@ -44,15 +44,23 @@ public class InflexionTester { * Main method. * * @param args - * Unused CLI args. + * Unused CLI args. */ public static void main(final String[] args) { final Prepositions prepositionDB = new Prepositions(); - prepositionDB.loadFromStream( - InflexionTester.class.getResourceAsStream("/prepositions.txt")); + try (InputStream strim + = InflectionML.class.getResourceAsStream("/prepositions.txt")) { + prepositionDB.loadFromStream(strim); + } catch (IOException ioex) { + ioex.printStackTrace(); + } - final Nouns nounDB = new Nouns(prepositionDB); - nounDB.loadFromStream(InflexionTester.class.getResourceAsStream("/nouns.txt")); + Nouns nounDB = new Nouns(prepositionDB); + try (InputStream strim = InflectionML.class.getResourceAsStream("/nouns.txt")) { + nounDB.loadFromStream(strim); + } catch (IOException ioex) { + ioex.printStackTrace(); + } final Scanner scn = new Scanner(System.in); @@ -81,7 +89,8 @@ public class InflexionTester { try (InputStream compressedStream = new FileInputStream(fname)) { final InputStream stream = new BZip2CompressorInputStream(compressedStream); - final BufferedReader reader = new BufferedReader(new InputStreamReader(stream)); + final BufferedReader reader + = new BufferedReader(new InputStreamReader(stream)); /* * Pattern find word name @@ -99,7 +108,7 @@ public class InflexionTester { * Pattern to find noun definition */ final Pattern enNounPattern = Pattern - .compile("\\{\\{en-noun([a-z0-9\\|\\-\\[\\]\\?\\!=]*)\\}\\}"); + .compile("\\{\\{en-noun([a-z0-9\\|\\-\\[\\]\\?\\!=]*)\\}\\}"); final Pattern wordPattern = Pattern.compile("([a-zA-Z\\-]+)"); @@ -220,13 +229,13 @@ public class InflexionTester { } if (basicWord) { - System.out.println("basic word: " + word + " got: " - + calculatedPlural + ", but expected " - + enNounMatcher.group(1)); + System.out.println( + "basic word: " + word + " got: " + calculatedPlural + + ", but expected " + enNounMatcher.group(1)); basicWrong++; } else if (!uncountable) { System.out.println(word + " got: " + calculatedPlural - + ", but expected " + enNounMatcher.group(1)); + + ", but expected " + enNounMatcher.group(1)); } } } @@ -236,18 +245,20 @@ public class InflexionTester { compressedStream.close(); final float correct = (count - wrong) * 100 / (float) count; - final float basicCorrect = (basicCount - basicWrong) * 100 / (float) basicCount; + final float basicCorrect + = (basicCount - basicWrong) * 100 / (float) basicCount; final float wrongNoPluralPercent = wrongNoPlural * 100 / (float) count; final int justPlainWrong = wrong - wrongNoPlural; final float justPlainWrongPercent = justPlainWrong * 100 / (float) count; - System.out.println("Words checked: " + count + " (" + basicCount + " basic words)"); - System.out.println("Correct: " + correct + "% (" + basicCorrect + "% basic words)"); + System.out.println( + "Words checked: " + count + " (" + basicCount + " basic words)"); + System.out.println( + "Correct: " + correct + "% (" + basicCorrect + "% basic words)"); System.out.println("Errors: "); System.out.println(" No plural form specified: " + wrongNoPlural + " (" - + wrongNoPluralPercent + "%)"); - System.out.println(" Incorrect answer: " + justPlainWrong + " (" + - justPlainWrongPercent - + "%)"); + + wrongNoPluralPercent + "%)"); + System.out.println(" Incorrect answer: " + justPlainWrong + " (" + + justPlainWrongPercent + "%)"); } catch (final FileNotFoundException fnfex) { fnfex.printStackTrace(); } catch (final IOException ioex) { |
