Skip to content

Commit

Permalink
Incorporates the Location Detector class
Browse files Browse the repository at this point in the history
  • Loading branch information
syfantid committed May 11, 2016
1 parent 6bd267c commit 7939c4d
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 6 deletions.
24 changes: 21 additions & 3 deletions src/analytics/AnalyticsExtractor.java
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,25 @@ private void getTwitterMentionFrequencies() {
* Gets the location frequencies in collected tweets and Youtube comments
*/
private void getLocationFrequencies() {
writeToTagcloudFile(calculateFrequenciesSimple("geo","twitter"),"location_frequencies_twitter.txt");
writeToTagcloudFile(calculateFrequenciesSimple("location","youtube"),"location_frequencies_youtube.txt");
writeToTagcloudFile(getCountriesFrequencies(calculateFrequenciesSimple("geo","twitter")),"location_frequencies_twitter.txt");
writeToTagcloudFile(getCountriesFrequencies(calculateFrequenciesSimple("location","youtube")),"location_frequencies_youtube.txt");
}

private HashMap<String,Integer> getCountriesFrequencies(HashMap<String,Integer> locations) {
HashMap<String, Integer> countriesFrequencies = new HashMap<>();
for(String location : locations.keySet()) {
String city = "";
if(location.contains(",")) {
city = location.substring(0, location.indexOf(",")).replaceAll(" ", "_");
}
city = city.replaceAll(" ","_");
String country = LocationDetector.getCountryOf(city);
if(!country.isEmpty()) {
countriesFrequencies.putIfAbsent(country, 0);
countriesFrequencies.computeIfPresent(country, (k, v) -> v + 1);
}
}
return countriesFrequencies;
}

/**
Expand All @@ -67,6 +84,7 @@ private void getYoutubeUsersFrequencies() {
writeToTagcloudFile(calculateFrequenciesSimple("authorID","youtube"),"user_frequencies_youtube.txt");
}


/**
* Calculates frequencies of field by hashing, without preprocessing
* @param field The field, which frequency is counted
Expand Down Expand Up @@ -139,7 +157,7 @@ private void writeToTagcloudFile(HashMap<String,Integer> map, String filename) {
try (Writer writer = new BufferedWriter(new OutputStreamWriter(
new FileOutputStream(path), "utf-8"))) {
for(String s : map.keySet()) {
String key = s.replace(", ",";");
String key = s.replace(", ",";"); // If there are commas in the initial key String
writer.write(key + " , " + map.get(s));
writer.write(System.lineSeparator());
}
Expand Down
6 changes: 3 additions & 3 deletions src/combiner/Combiner.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ public static void main(String[] args) throws JSONException, IOException {

if(args != null) {
// Collect Youtube comments and insert them to DB
YoutubeExporter.main(args);
Preprocessor.preprocessComments(args[4].split("=")[1], fc);
/*YoutubeExporter.main(args);
Preprocessor.preprocessComments(args[4].split("=")[1], fc);*/


// Collect tweets and insert them to DB
Expand All @@ -42,7 +42,7 @@ public static void main(String[] args) throws JSONException, IOException {

if(args.length >= 5) {
analyticsExtractor = new AnalyticsExtractor(args[4].split("=")[1]);
analyticsExtractor.analyze();
//analyticsExtractor.analyze();
}
}

Expand Down

0 comments on commit 7939c4d

Please sign in to comment.