summaryrefslogtreecommitdiff
path: root/src/main/FarmShell.java
diff options
context:
space:
mode:
authorPeter Wu <peter@lekensteyn.nl>2014-05-15 16:22:53 +0200
committerPeter Wu <peter@lekensteyn.nl>2014-05-15 16:22:53 +0200
commit53a0049712a50949dc3972c189a9c268907b1d81 (patch)
tree2ec202f3545207fda9c426fe13daf1fc71a038dc /src/main/FarmShell.java
parent8d0aa5d81d33167ac4449e68b172a5402e815156 (diff)
parent0c90e906db44c6a61e28338d4abc71d27c7b936f (diff)
downloadGoldfarmer-53a0049712a50949dc3972c189a9c268907b1d81.tar.gz
Merge remote-tracking branch 'origin/master'
Conflicts: src/main/Analyzor.java src/main/FarmShell.java src/main/Main.java
Diffstat (limited to 'src/main/FarmShell.java')
-rw-r--r--src/main/FarmShell.java93
1 files changed, 49 insertions, 44 deletions
diff --git a/src/main/FarmShell.java b/src/main/FarmShell.java
index cf15ff3..9dd1167 100644
--- a/src/main/FarmShell.java
+++ b/src/main/FarmShell.java
@@ -14,6 +14,9 @@ import java.util.Scanner;
*/
public class FarmShell {
+ /**
+ * A scanner for the stdin.
+ */
private final Scanner scanner = new Scanner(System.in);
private Analyzor cached_analyzor;
@@ -65,6 +68,12 @@ public class FarmShell {
throw new NoSuchElementException();
}
+ /**
+ * Execute a single commands.
+ *
+ * @param cmd A single line of the command.
+ * @return Whether to continue or exit the application.
+ */
public boolean execute(String cmd) {
String[] args = cmd.trim().split("\\s+", 2);
if (!args[0].isEmpty()) {
@@ -102,9 +111,48 @@ public class FarmShell {
return true;
}
+ private void execute(Command command, String[] params) throws SQLException, IOException {
+ if (params.length < command.getParamCount()) {
+ throw new IllegalArgumentException("Expected "
+ + command.getParamCount() + " parameters, got only "
+ + params.length);
+ }
+ switch (command) {
+ case filterbots:
+ System.out.println("not yet implemented");
+ break;
+ case sentiment:
+ getAnalyzor().sentimentAnalysis(params[0]);
+ break;
+ case wordcloud:
+ getAnalyzor().makeWordCloud(params[0]);
+ break;
+ case help:
+ for (String line : HELP) {
+ System.out.println(line);
+ }
+ for (Command cmd : Command.values()) {
+ System.out.printf(" %-10s", cmd.name());
+ if (!cmd.getDescription().isEmpty()) {
+ System.out.print(" " + cmd.getDescription());
+ }
+ if (cmd.getParamCount() == 1) {
+ System.out.print(" (1 arg)");
+ } else if (cmd.getParamCount() > 1) {
+ System.out.printf(" (%d args)", cmd.getParamCount());
+ }
+ System.out.println();
+ }
+ break;
+ case exit:
+ throw new NoSuchElementException();
+ default:
+ throw new AssertionError(command.name());
+ }
+ }
+
enum Command {
- query("make a query to the database; needed to do analysis", 1),
filterbots("marks all users as bot or not", 1),
sentiment("analyzes all tweets on positivity (about a brand)", 1),
wordcloud("makes a wordcloud of the text of the tweets", 1),
@@ -147,47 +195,4 @@ public class FarmShell {
"",
"Available commands:"
};
-
- private void execute(Command command, String[] params) throws SQLException, IOException {
- if (params.length < command.getParamCount()) {
- throw new IllegalArgumentException("Expected "
- + command.getParamCount() + " parameters, got only "
- + params.length);
- }
- switch (command) {
- case query:
- System.err.println("isn't supported anymore, now enter query after analysis type");
- break;
- case filterbots:
- System.out.println("not yet implemented");
- break;
- case sentiment:
- getAnalyzor().sentimentAnalysis(params[0]);
- break;
- case wordcloud:
- getAnalyzor().makeWordCloud(params[0]);
- break;
- case help:
- for (String line : HELP) {
- System.out.println(line);
- }
- for (Command cmd : Command.values()) {
- System.out.printf(" %-10s", cmd.name());
- if (!cmd.getDescription().isEmpty()) {
- System.out.print(" " + cmd.getDescription());
- }
- if (cmd.getParamCount() == 1) {
- System.out.print(" (1 arg)");
- } else if (cmd.getParamCount() > 1) {
- System.out.printf(" (%d args)", cmd.getParamCount());
- }
- System.out.println();
- }
- break;
- case exit:
- throw new NoSuchElementException();
- default:
- throw new AssertionError(command.name());
- }
- }
}