Map<String,Double> urlCategoryScores = new HashMap<String,Double>();
Map<String,Integer> urlCategoryCounts = new HashMap<String,Integer>();
for(SimpleTweet tweet : tweets) {
//Handle tweet content classification
AlchemyClassification textClassification = AlchemyClassifier.classifyText(tweet.getText());
if(textClassification == null) {
System.err.println("Daily Transaction Limit has been reached (or a null classification was given weirdly)");
return false;
}
writeOutTweets.print(tweet.getTweetID()+","+textClassification.getCategory()+","+textClassification.getScore());
System.err.println("JUST WROTE TWEEET OUT");
if(textCategoryScores.containsKey(textClassification.getCategory())) {
//Add the new value, since the key already exists
textCategoryScores.put(textClassification.getCategory(), textCategoryScores.get(textClassification.getCategory()) + textClassification.getScore());
textCategoryCounts.put(textClassification.getCategory(), textCategoryCounts.get(textClassification.getCategory()) + 1);
} else {
//Insert the category into the map
textCategoryScores.put(textClassification.getCategory(), textClassification.getScore());
textCategoryCounts.put(textClassification.getCategory(), 1);
}
//Handle URL classification
for(String url : tweet.getUrls()) {
AlchemyClassification urlClassification = AlchemyClassifier.classifyURL(url);
if(urlClassification == null) {
System.err.println("Daily Transaction Limit has been reached (or a null classification was given weirdly)");
return false;
}
writeOutTweets.print(","+urlClassification.getCategory()+","+urlClassification.getScore());
if(urlCategoryScores.containsKey(urlClassification.getCategory())) {
//Add the new value, since the key already exists
urlCategoryScores.put(urlClassification.getCategory(), urlCategoryScores.get(urlClassification.getCategory()) + urlClassification.getScore());
urlCategoryCounts.put(urlClassification.getCategory(), urlCategoryCounts.get(urlClassification.getCategory()) + 1);
} else {
//Insert the category into the map
urlCategoryScores.put(urlClassification.getCategory(), urlClassification.getScore());
urlCategoryCounts.put(urlClassification.getCategory(), 1);
}
}
//writeOutTweets.println();
}