diff options
author | Peter Wu <peter@lekensteyn.nl> | 2014-05-26 12:03:33 +0200 |
---|---|---|
committer | Peter Wu <peter@lekensteyn.nl> | 2014-05-26 12:03:33 +0200 |
commit | 00baf4ffc86dac7b723c4fc3d2c963d1fa84729b (patch) | |
tree | 6e26c2215aa398f6893ed3bc5148e15c8108ba2b /src/main/Analyzor.java | |
parent | 7df2ae452a984cb12986b33034557476cb4a1536 (diff) | |
download | Goldfarmer-00baf4ffc86dac7b723c4fc3d2c963d1fa84729b.tar.gz |
Formatting, drop useless license header
Sam Hocevar doesn't know us nor does he have copyright about this
work...
Diffstat (limited to 'src/main/Analyzor.java')
-rw-r--r-- | src/main/Analyzor.java | 57 |
1 files changed, 27 insertions, 30 deletions
diff --git a/src/main/Analyzor.java b/src/main/Analyzor.java index 5385a79..ffd9a5b 100644 --- a/src/main/Analyzor.java +++ b/src/main/Analyzor.java @@ -188,14 +188,14 @@ public class Analyzor { String text; String brand; String[] words; - HashMap<String,HashMap<String, Integer>> wordcloud = new HashMap<>(); + HashMap<String, HashMap<String, Integer>> wordcloud = new HashMap<>(); 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>()); + if (!wordcloud.containsKey(brand)) { + wordcloud.put(brand, new HashMap<String, Integer>()); } //get the text text = data.getString("text"); @@ -206,15 +206,14 @@ public class Analyzor { //for all words for (String word : words) { //if it is empty, a space or a stripe, skip it - if(word.equals("") || word.equals(" ") || word.equals("-")){ + if (word.equals("") || word.equals(" ") || word.equals("-")) { continue; } //if the word is already in the map, increment the amount - if(wordcloud.get(brand).containsKey(word)){ + if (wordcloud.get(brand).containsKey(word)) { wordcloud.get(brand).put(word, wordcloud.get(brand).get(word) + 1); - } - //if the word is not already in the map, make an entry with amount = 1 - else{ + } //if the word is not already in the map, make an entry with amount = 1 + else { wordcloud.get(brand).put(word, 1); } } @@ -275,31 +274,29 @@ public class Analyzor { //gets the amount of users that tweet about a brand in a timezone //makes a csv file timezone, brand, amount - public void timezone(String query) throws SQLException, FileNotFoundException, UnsupportedEncodingException{ + public void timezone(String query) throws SQLException, FileNotFoundException, UnsupportedEncodingException { query(query); //hashmap timezone, brand, amount HashMap<String, HashMap<String, Integer>> timeMap = new HashMap<>(); String timezone; String brand; - - while(data.next()){ + + while (data.next()) { timezone = data.getString("timezone"); brand = data.getString("brand"); //if the timezone is already in the map - if(timeMap.containsKey(timezone)){ + if (timeMap.containsKey(timezone)) { //if the brand for that timezone is already in the map - if(timeMap.get(timezone).containsKey(brand)){ + if (timeMap.get(timezone).containsKey(brand)) { //increment the amount timeMap.get(timezone).put(brand, timeMap.get(timezone).get(brand) + 1); - } - //if the brand for that timezone is not yet in the map - else{ + } //if the brand for that timezone is not yet in the map + else { //make a new entry for that brand with amount = 1 timeMap.get(timezone).put(brand, 1); } - } - //if the timezone is not yet in the map - else{ + } //if the timezone is not yet in the map + else { //make a new hashmap for this map and fill it with the brand and the amount timeMap.put(timezone, new HashMap<String, Integer>()); timeMap.get(timezone).put(brand, 1); @@ -308,7 +305,7 @@ public class Analyzor { //make the CSV out of the map mapToCSV(timeMap, "timezone.csv", "timezone,brand,count"); } - + //replaces punctuation so it will be splitted //also removes urls private String splitPunctToWords(String text) { @@ -327,25 +324,25 @@ public class Analyzor { text = text.replaceAll("[^a-zA-Z0-9#_-]", " "); return text; } - + //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) - throws FileNotFoundException, UnsupportedEncodingException{ - + void mapToCSV(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()){ + for (Entry en : map.entrySet()) { //loop over words - for(Entry e : map.get(en.getKey()).entrySet()){ + 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"); } |