diff options
author | unknown <s123188@S123188.campus.tue.nl> | 2014-05-19 14:29:26 +0200 |
---|---|---|
committer | unknown <s123188@S123188.campus.tue.nl> | 2014-05-19 14:29:26 +0200 |
commit | 10a32f00d3bbe4b73adccdd522d4925e9e494582 (patch) | |
tree | 21125b8fcb95835976957cba421e7ef88b85faf5 /src/main/Analyzor.java | |
parent | 6bf5bfff47b085e7aec22aee04c897f52e79c557 (diff) | |
download | Goldfarmer-10a32f00d3bbe4b73adccdd522d4925e9e494582.tar.gz |
wordcloud now makes csv files for wordcloud.html
Diffstat (limited to 'src/main/Analyzor.java')
-rw-r--r-- | src/main/Analyzor.java | 26 |
1 files changed, 14 insertions, 12 deletions
diff --git a/src/main/Analyzor.java b/src/main/Analyzor.java index 678887f..914fced 100644 --- a/src/main/Analyzor.java +++ b/src/main/Analyzor.java @@ -13,6 +13,7 @@ import java.sql.PreparedStatement; import java.sql.ResultSet; import java.sql.SQLException; import java.util.HashMap; +import java.util.Map.Entry; import java.util.Scanner; /** @@ -173,12 +174,7 @@ public class Analyzor { String text; String[] words; - Integer value; - String tweetid; - - PrintWriter writer = new PrintWriter("wordcloud.csv", "UTF-8"); - //print the first row - writer.println("tweetid, word"); + HashMap<String, Integer> wordcloud = new HashMap<>(); while (data.next()) { //get the text @@ -187,19 +183,25 @@ public class Analyzor { text = removePunct(text); text = text.toLowerCase(); words = text.split("\\s+"); - //we use the tweetid as case id - tweetid = Long.toString(data.getLong("tweetid")); for (String word : words) { - writer.println(tweetid + ", " + word); + if(wordcloud.containsKey(word)){ + wordcloud.put(word, wordcloud.get(word)); + } + else{ + wordcloud.put(word, 1); + } } } - //print it in a csv file to put in disco + //print the words and their frequency in a csv file + PrintWriter writer = new PrintWriter("wordcloud.csv", "UTF-8"); - //print the first row + for(Entry e : wordcloud.entrySet()){ + writer.print(e.getKey() + ", " + e.getValue()); + } - //print the values writer.close(); + System.out.println("csv file made, please put it next to wordcloud.html and run this"); } //generate csv for disco from the query |