Advertisement
Guest User

Untitled

a guest
Oct 31st, 2014
132
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.85 KB | None | 0 0
  1. package problema;
  2.  
  3. import java.io.BufferedReader;
  4. import java.io.FileReader;
  5. import java.io.IOException;
  6. import java.util.Arrays;
  7.  
  8. public class TweetAnalysis {
  9.  
  10. public static int countTags = 0;
  11. public static String initDateTime = "2014-07-06T18:08:22";
  12. public static String endDateTime = "2014-07-06T18:08:24";
  13. public static String fileToRead;
  14. public static String tagFile = "C:/Users/Rebelo/Desktop/Eclipse/problema/AED/hastag.tag";
  15.  
  16. public static void main(String[] args) throws IOException {
  17. fileToRead = "C:/Users/Rebelo/Desktop/Eclipse/problema/AED/sample44Xfiltered.twt/sample44Xfiltered.twt";
  18. moreMentioned(initDateTime, endDateTime, tagFile);
  19. }
  20.  
  21. public static String[] readTagFile(String file) throws IOException {
  22. String tagsFromFile = "";
  23. String[] tags;
  24. String line;
  25.  
  26. BufferedReader reader = new BufferedReader(new FileReader(file));
  27.  
  28. while ((line = reader.readLine()) != null) {
  29. tagsFromFile += line + " ";
  30. ++countTags;
  31. }
  32. reader.close();
  33. tags = tagsFromFile.split(" ");
  34.  
  35. return tags;
  36. }
  37.  
  38. public static String moreMentioned(String initDateTime, String endDateTime, String file) throws IOException {
  39. int moreMentioned = 0;
  40. String line, split;
  41. String[] tags = readTagFile(file);
  42. Long currDate, initTime = ConvertDate.getInstant(initDateTime), endTime = ConvertDate.getInstant(endDateTime);
  43. String[] hashtags;
  44.  
  45. BufferedReader reader = new BufferedReader(new FileReader(fileToRead));
  46.  
  47. while ((line = reader.readLine()) != null) {
  48. currDate = ConvertDate.getInstant(line.substring(line.indexOf(":") + 3, line.indexOf(",") - 1));
  49. if (currDate >= initTime && currDate <= endTime) {
  50. split = line.substring(line.indexOf("[") + 1, line.indexOf("]"));
  51. hashtags = split.split(", ");
  52.  
  53.  
  54.  
  55.  
  56. }
  57.  
  58. }
  59. reader.close();
  60. return tags[moreMentioned];
  61. }
  62. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement