From bb1941650805ea7772082ee2724b98bb8154148e Mon Sep 17 00:00:00 2001 From: Peter Wu Date: Thu, 15 May 2014 16:40:46 +0200 Subject: Catch a more specific NoSuchElementException, fix lexicon reading --- src/main/Analyzor.java | 5 +++-- src/main/FarmShell.java | 13 ++++++++----- 2 files changed, 11 insertions(+), 7 deletions(-) (limited to 'src') diff --git a/src/main/Analyzor.java b/src/main/Analyzor.java index 9be1101..b4fbae7 100644 --- a/src/main/Analyzor.java +++ b/src/main/Analyzor.java @@ -2,6 +2,7 @@ package main; import database.NamedPreparedStatement; import database.QueryUtils; +import java.io.File; import java.io.FileNotFoundException; import java.io.IOException; import java.sql.Connection; @@ -43,8 +44,8 @@ public class Analyzor { // A unigram is in the format (WS = whitespace): // word rating ??? ?? // A bigram has an two WS-separated words instead of one. - try (Scanner uniScanner = new Scanner("unigrams-pmilexicon.txt"); - Scanner biScanner = new Scanner("bigrams-pmilexicon.txt");) { + try (Scanner uniScanner = new Scanner(new File("unigrams-pmilexicon.txt")); + Scanner biScanner = new Scanner(new File("bigrams-pmilexicon.txt"));) { //Fill the map of unigrams while (uniScanner.hasNext()) { String words = uniScanner.next(); diff --git a/src/main/FarmShell.java b/src/main/FarmShell.java index 3c6f17f..7186c2f 100644 --- a/src/main/FarmShell.java +++ b/src/main/FarmShell.java @@ -64,8 +64,6 @@ public class FarmShell { // print prompt for reading next line printPrompt(); } - // prevent corrupted compressed files when exiting without a command - throw new NoSuchElementException(); } /** @@ -102,8 +100,13 @@ public class FarmShell { System.err.println("Command " + args[0] + " failed with " + ex); ex.printStackTrace(); } catch (NoSuchElementException ex) { - // thrown by the "exit" command to signal exit - return false; + if ("EXIT NOW".equals(ex.getMessage())) { + // thrown by the "exit" command to signal exit + return false; + } else { + System.err.println("ZOMG SOMETHIGN FAILED: " + ex.getMessage()); + ex.printStackTrace(); + } } catch (SQLException ex) { System.err.println("such " + ex); } @@ -145,7 +148,7 @@ public class FarmShell { } break; case exit: - throw new NoSuchElementException(); + throw new NoSuchElementException("EXIT NOW"); default: throw new AssertionError(command.name()); } -- cgit v1.2.1 From ef978326e8b4765c9c9a7c0d649d557a8eb250ec Mon Sep 17 00:00:00 2001 From: Peter Wu Date: Thu, 15 May 2014 16:43:53 +0200 Subject: Do not try to rewind a non-rewindable resultset --- src/main/Analyzor.java | 1 - 1 file changed, 1 deletion(-) (limited to 'src') diff --git a/src/main/Analyzor.java b/src/main/Analyzor.java index b4fbae7..3ef450d 100644 --- a/src/main/Analyzor.java +++ b/src/main/Analyzor.java @@ -96,7 +96,6 @@ public class Analyzor { System.err.println("data is empty, try querying first"); return; } - data.beforeFirst(); Double value; String text; -- cgit v1.2.1 From 9cda667f93e1b2226b8ef7eb97c00c21f3b6211e Mon Sep 17 00:00:00 2001 From: Peter Wu Date: Thu, 15 May 2014 17:12:06 +0200 Subject: Print status info for lexicons reading --- src/main/Analyzor.java | 2 ++ 1 file changed, 2 insertions(+) (limited to 'src') diff --git a/src/main/Analyzor.java b/src/main/Analyzor.java index 3ef450d..639f385 100644 --- a/src/main/Analyzor.java +++ b/src/main/Analyzor.java @@ -41,6 +41,7 @@ public class Analyzor { // data is already read. return; } + System.err.println("Trying to read lexicons..."); // A unigram is in the format (WS = whitespace): // word rating ??? ?? // A bigram has an two WS-separated words instead of one. @@ -64,6 +65,7 @@ public class Analyzor { } } } + System.err.println("Lexicons are read."); } /** -- cgit v1.2.1