diff --git a/2_Text_and_Archive/Code/TwitterPull/TwitterPull.pde b/2_Text_and_Archive/Code/TwitterPull/TwitterPull.pde index 5f8fdf7..446905f 100644 --- a/2_Text_and_Archive/Code/TwitterPull/TwitterPull.pde +++ b/2_Text_and_Archive/Code/TwitterPull/TwitterPull.pde @@ -23,7 +23,7 @@ PrintWriter writer; boolean tweeted = false; //This is the phrase we're looking for -String phrase = "ukraine"; +String phrase = "hong kong"; //This is how many tweets we're collecting int max = 1000; //counter for Tweets @@ -37,10 +37,10 @@ void setup() { //Initiate a configuration builder with our OAuth info. ConfigurationBuilder cb = new ConfigurationBuilder(); - cb.setOAuthConsumerKey("KEY"); - cb.setOAuthConsumerSecret("SECRET"); - cb.setOAuthAccessToken("KEY"); - cb.setOAuthAccessTokenSecret("SECRET"); + cb.setOAuthConsumerKey("JBFDbODYXiRFpJWerIJCV2g3y"); + cb.setOAuthConsumerSecret("4vd4xfhTP4T6QzR0xTUMtCbmse2sopIsT6YlFrg2sNthouYakh"); + cb.setOAuthAccessToken("17013577-3kqdwNqWmH7eiIn1MuG7FNByCYwOTAMGbEz1pOFh0"); + cb.setOAuthAccessTokenSecret("tcX7oWYF7oUpTNM5M12M8Fg3e1YDxB1PXL4xq5Ube1sZq"); //Request a Twitter Stream TwitterStream twitterStream = new TwitterStreamFactory(cb.build()).getInstance(); diff --git a/2_Text_and_Archive/Code/WordCounts/WordCounts.pde b/2_Text_and_Archive/Code/WordCounts/WordCounts.pde index 1427c87..a895e00 100644 --- a/2_Text_and_Archive/Code/WordCounts/WordCounts.pde +++ b/2_Text_and_Archive/Code/WordCounts/WordCounts.pde @@ -2,18 +2,78 @@ import rita.*; String dataPath = "../../../data/"; +HashMap stopList = new HashMap(); + +IntDict counter = new IntDict(); +float left = 0; + +PFont label; void setup() { size(1280,720); + makeStopList("stop.txt"); countWords("mobydick.txt"); + + label = createFont("Helvetica", 120); + textFont(label); + } void draw() { + background(0); + float xOffset = map(mouseX, 0, width, 0, left - width); + + pushMatrix(); + translate(-xOffset, 0); + //println(xOffset); + renderWords(); + popMatrix(); + } +void renderWords() { + randomSeed(1); + String[] theKeys = counter.keyArray(); + + left = 0; + for (int i = 0; i < 100; i++) { + String word = theKeys[i]; + int count = counter.get(word); + float x = i * 50; + float y = height/2; + float s = sqrt(count) * 5; + + + fill(255,100); + textSize(s); + + float w = textWidth(word); + + text(word, 0, y); + fill(255); + textSize(16); + text(count, 0, y + 20); + + //rotate(map(mouseX, 0, width, 0, 1)); + translate(w,0); + left += w; + } +} + +void makeStopList(String url) { + String[] stops = loadStrings(dataPath + url); + for(String s:stops) { + stopList.put(s,s); + } +} + +boolean checkStop(String word) { + return(stopList.containsKey(word.toLowerCase())); +} + void countWords(String url) { - IntDict counter = new IntDict(); + String[] rows = loadStrings(dataPath + url); String text = join(rows,""); @@ -22,16 +82,15 @@ void countWords(String url) { for (String s:sentences) { String[] words = RiTa.tokenize(RiTa.stripPunctuation(s)); for (String w:words) { - counter.add(w.toLowerCase(), 1); + //counter.add(w.toLowerCase(), 1); + if(!checkStop(w)) counter.increment(w.toLowerCase()); } } counter.sortValuesReverse(); - String[] theKeys = counter.keyArray(); + - for (int i = 0; i < 100; i++) { - println(theKeys[i]); - } + }