From 8d0aa5d81d33167ac4449e68b172a5402e815156 Mon Sep 17 00:00:00 2001 From: Peter Wu Date: Thu, 15 May 2014 16:12:01 +0200 Subject: Fixups --- src/main/Analyzor.java | 28 +++++++++++++--------------- src/main/FarmShell.java | 4 ++-- 2 files changed, 15 insertions(+), 17 deletions(-) (limited to 'src') diff --git a/src/main/Analyzor.java b/src/main/Analyzor.java index 00e3442..b7e1dc0 100644 --- a/src/main/Analyzor.java +++ b/src/main/Analyzor.java @@ -71,7 +71,6 @@ public class Analyzor { //analyzes the tweet on their positivity //this is just a base version void sentimentAnalysis(String query) throws SQLException, IOException { - query(query); //read the lexicons @@ -91,7 +90,7 @@ public class Analyzor { while (data.next()) { //get the text text = data.getString("text"); - text = replacePunct(text); + text = splitPunctToWords(text); // test is the tweet text you are going to analyze String[] words = text.split("\\s+"); // text splitted into separate words double positiverate = 0; // positive rating @@ -123,36 +122,35 @@ public class Analyzor { //makes a wordcloud of the tweets in the ResultSet data void makeWordCloud(String query) throws SQLException { - + query(query); //go to the start of the ResultSet data if (data == null) { System.err.println("data is empty, try querying first"); return; } - + //make the hashmap with the words and their frequency HashMap wordcloud = new HashMap<>(); - + String text; String[] words; Integer value; - - while(data.next()){ + + while (data.next()) { //get the text text = data.getString("text"); //remove punctuation, convert to lowercase and split on words text = removePunct(text); text = text.toLowerCase(); words = text.split("\\s+"); - + //count the words - for(String word : words){ + for (String word : words) { value = wordcloud.get(word); - if(value == null){ + if (value == null) { wordcloud.put(word, 1); - } - else{ + } else { wordcloud.put(word, value++); } } @@ -161,17 +159,17 @@ public class Analyzor { //replaces punctuation so it will be splitted //also removes urls - private String replacePunct(String text) { + private String splitPunctToWords(String text) { text = text.replaceAll("https?://\\S*", ""); text = text.replaceAll("[!?):;\"']", " $0"); text = text.replaceAll("[.,-](\\s|$)", " $0"); text = text.replaceAll("\\s[(\"']", "$0 "); return text; } - + //removes punctuation //also removes urls - private String removePunct(String text){ + private String removePunct(String text) { text = text.replaceAll("https?://\\S*", ""); text = text.replaceAll("[.,!?()-:;\"']", " "); return text; diff --git a/src/main/FarmShell.java b/src/main/FarmShell.java index a8e8a8e..cf15ff3 100644 --- a/src/main/FarmShell.java +++ b/src/main/FarmShell.java @@ -95,7 +95,7 @@ public class FarmShell { } catch (NoSuchElementException ex) { // thrown by the "exit" command to signal exit return false; - } catch (SQLException ex){ + } catch (SQLException ex) { System.err.println("such " + ex); } // another satisfied customer, next! @@ -165,7 +165,7 @@ public class FarmShell { getAnalyzor().sentimentAnalysis(params[0]); break; case wordcloud: - analyzor.makeWordCloud(params[0]); + getAnalyzor().makeWordCloud(params[0]); break; case help: for (String line : HELP) { -- cgit v1.2.1