Skip to content

Commit

Permalink
Class 4.
Browse files Browse the repository at this point in the history
Former-commit-id: 01e669b2b829499fb05f6d874f45ec570eeb2304 [formerly 01e669b2b829499fb05f6d874f45ec570eeb2304 [formerly 956ba8a]]
Former-commit-id: c4f9379
Former-commit-id: 59e4564
  • Loading branch information
blprnt committed Sep 29, 2014
1 parent 54ca4af commit 31604dd
Show file tree
Hide file tree
Showing 2 changed files with 70 additions and 11 deletions.
10 changes: 5 additions & 5 deletions 2_Text_and_Archive/Code/TwitterPull/TwitterPull.pde
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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();
Expand Down
71 changes: 65 additions & 6 deletions 2_Text_and_Archive/Code/WordCounts/WordCounts.pde
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,78 @@
import rita.*;

String dataPath = "../../../data/";
HashMap<String, String> 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,"");
Expand All @@ -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]);
}

}


0 comments on commit 31604dd

Please sign in to comment.