diff options
-rw-r--r-- | src/main/Analyzor.java | 34 |
1 files changed, 18 insertions, 16 deletions
diff --git a/src/main/Analyzor.java b/src/main/Analyzor.java index b493a33..22ea6ec 100644 --- a/src/main/Analyzor.java +++ b/src/main/Analyzor.java @@ -12,9 +12,9 @@ import java.sql.Connection; import java.sql.PreparedStatement; import java.sql.ResultSet; import java.sql.SQLException; -import java.util.ArrayList; -import java.util.HashMap; import java.util.List; +import java.util.HashMap; +import java.util.Map.Entry; import java.util.Scanner; /** @@ -180,12 +180,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 @@ -194,18 +189,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 first row - //print the values + //print the words and their frequency in a csv file + PrintWriter writer = new PrintWriter("wordcloud.csv", "UTF-8"); + + for(Entry e : wordcloud.entrySet()){ + writer.print(e.getKey() + ", " + e.getValue()); + } + 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 |