summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorPeter Wu <peter@lekensteyn.nl>2014-05-15 16:12:01 +0200
committerPeter Wu <peter@lekensteyn.nl>2014-05-15 16:12:01 +0200
commit8d0aa5d81d33167ac4449e68b172a5402e815156 (patch)
treefd4cc3066eac98afdd2f75b8f8ba6424026e3e43 /src
parent879deb56f0666e66e0075df510f6a779373243d5 (diff)
downloadGoldfarmer-8d0aa5d81d33167ac4449e68b172a5402e815156.tar.gz
Fixups
Diffstat (limited to 'src')
-rw-r--r--src/main/Analyzor.java28
-rw-r--r--src/main/FarmShell.java4
2 files changed, 15 insertions, 17 deletions
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<String, Integer> 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) {