From 2d140567edf035fe665f66b78d488bc12c0f157b Mon Sep 17 00:00:00 2001 From: Ben Culkin Date: Mon, 30 Mar 2020 20:58:40 -0400 Subject: Clean up warnings Clear up some warnings that had popped up. Mostly, closing some input streams after we're done with them. --- .../java/bjc/inflexion/examples/InflexionTester.java | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) (limited to 'src/examples') diff --git a/src/examples/java/bjc/inflexion/examples/InflexionTester.java b/src/examples/java/bjc/inflexion/examples/InflexionTester.java index ff5dcd7..0595cfa 100644 --- a/src/examples/java/bjc/inflexion/examples/InflexionTester.java +++ b/src/examples/java/bjc/inflexion/examples/InflexionTester.java @@ -48,11 +48,18 @@ public class InflexionTester { */ 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); -- cgit v1.2.3 From 2f6a7807f7180fb467e3d06f2af4263a45759c28 Mon Sep 17 00:00:00 2001 From: Ben Culkin Date: Mon, 13 Apr 2020 18:44:24 -0400 Subject: Cleanup pass Pass to do some cleanups --- .../java/bjc/inflexion/examples/IndefTester.java | 7 +++-- .../bjc/inflexion/examples/InflexionTester.java | 34 ++++++++++++---------- 2 files changed, 24 insertions(+), 17 deletions(-) (limited to 'src/examples') 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 0595cfa..bf0452c 100644 --- a/src/examples/java/bjc/inflexion/examples/InflexionTester.java +++ b/src/examples/java/bjc/inflexion/examples/InflexionTester.java @@ -44,11 +44,12 @@ 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(); - try (InputStream strim = InflectionML.class.getResourceAsStream("/prepositions.txt")) { + try (InputStream strim + = InflectionML.class.getResourceAsStream("/prepositions.txt")) { prepositionDB.loadFromStream(strim); } catch (IOException ioex) { ioex.printStackTrace(); @@ -88,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 @@ -106,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\\-]+)"); @@ -227,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)); } } } @@ -243,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) { -- cgit v1.2.3