From 10a32f00d3bbe4b73adccdd522d4925e9e494582 Mon Sep 17 00:00:00 2001 From: unknown Date: Mon, 19 May 2014 14:29:26 +0200 Subject: wordcloud now makes csv files for wordcloud.html --- src/main/Analyzor.java | 26 ++++++++++++++------------ 1 file changed, 14 insertions(+), 12 deletions(-) (limited to 'src') 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 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 -- cgit v1.2.1