summaryrefslogtreecommitdiff
path: root/src/main/FarmShell.java
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/FarmShell.java')
-rw-r--r--src/main/FarmShell.java109
1 files changed, 60 insertions, 49 deletions
diff --git a/src/main/FarmShell.java b/src/main/FarmShell.java
index daab973..80dce2e 100644
--- a/src/main/FarmShell.java
+++ b/src/main/FarmShell.java
@@ -1,5 +1,6 @@
package main;
+import database.ConnectionBuilder;
import java.io.IOException;
import java.util.Arrays;
import java.util.NoSuchElementException;
@@ -11,14 +12,23 @@ import java.util.Scanner;
*/
public class FarmShell {
+ /**
+ * A scanner for the stdin.
+ */
private final Scanner scanner = new Scanner(System.in);
- Analyzor analyzor;
+ /**
+ * The sentiment analysis class.
+ */
+ private final Analyzor analyzor;
- private void printPrompt() {
- System.out.print("$ ");
+ /**
+ * @param builder The connection builder for the database.
+ */
+ public FarmShell(final ConnectionBuilder builder) {
+ analyzor = new Analyzor(builder);
}
-
+
/**
* Processes commands from stdin until the exit command is received or EOF.
*/
@@ -67,7 +77,6 @@ public class FarmShell {
* otherwise.
*/
public boolean execute(String[] args) {
-
try {
Command command = Command.fromString(args[0]);
@@ -85,11 +94,55 @@ public class FarmShell {
// another satisfied customer, next!
return true;
}
+
+ private void execute(Command command, String[] params) throws IOException {
+ if (params.length < command.getParamCount()) {
+ throw new IllegalArgumentException("Expected "
+ + command.getParamCount() + " parameters, got only "
+ + params.length);
+ }
+ switch (command) {
+ case query:
+ //make a new Analyzor
+ analyzor.Query(params[0]);
+ break;
+ case filterbots:
+ System.out.println("not yet implemented");
+ break;
+ case sentiment:
+ analyzor.sentimentAnalysis();
+ 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());
+ }
+ }
+
+ private void printPrompt() {
+ System.out.print("$ ");
+ }
enum Command {
-
query("make a query to the database; needed to do analysis", 1),
- filterbots("marks all users as bot or not"),
+ filterbots("Filters and marks the bots in all the users"),
sentiment("analyzes all tweets on positivity (about a brand)"),
exit("Returns to shell"),
help("Get help");
@@ -130,46 +183,4 @@ public class FarmShell {
"",
"Available commands:"
};
-
- private void execute(Command command, String[] params) throws IOException {
- if (params.length < command.getParamCount()) {
- throw new IllegalArgumentException("Expected "
- + command.getParamCount() + " parameters, got only "
- + params.length);
- }
- switch (command) {
- case query:
- //make a new Analyzor
- analyzor = new Analyzor();
- analyzor.Query(params[0]);
- break;
- case filterbots:
- System.out.println("not yet implemented");
- break;
- case sentiment:
- analyzor.sentimentAnalysis();
- 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());
- }
- }
}