summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authors123188 <s123188@S123188.campus.tue.nl>2014-05-31 15:44:18 +0200
committers123188 <s123188@S123188.campus.tue.nl>2014-05-31 15:44:18 +0200
commita39323f583e1878d3cdafed8de99b4614dab7682 (patch)
tree9f7f481e3ad350f1fad51e65c82fc041a34568e7 /src
parentc5e39a20d29d7a7b9d516f0d4fcdbed2ef44e0a3 (diff)
downloadGoldfarmer-a39323f583e1878d3cdafed8de99b4614dab7682.tar.gz
made a method for the posnegVisualizer
Diffstat (limited to 'src')
-rw-r--r--src/main/Analyzor.java78
1 files changed, 71 insertions, 7 deletions
diff --git a/src/main/Analyzor.java b/src/main/Analyzor.java
index b896f62..89a8403 100644
--- a/src/main/Analyzor.java
+++ b/src/main/Analyzor.java
@@ -188,7 +188,7 @@ public class Analyzor {
while (data.next()) {
//get brand
- brand=data.getString("brand");
+ brand = data.getString("brand");
//make hashmap for each brand
if(!wordcloud.containsKey(brand)){
wordcloud.put(brand, new HashMap<String,Integer>());
@@ -216,7 +216,7 @@ public class Analyzor {
}
}
//print the words and their frequency in a csv file
- mapToCSV(wordcloud, "wordcloud.csv", "brand,word,count");
+ ssiMapToCSV(wordcloud, "wordcloud.csv", "brand,word,count");
}
//generate csv for disco from the query
@@ -284,8 +284,6 @@ public class Analyzor {
}
}
-
-
//hashmap timezone, brand, amount
HashMap<String, HashMap<String, Integer>> timeMap = new HashMap<>();
String timezone;
@@ -299,6 +297,7 @@ public class Analyzor {
timezone="other";
}
brand = data.getString("brand");
+
//if the timezone is already in the map
if(timeMap.containsKey(timezone)){
//if the brand for that timezone is already in the map
@@ -320,9 +319,55 @@ public class Analyzor {
}
}
-
//make the CSV out of the map
- mapToCSV(timeMap, "timezone.csv", "timezone,brand,count");
+ ssiMapToCSV(timeMap, "timezone.csv", "timezone,brand,count");
+ }
+
+ //gets the positivity of the tweets about a brand
+ //makes a csv file for posnegVisualizer
+ void posNeg(String query) throws SQLException, FileNotFoundException, UnsupportedEncodingException{
+ query(query);
+
+ String brand;
+ int rating;
+ int ratingInterval;
+
+ int intervalSize = 10;
+ //brand, ratingInterval, amount
+ HashMap<String, HashMap<Integer, Integer>> posnegMap = new HashMap<>();
+ /*
+ the rating interval is given by an integer, which is the result of the
+ tweets sentiment value divided by interval size rounded down.
+ This puts all data in boxes for the histogram.
+ */
+
+ while(data.next()){
+
+ brand = data.getString("brand");
+ rating = data.getInt("rating");
+ ratingInterval = rating/intervalSize;
+
+ //if the brand is already in the map
+ if(posnegMap.containsKey(brand)){
+ //if the brand for that brand is already in the map
+ if(posnegMap.get(brand).containsKey(ratingInterval)){
+ //increment the amount
+ posnegMap.get(brand).put(ratingInterval, posnegMap.get(brand).get(ratingInterval) + 1);
+ }
+ //if the brand for that brand is not yet in the map
+ else{
+ //make a new entry for that brand with amount = 1
+ posnegMap.get(brand).put(ratingInterval, 1);
+ }
+ }
+ //if the brand is not yet in the map
+ else{
+ //make a new hashmap for this map and fill it with the brand and the amount
+ posnegMap.put(brand, new HashMap<Integer, Integer>());
+ posnegMap.get(brand).put(ratingInterval, 1);
+ }
+ }
+ siiMapToCSV(posnegMap, "posneg.csv", "brand,ratingInterval,count");
}
//replaces punctuation so it will be splitted
@@ -347,7 +392,26 @@ public class Analyzor {
//prints a hashmap into a csv for a html application
//Hashmap<key1, HashMap<key2, value>> becomes key1, key2, value
//only for String, String, Integer
- void mapToCSV(HashMap<String, HashMap<String, Integer>> map, String fileName, String firstLine)
+ void ssiMapToCSV(HashMap<String, HashMap<String, Integer>> map, String fileName, String firstLine)
+ throws FileNotFoundException, UnsupportedEncodingException{
+
+ PrintWriter writer = new PrintWriter(fileName, "UTF-8");
+
+ writer.println(firstLine);
+
+ //loop over brands
+ for(Entry en : map.entrySet()){
+ //loop over words
+ for(Entry e : map.get(en.getKey()).entrySet()){
+ writer.println(en.getKey() + "," + e.getKey() + "," + e.getValue());
+ }
+ }
+
+ writer.close();
+ System.out.println("csv file made, please put it next to html file and run this");
+ }
+
+ void siiMapToCSV(HashMap<String, HashMap<Integer, Integer>> map, String fileName, String firstLine)
throws FileNotFoundException, UnsupportedEncodingException{
PrintWriter writer = new PrintWriter(fileName, "UTF-8");