summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/main/CommandParser.java113
-rw-r--r--src/main/CommandQueue.java39
-rw-r--r--src/main/ICommand.java14
-rw-r--r--src/main/RequestCommand.java118
-rw-r--r--src/utils/Tags.java52
-rw-r--r--src/utils/TextUtils.java212
6 files changed, 0 insertions, 548 deletions
diff --git a/src/main/CommandParser.java b/src/main/CommandParser.java
deleted file mode 100644
index 97f01fc..0000000
--- a/src/main/CommandParser.java
+++ /dev/null
@@ -1,113 +0,0 @@
-package main;
-
-import java.lang.reflect.Array;
-import java.util.Arrays;
-import mining.TwitterApi;
-
-/**
- * Class that creates executable commands from input.
- * @author Maurice Laveaux
- */
-public class CommandParser {
- // the queue of commands.
- private final CommandQueue m_queue;
-
- // the twitter api.
- private final TwitterApi m_api;
-
- /**
- * Default constructor, requires the TwitterApi
- * @param queue A valid CommandQueue that can execute requests.
- * @param api the TwitterApi to use for the commands.
- */
- public CommandParser(CommandQueue queue, TwitterApi api) {
- m_queue = queue;
- m_api = api;
- }
-
- /**
- * Parses a string and creates an executable command for it.
- * @param command The string to parse the command from.
- */
- final public void parse(final String command) {
- // split the code for each space ' '.
- String[] seperated = command.split(" ");
-
- // parse the seperated code for each argument.
- parse(seperated);
- }
-
- /**
- * Parses a string and creates an executable command for it.
- * @param seperated A space seperated string for each argument.
- */
- final public void parse(final String[] seperated) {
- if (seperated.length == 0) {
- return;
- }
-
- // The main command.
- String command = seperated[0];
-
- // the first command issued
- switch (command) {
- case "help":
- showFullHelp();
- return;
- case "-h":
- showFullHelp();
- return;
- case "quit":
- // TODO: implement less hack way of quiting the program.
- System.exit(0);
- default:
- break;
- }
-
- // there is a command without errors but it was not switched.
- if (seperated.length == 1) {
- showUsageHelp(command);
- return;
- }
-
- // commands with multiple parameters
- String[] extra = Arrays.copyOfRange(seperated, 1, seperated.length);
-
- if (seperated.length < 3) {
- showUsageHelp(extra.toString());
- return;
- }
-
- String[] parameters = Arrays.copyOfRange(extra, 1, extra.length);
-
- try {
- switch (command) {
- case "get":
- m_queue.add(new RequestCommand(m_api, extra[0], parameters));
- return;
- }
- }
- catch (IllegalArgumentException ex) {
- System.out.println(ex);
- }
- }
-
- /** Show the basic usage help in console */
- private void showUsageHelp(String unknown) {
- System.out.println("Unknown argument: \"" + unknown + "\".");
- System.out.println(" Use help, -h for more help.");
- }
-
- /** Show the full manual page in the console */
- private void showFullHelp() {
- System.out.println("Usage: [command] [arguments], see below for options.");
-
- System.out.println("\n command:");
- System.out.println(" set, use the twitter Search/REST API.");
- System.out.println(" stream, use the twitter Stream API.");
-
- System.out.println("\n arguments:");
- System.out.println(" <main>, the information to get from api.twitter.com.");
- System.out.println(" <json_member>, any number of arguments for the information");
- }
-} \ No newline at end of file
diff --git a/src/main/CommandQueue.java b/src/main/CommandQueue.java
deleted file mode 100644
index b3fde3e..0000000
--- a/src/main/CommandQueue.java
+++ /dev/null
@@ -1,39 +0,0 @@
-package main;
-
-import java.util.LinkedList;
-import java.util.Queue;
-
-/**
- * The queue of commands to be executed every step.
- *
- * @author Maurice Laveaux
- */
-public class CommandQueue {
-
- // the list of commands executed in this order.
- private final Queue<ICommand> m_commands;
-
- public CommandQueue() {
- m_commands = new LinkedList();
- }
-
- /**
- * Add another command to the last position in the queue.
- *
- * @param command Any command that can be executed.
- */
- public void add(ICommand command) {
- m_commands.offer(command);
- }
-
- /**
- * Execute every command that is in the queue.
- */
- public void executeAll() {
- while (!m_commands.isEmpty()) {
- ICommand command = m_commands.poll();
-
- command.execute();
- }
- }
-}
diff --git a/src/main/ICommand.java b/src/main/ICommand.java
deleted file mode 100644
index 14419a2..0000000
--- a/src/main/ICommand.java
+++ /dev/null
@@ -1,14 +0,0 @@
-package main;
-
-/**
- * The standard interface for any command
- *
- * @author Maurice Laveaux
- */
-public interface ICommand {
-
- /**
- * Execute all the steps to complete this Command.
- */
- public void execute();
-}
diff --git a/src/main/RequestCommand.java b/src/main/RequestCommand.java
deleted file mode 100644
index 42ff41b..0000000
--- a/src/main/RequestCommand.java
+++ /dev/null
@@ -1,118 +0,0 @@
-package main;
-
-import java.io.File;
-import java.io.FileWriter;
-import java.io.IOException;
-import java.util.ArrayList;
-import mining.TwitterApi;
-import mining.TwitterApi.Builder;
-import org.json.JSONException;
-import org.json.JSONObject;
-
-/**
- * Basic contained class for a Pair, because Java doesn't provide this.
- *
- * @author Maurice Laveaux
- */
-class Parameter {
-
- public Parameter(String variable, String value) {
- this.variable = variable;
- this.value = value;
- }
-
- public String variable;
- public String value;
-}
-
-/**
- * A single request/response command that executes once.
- *
- * @author Maurice Laveaux
- */
-public class RequestCommand implements ICommand {
-
- /**
- * The api to execute requests on
- */
- private final TwitterApi m_api;
-
- private final String m_command;
-
- /**
- * The list of parameters that are executed
- */
- private final ArrayList<Parameter> m_parameters;
-
- /**
- * Contruct a RequestCommand that executes the request and writes the
- * results into a file.
- *
- * @param api the main twitter api.
- * @param command the command of the twitter api f.e. users/show.
- * @param parameters the parameters for the executed command.
- */
- public RequestCommand(TwitterApi api, String command, String[] parameters) {
- m_api = api;
- m_command = command;
-
- m_parameters = new ArrayList();
-
- if (parameters.length < 1) {
- throw new IllegalArgumentException("Not enough parameters specified.");
- }
-
- for (String param : parameters) {
- // parse the parameter to a variable with a value.
- m_parameters.add(parseParam(param));
- }
- }
-
- @Override
- public void execute() {
- try {
- // create the building object with the command.
- Builder builder = m_api.build(m_command);
-
- // add every parameter to the builder.
- for (Parameter param : m_parameters) {
- builder = builder.param(param.variable, param.value);
- }
-
- JSONObject result = builder.request();
-
- // TODO: add the results to the main database.
- // For now write to a file
- File file = new File("database.txt");
-
- FileWriter writer = new FileWriter(file, true);
-
- writer.write("\n\r" + result.toString());
- writer.flush();
-
- System.out.println(result.toString(4));
- } catch (JSONException ex) {
- /* cannot happen */
- throw new RuntimeException(ex);
- } catch (IOException ex) {
- // TODO: when ratelimit reached, add event back to queue.
- throw new RuntimeException(ex);
- }
- }
-
- /**
- * Parses the input string to a parameter.
- *
- * @param input A single line in the form variable=value.
- * @return A pair of strings for variable and value.
- */
- private Parameter parseParam(final String input) {
- String[] seperated = input.split("=");
-
- if (seperated.length < 2) {
- throw new IllegalArgumentException("parameter did not contain <variable>=<value>.");
- }
-
- return new Parameter(seperated[0], seperated[1]);
- }
-}
diff --git a/src/utils/Tags.java b/src/utils/Tags.java
deleted file mode 100644
index f1a5b56..0000000
--- a/src/utils/Tags.java
+++ /dev/null
@@ -1,52 +0,0 @@
-/*
- * To change this template, choose Tools | Templates
- * and open the template in the editor.
- */
-
-package utils;
-
-/**
- *
- * @author skumar34
- */
-public class Tags implements Comparable{
- public String key;
- public double value;
-
- public Tags()
- {
-
- }
-
- public Tags(String key, double value) {
- this.key = key;
- this.value = value;
- }
- public int compareTo(Object obj)
- {
- Tags tempObject=new Tags();
- tempObject=(Tags) obj;
- if(this.value>tempObject.value)
- return 1;
- if(this.value<tempObject.value)
- return -1;
- else
- return 0;
- }
-
- public String getKey() {
- return key;
- }
-
- public void setKey(String key) {
- this.key = key;
- }
-
- public double getValue() {
- return value;
- }
-
- public void setValue(double value) {
- this.value = value;
- }
-}
diff --git a/src/utils/TextUtils.java b/src/utils/TextUtils.java
deleted file mode 100644
index 764ce11..0000000
--- a/src/utils/TextUtils.java
+++ /dev/null
@@ -1,212 +0,0 @@
-/* TweetTracker. Copyright (c) Arizona Board of Regents on behalf of Arizona State University
- * @author shamanth
- */
-package utils;
-
-import java.io.BufferedReader;
-import java.io.FileInputStream;
-import java.io.FileNotFoundException;
-import java.io.IOException;
-import java.io.InputStreamReader;
-import java.io.UnsupportedEncodingException;
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.HashSet;
-import java.util.logging.Level;
-import java.util.logging.Logger;
-import java.util.regex.Matcher;
-import java.util.regex.Pattern;
-
-public class TextUtils
-{
- //holds a list of stop words to be removed when generating word clouds etc.
- HashSet<String> STOPWORDS = new HashSet<String>();
-
- String SEPARATOR = " ";
-
- /**
- * Loads the stop words from a file onto a collection. for use by all methods in this class
- * @param filename
- */
- public void LoadStopWords(String filename)
- {
- if(!filename.isEmpty())
- {
-
- BufferedReader bread = null;
- try {
- bread = new BufferedReader(new InputStreamReader(new FileInputStream(filename), "UTF8"));
- String temp = "";
- try {
- while ((temp = bread.readLine()) != null) {
- if (!temp.isEmpty()) {
- String[] stwords = temp.split(",");
- for (String t : stwords) {
- t = t.toLowerCase();
- if (!STOPWORDS.contains(t)) {
- STOPWORDS.add(t);
- }
- }
- }
- }
- } catch (IOException ex) {
- Logger.getLogger(TextUtils.class.getName()).log(Level.SEVERE, null, ex);
- }
- } catch (UnsupportedEncodingException ex) {
- Logger.getLogger(TextUtils.class.getName()).log(Level.SEVERE, null, ex);
- } catch (FileNotFoundException ex) {
- Logger.getLogger(TextUtils.class.getName()).log(Level.SEVERE, null, ex);
- } finally {
- try {
- bread.close();
- } catch (IOException ex) {
- Logger.getLogger(TextUtils.class.getName()).log(Level.SEVERE, null, ex);
- }
- }
- }
- }
-
- /**
- * Converts a tweet/text into individual words/tokens. All stopwords are removed and the list also does not contain hyperlinks.
- * Splitting is performed on space.
- * @param text
- * @param ignoreHashtags
- * @param ignoreUsernames
- * @return a list of words contained in text
- */
- public HashMap<String,Integer> TokenizeText(String text, boolean ignoreHashtags, boolean ignoreUsernames)
- {
- String[] tokens = text.split(SEPARATOR);
- HashMap<String,Integer> words = new HashMap<String,Integer>();
- for(String token:tokens)
- {
- token = token.replaceAll("\"|'|\\.||;|,", "");
- if(token.isEmpty()||token.length()<=2||STOPWORDS.contains(token)||token.startsWith("&")||token.startsWith("http"))
- {
- continue;
- }
- else
- {
- if(ignoreHashtags)
- {
- if(token.startsWith("#"))
- {
- continue;
- }
- }
- if(ignoreUsernames)
- {
- if(token.startsWith("@"))
- {
- continue;
- }
- }
- if(!words.containsKey(token))
- {
- words.put(token,1);
- }
- else
- {
- words.put(token, words.get(token)+1);
- }
- }
- }
- return words;
- }
-
- /**
- * Checks whether the tweet is a retweet based on the presence of the RT pattern as the start of the text. Expects the tweet text to be in lowercase.
- * @param text
- * @return
- */
- public static boolean IsTweetRT(String text)
- {
- Pattern p = Pattern.compile("^rt @[a-z_0-9]+");
- Matcher m = p.matcher(text);
- if(m.find())
- {
- return true;
- }
- return false;
- }
-
- /**
- * Checks whether the text contains a hyperlink in the text
- * @param text
- * @return
- */
- public static boolean ContainsURL(String text)
- {
- Pattern urlpat = Pattern.compile("https?://[a-zA-Z0-9\\./]+");
- Matcher urlmat = urlpat.matcher(text);
- if(urlmat.find())
- {
- return true;
- }
- else
- return false;
- }
-
- /**
- * extracts and returns a list of hashtags from the text
- * @param text
- * @return
- */
- public static ArrayList<String> GetHashTags(String text)
- {
- Pattern p = Pattern.compile("#[a-zA-Z0-9]+");
- Matcher mat = p.matcher(text);
- ArrayList<String> tags = new ArrayList<String>();
- while(mat.find())
- {
- String tag = text.substring(mat.start(),mat.end());
- if(!tags.contains(tag.toLowerCase()))
- {
- tags.add(tag.toLowerCase());
- }
- }
- return tags;
- }
-
- /**
- * Removes LF and CR from the text as well as any quotes and backslashes
- * @param text
- * @return
- */
- public static String GetCleanText(String text)
- {
- text = text.replaceAll("'|\"|&quot;", "");
- text = text.replaceAll("\\\\", "");
- text = text.replaceAll("\r\n|\n|\r", " ");
- text = text.trim();
- return text;
- }
-
- /**
- * Removes all patterns that correspond to Retweeted status leaving only original text
- * @param tweet
- * @return
- */
- public static String RemoveRTElements(String tweet)
- {
- String text = tweet.replaceAll("rt @[a-z_A-Z0-9]+", " ");
- text = text.replaceAll("RT @[a-z_A-Z0-9]+", " ");
- text = text.replaceAll(":","");
- return text.trim();
- }
-
- /**
- * Removes all hashtags, URLs, and usernames from the tweet text
- * @param tweet
- * @return
- */
- public static String RemoveTwitterElements(String tweet)
- {
- String temptweet = tweet.replaceAll("#[a-zA-Z_0-9]+", "");
- temptweet = temptweet.replaceAll("https?://[a-zA-Z0-9\\./]+", "");
- temptweet = temptweet.replaceAll("@[a-zA-Z_0-9]+", "");
- temptweet = temptweet.replaceAll("[:?\\.;<>()]", "");
- return temptweet;
- }
-
-}