summaryrefslogtreecommitdiff
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
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
-rw-r--r--nbproject/genfiles.properties4
-rwxr-xr-xrun.sh20
-rw-r--r--src/analysis/BrandChecker.java61
-rw-r--r--src/main/Analyzor.java38
-rw-r--r--src/main/FarmShell.java93
-rw-r--r--src/main/Main.java12
6 files changed, 161 insertions, 67 deletions
diff --git a/nbproject/genfiles.properties b/nbproject/genfiles.properties
index a2b5530..cc698f1 100644
--- a/nbproject/genfiles.properties
+++ b/nbproject/genfiles.properties
@@ -4,5 +4,5 @@ build.xml.stylesheet.CRC32=8064a381@1.68.1.46
# This file is used by a NetBeans-based IDE to track changes in generated files such as build-impl.xml.
# Do not edit this file. You may delete it but then the IDE will never regenerate such files for you.
nbproject/build-impl.xml.data.CRC32=e2d66212
-nbproject/build-impl.xml.script.CRC32=ae9729a9
-nbproject/build-impl.xml.stylesheet.CRC32=5a01deb7@1.68.1.46
+nbproject/build-impl.xml.script.CRC32=5a37ea3f
+nbproject/build-impl.xml.stylesheet.CRC32=876e7a8f@1.74.2.48
diff --git a/run.sh b/run.sh
new file mode 100755
index 0000000..d6bc225
--- /dev/null
+++ b/run.sh
@@ -0,0 +1,20 @@
+#!/bin/sh
+# You should build the jar file with `ant jar`, then run this script
+
+# Exit on errors
+set -e
+
+# Change dir to project
+cd "$(dirname "$(readlink -f "$0")")"
+
+# java jar is slower. Also note that netbeans might already have built the
+# classes so `ant compile` will be faster.
+ant -q compile
+java -cp build/classes:$(echo lib/*.jar | tr \ :) main.Main "$@"
+exit # Do not build jar
+
+jar=dist/Datafiller.jar
+# Build jar if missing
+[ -e "$jar" ] || ant jar
+
+java -jar "$jar" "$@"
diff --git a/src/analysis/BrandChecker.java b/src/analysis/BrandChecker.java
new file mode 100644
index 0000000..6b57a39
--- /dev/null
+++ b/src/analysis/BrandChecker.java
@@ -0,0 +1,61 @@
+/*
+ * DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE Version 2, December 2004
+ *
+ * Copyright (C) 2004 Sam Hocevar
+ *
+ * Everyone is permitted to copy and distribute verbatim or modified copies
+ * of this license document, and changing it is allowed as long as the name is
+ * changed.
+ *
+ * DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE TERMS AND CONDITIONS FOR COPYING,
+ * DISTRIBUTION AND MODIFICATION
+ *
+ * 0. You just DO WHAT THE FUCK YOU WANT TO.
+ */
+package analysis;
+
+import java.io.FileInputStream;
+import java.io.FileNotFoundException;
+import java.io.InputStream;
+import java.util.List;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+
+/**
+ * This class obtains a text and returns the brands that are contained in this
+ * text.
+ *
+ * @author Maurice Laveaux
+ */
+public class BrandChecker {
+
+ /**
+ * @param filename The filename that contains all the brands.
+ */
+ public BrandChecker(final String filename) {
+ try {
+ readFile(filename);
+ } catch (FileNotFoundException ex) {
+ Logger.getLogger(BrandChecker.class.getName()).log(Level.SEVERE, null, ex);
+ }
+ }
+
+ /**
+ * Get the brands that are in some text.
+ *
+ * @param text Any valid text.
+ * @return The list of brands that are contained in this text or null.
+ */
+ public List<String> getBrands(String text) {
+
+
+
+ return null;
+ }
+
+ private void readFile(final String filename) throws FileNotFoundException {
+
+ InputStream inFile = new FileInputStream(filename);
+
+ }
+}
diff --git a/src/main/Analyzor.java b/src/main/Analyzor.java
index b7e1dc0..e7e26fe 100644
--- a/src/main/Analyzor.java
+++ b/src/main/Analyzor.java
@@ -12,16 +12,22 @@ import java.util.HashMap;
import java.util.Scanner;
/**
- * Analyze tweets with a lexicon.
+ * The sentiment analysis class that rates tweets based on a unigram and bigram
+ * set of weights.
*/
public class Analyzor {
- //maps for the lexicons
- HashMap<String, Double> unimap = new HashMap<>(); // Map for uni
- HashMap<String, Double> bimap = new HashMap<>(); // Map for bi
+ /**
+ * The map that matches single words to their weights.
+ */
+ private final HashMap<String, Double> unimap = new HashMap();
- //the resultset of the query or the import
- ResultSet data;
+ /**
+ * The map that matches word pairs to their weights.
+ */
+ private final HashMap<String, Double> bimap = new HashMap();
+
+ private ResultSet data;
private final Connection connection;
Analyzor(Connection connection) {
@@ -59,18 +65,26 @@ public class Analyzor {
}
}
- //query the database
- //fills the ResultSet data
- void query(String query) throws SQLException {
+ /**
+ * Executes a query that the analyzer can analyze.
+ *
+ * @param query The query string to execute.
+ * @throws SQLException When database connection isn't available.
+ */
+ public void query(String query) throws SQLException {
PreparedStatement statement;
//make a connection to the database and execute the query
statement = connection.prepareStatement(query);
data = statement.executeQuery();
}
- //analyzes the tweet on their positivity
- //this is just a base version
- void sentimentAnalysis(String query) throws SQLException, IOException {
+ /**
+ * Run a sentiment analysis and fill the database with the output.
+ *
+ * @throws SQLException
+ * @throws IOException
+ */
+ public void sentimentAnalysis(String query) throws SQLException, IOException {
query(query);
//read the lexicons
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());
- }
- }
}
diff --git a/src/main/Main.java b/src/main/Main.java
index 88b7a04..02673b2 100644
--- a/src/main/Main.java
+++ b/src/main/Main.java
@@ -1,17 +1,10 @@
package main;
import database.ConnectionBuilder;
-import java.io.File;
-import java.io.FileNotFoundException;
-import java.io.IOException;
import java.util.Arrays;
-import java.util.HashMap;
-import java.util.Scanner;
/**
* The main class containing the main method.
- *
- * @author Maurice Laveaux
*/
public class Main {
@@ -28,6 +21,7 @@ public class Main {
}
main.run();
}
+
private String[] leftover_params;
public Main(String[] args) {
@@ -36,6 +30,7 @@ public class Main {
.setUsername("twitter")
.setPassword("2IOC02")
.setDbName("twitter");
+
parseGlobalOptions(args);
}
@@ -77,8 +72,7 @@ public class Main {
private String getArg(String[] params, int index, String name) {
if (index >= params.length) {
- System.err.println("Missing argument for parameter " + name);
- System.exit(1);
+ throw new IllegalArgumentException("Missing argument for parameter " + name);
}
return params[index];
}