예제 #1
0
  public List<Map<String, Object>> getTwitter(String url, Context context) {
    ArrayList<Map<String, String>> json = this.JSON(url, context);
    List<Map<String, Object>> tweets = new ArrayList<Map<String, Object>>();
    Map<String, Object> data;
    if (json.get(0).get("internet").equals("true")) {
      for (int i = 0; i < json.size(); i++) {
        try {
          data = new HashMap<String, Object>();
          Log.i("JSON Lista Recebida", i + " -> " + json.get(i).toString());
          Tweet tweet =
              new Tweet(
                  json.get(i).get("texto"),
                  json.get(i).get("autor"),
                  json.get(i).get("imagem"),
                  json.get(i).get("date"));

          data.put("internet", true);
          data.put("text", tweet.getText());
          data.put("author", tweet.getAuthor());
          data.put("image", tweet.getImage());
          data.put("datetime", tweet.getDate());

          tweets.add(data);
        } catch (Exception e) {
          Log.e("JSON - Tweets", e.getMessage() + " " + e.getStackTrace());
        }
      }
    } else {
      data = new HashMap<String, Object>();
      data.put("internet", false);
      tweets.add(data);
    }
    return tweets;
  }
  /** Print the Event to the console. */
  public EventResult handleEvent(Tweet event) {

    System.out.println(
        String.format("[%s] => %s", event.getUser().getAccountName(), event.getMessage()));

    return EventResult.Handled;
  }
    /** Shows current tweet dialog and downloads user image */
    private void showTweet() {
      String text = current_tweet.getText();

      if (text != null) {
        String from = current_tweet.getFromUser();
        Alert a = new Alert("" + from, text, null, AlertType.INFO);

        a.setTimeout(Alert.FOREVER);
        display.setCurrent(a, this);
        String url = current_tweet.getProfileImageUrl();

        if (url != null) {
          // download and set user image to visible alert
          Image img;
          InputStream is = null;

          try {
            is = Connector.openInputStream(url);
            img = Image.createImage(is);
            a.setImage(img);
          } catch (Throwable t) { // do not show errors if image
            // download fails
          } finally {
            try {
              if (is != null) {
                is.close();
              }
            } catch (Throwable e) {
            }
          }
        }
      }
    }
 private void startTag(String aPrefix, String aName, XmlPullParser aParser) throws Exception {
   if ("entry".equals(aName)) {
     tweets.addTweet(currentTweet = new Tweet());
   } else if ("published".equals(aName)) {
     aParser.next();
     currentTweet.setPublished(dateFormat.parse(aParser.getText()));
   } else if (("title".equals(aName)) && (currentTweet != null)) {
     aParser.next();
     currentTweet.setTitle(aParser.getText());
   } else if ("content".equals(aName)) {
     Content _c = new Content();
     _c.setType(aParser.getAttributeValue(null, "type"));
     aParser.next();
     _c.setValue(aParser.getText());
     currentTweet.setContent(_c);
   } else if ("lang".equals(aName)) {
     aParser.next();
     currentTweet.setLanguage(aParser.getText());
   } else if ("author".equals(aName)) {
     currentTweet.setAuthor(currentAuthor = new Author());
   } else if ("name".equals(aName)) {
     aParser.next();
     currentAuthor.setName(aParser.getText());
   } else if ("uri".equals(aName)) {
     aParser.next();
     currentAuthor.setUri(aParser.getText());
   }
 }
    /** creates marker for tweet and its to map */
    private void addTweet(Tweet t) {
      if (t.getText() == null) {
        // ignore tweets without text
        return;
      }
      GeoCoordinate gc = t.getUserCoordinate();
      boolean addTweet = true;

      cleanOldest();
      if (map.getZoomLevel() > 0) {
        GeoBoundingBox gbb =
            new GeoBoundingBox(
                map.pixelToGeo(new Point(0, 0)),
                map.pixelToGeo(new Point(map.getWidth(), map.getHeight())));

        addTweet = gbb.contains(gc);
      }
      if (addTweet) {
        MapStandardMarker msm =
            mapFactory.createStandardMarker(gc, 100, "", MapStandardMarker.BALLOON);

        msm.setColor(MARKER_COLOR);
        map.addMapObject(msm);
        addedTweets.addData(msm, t);
        tweetAge.put(msm, new Long(t.getCreatedTime()));
        repaint();
      }
    }
예제 #6
0
 public TweetSlideEvent(String slide, Tweet tweet) {
   this.slide = slide.replace(" ", "_");
   this.createdAt = tweet.getCreatedAt().toString();
   this.id = tweet.getId();
   this.userId = tweet.getUserId();
   this.text = tweet.getText().replaceAll("\\s+", " ");
 }
예제 #7
0
  public static Tweet parseTweet(JSONObject input) {
    // Example of a tweet in JSON format:
    // https://dev.twitter.com/docs/api/1/get/search
    // logger.info("parsing as twitter doc");
    try {
      Tweet t = new Tweet();

      JSONObject user;
      user = input.getJSONObject("user");
      t.userID = user.getLong("id");
      t.text = input.getString("text");
      t.isRetweet = !input.isNull("retweeted_status");
      t.setDoctype(DocumentType.TWIITER_DOC);
      if (input.has("coordinates") && !input.isNull("coordinates")) {
        JSONObject geo = (JSONObject) input.getJSONObject("coordinates");
        if (geo.getString("type") == "Point") {
          JSONArray coords = geo.getJSONArray("coordinates");
          GeoLabel.LonLatPair geotag = new GeoLabel.LonLatPair();
          geotag.setLongitude(coords.getDouble(0));
          geotag.setLatitude(coords.getDouble(1));
        }
      }
      return t;
    } catch (JSONException e) {
      logger.error("Json exception in parsing tweet: " + input);
      logger.error(elog.toStringException(e));
      throw new RuntimeException(e);
    }
  }
예제 #8
0
  /**
   * Note the tweets with the chosen method
   *
   * @param listeTweets : list of tweets
   * @param algo : choice of the ranking method
   * @throws IOException
   */
  public void rateTweets(List<Tweet> listeTweets, String algo) throws IOException {
    for (Tweet tweet : listCleanTweets) {
      String text = tweet.getTweet();
      int mark = 0;

      switch (algo) {
        case "Keyword":
          mark = KeywordMethod.getClassePosNeg(text);
          break;
        case "Knn":
          mark = KnnMethod.knn(text, 30, baseTweets);
          break;
        case "BayesUniPres":
          mark = BayesMethod.rankBayes(listCleanTweets, text, 0);
          break;
        case "BayesUniFreq":
          mark = BayesMethod.rankBayes(listCleanTweets, text, 1);
          break;
        case "BayesBigPres":
          mark = BayesBiGrammeMethod.rankBigramBayes(listCleanTweets, text, 1);
          break;
        case "BayesBigFreq":
          mark = BayesBiGrammeMethod.rankBigramBayes(listCleanTweets, text, 0);
          break;
      }
      tweet.setNote(mark);
    }
  }
예제 #9
0
 @Test
 public void findRepostByTweets_Entity_複数_00() {
   Tweet twt1 = Tweet.findBySerialCode("twt-goro2").first();
   Tweet twt2 = Tweet.findBySerialCode("twt-jiro1").first();
   List<RepostBase> lst = RepostBase.findRepostByTweets(twt1, twt2).fetch();
   assertThat(lst.size(), is(7));
   // DBからの取得リストの並び保証なし
 }
 public static void clean(Tweet tw) {
   String tweet = removeUrl(tw.getTweet());
   List<String> newToks = Twokenize.tokenizeRawTweetText(tweet);
   replaceSlangs(newToks);
   // newToks = removeStopWords(newToks);
   tweet = String.join(" ", newToks);
   tw.setTweet(tweet);
 }
예제 #11
0
 @Test
 public void findRepostByTweets_Entity_複数_投稿者_00() {
   Tweet twt1 = Tweet.findBySerialCode("twt-goro2").first();
   Tweet twt2 = Tweet.findBySerialCode("twt-jiro1").first();
   Account acnt = Account.findByLoginName("goro_san").first();
   List<RepostBase> lst = RepostBase.findRepostByTweets(twt1, twt2).contributor(acnt).fetch();
   assertThat(lst.size(), is(5));
   // DBからの取得リストの並び保証なし
 }
예제 #12
0
  public void draw(float rect_width, float rect_height, float right_edge, float bottom_edge) {

    // parent.println(".");

    parent.textFont(parent.stack_font);
    parent.textSize(parent.new_tweets_stack_font_size);
    parent.textAlign(Twt.RIGHT);
    float z_pos = 0;
    float line_height = parent.textAscent() + parent.textDescent();
    float top_edge = bottom_edge - rect_height;
    float current_y = bottom_edge - rect_height; // bottom_edge - parent.textDescent();
    float cum_fade_out_correction = 0f;

    int fades_to_remove = 0;

    synchronized (new_tweets_stack) {
      for (int i = 0; i < new_tweets_stack.size(); i++) {
        // parent.println(i);
        float target_y =
            bottom_edge - parent.textDescent() - (float) i * (line_height * separation_factor);
        Tweet tweet = new_tweets_stack.elementAt(i);
        if (tweet.age() < IncomingStack.fade_in_time) {
          if (fade_ins.size() <= i) fade_ins.add(setUpFadein());
          parent.fill(color.getRGB(), 127 * fade_ins.elementAt(i).position());
          current_y = top_edge + (target_y - top_edge) * fade_ins.elementAt(i).position();
          // parent.println("fading in at " + current_y);
        } else if (tweet.age() > IncomingStack.display_time + IncomingStack.fade_in_time) {
          if (fade_outs.size() <= i) fade_outs.add(setUpFadeout());
          parent.fill(color.getRGB(), 127 * (1f - fade_outs.elementAt(i).position()));
          current_y =
              target_y + line_height * separation_factor * fade_outs.elementAt(i).position();
          cum_fade_out_correction +=
              line_height * separation_factor * fade_outs.elementAt(i).position();
          // parent.println("fading out at " + current_y);
          if (!fade_outs.elementAt(i).isTweening()) {
            fades_to_remove += 1;
            tweet.is_newcommer = false;
          }
        } else {
          parent.fill(color.getRGB(), color.getAlpha());
          // parent.println("showing at " + current_y);
          current_y = target_y;
        }
        // FIXME: there's a blink after a tweet is removed from the stack. Why?
        parent.text(tweet.the_tweet, right_edge, current_y + cum_fade_out_correction, z_pos);
      }

      while (fades_to_remove > 0) {
        fade_outs.removeElementAt(0);
        fade_ins.removeElementAt(0);
        new_tweets_stack.removeElementAt(0);
        fades_to_remove--;
      }
    }
  }
예제 #13
0
 @Test
 public void findRepostByTweets_Entity_複数_投稿者_降順_00() {
   Tweet twt1 = Tweet.findBySerialCode("twt-goro2").first();
   Tweet twt2 = Tweet.findBySerialCode("twt-jiro1").first();
   Account acnt = Account.findByLoginName("goro_san").first();
   List<RepostBase> lst =
       RepostBase.findRepostByTweets(twt1, twt2)
           .contributor(acnt)
           .orderBy(RepostBase.OrderBy.DATE_OF_REPOST_DESC)
           .fetch();
   assertThat(lst.size(), is(5));
   assertThat(lst.get(0).getItem().serialCode, is("twt-jiro1"));
 }
예제 #14
0
  /** Adds the seached tweets to the file tweetsBase.csv */
  public void saveBase() {
    try {
      if (baseTweets == null) {
        baseTweets = new ArrayList<Tweet>();
      }
      CsvWriter csvOutput = new CsvWriter(new FileWriter(AppliSettings.filename, true), ';');
      for (Tweet tweet : listCleanTweets) {
        int index = alreadyIn(tweet.getId());
        if (index == -1) {
          csvOutput.write("" + tweet.getId());
          csvOutput.write(tweet.getUser());
          String text = cleanTweet(tweet.getTweet());
          csvOutput.write(text);
          csvOutput.write("" + tweet.getDate());
          csvOutput.write("" + tweet.getNote());
          csvOutput.endRecord();
          baseTweets.add(tweet);
        } else {
          updateCSV(tweet.getNote(), index);
        }
      }

      csvOutput.close();
    } catch (IOException e) {
      System.out.println("saveBase");
      System.out.println(e.getMessage());
    }
  }
    /** Updates Twitter feed */
    private void updateTweets() throws IOException {
      Vector tweets =
          twitterRequest.getTweets(
              config.getPosition(), config.getRadius(), config.getQuery(), config.getMaxCount());

      for (Enumeration iterator = tweets.elements(); iterator.hasMoreElements(); ) {
        Tweet tweet = (Tweet) iterator.nextElement();

        if (tweet.getUserCoordinate() == null) {
          randomPlaceWithinRadius(tweet);
        }
        addTweet(tweet);
      }
    }
예제 #16
0
  @Override
  public int performAnalysis(Tweet tweet) {
    String[] words = tweet.getStatus().split(" ");
    Sentiment sentiment = new Sentiment();
    tweet.setSentiment(sentiment);

    for (int i = 0; i < words.length; i++) {
      if (negative.contains(words[i])) {
        sentiment.decrease(1);
      }
      if (positive.contains(words[i])) {
        sentiment.increase(1);
      }
    }
    return sentiment.getScore();
  }
  public static void obfuscateUserNames(Tweet tweet) {

    String message = tweet.getMessage();

    for (User mention : tweet.getMentioned()) {

      mention.setUserId(mention.getAccountName().hashCode());

      message =
          message.replace(mention.getAccountName(), String.format("@%s", mention.getUserId()));

      mention.setAccountName("omitted");
    }

    tweet.setMessage(message);
  }
예제 #18
0
 @Override
 public View getView(int position, View convertView, ViewGroup parent) {
   View v = convertView;
   if (v == null) {
     LayoutInflater vi = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);
     v = vi.inflate(R.layout.tweet_row, null);
   }
   Tweet tweet = tweets.get(position);
   if (tweet != null) {
     TextView tweetText = (TextView) v.findViewById(R.id.tweetTxt);
     if (tweetText != null) {
       tweetText.setText("Tweet: " + tweet.getTweet());
     }
   }
   return v;
 }
예제 #19
0
 public void onStatus(twitter4j.Status status) {
   Logger.info(status.getUser().getName() + " : " + status.getText());
   Tweet tweet = new Tweet(status);
   tweet.conformsToTerms = checkMatch(status);
   tweet.save();
   if (tweet.conformsToTerms && esClient != null) {
     String json = DataObjectFactory.getRawJSON(status);
     json =
         json.replaceAll(
             "(\"geo\":\\{\"type\":\"Point\",\"coordinates\":)\\[([-0-9.,]*)\\]", "$1\"$2\"");
     // Logger.debug("geo mangled json");
     // Logger.debug(json);
     IndexResponse response =
         esClient.prepareIndex("twitter", "tweet").setSource(json).execute().actionGet();
   }
 }
예제 #20
0
  /** Load the base tweet, and initialize the tweet list and the classification list */
  public static void loadBaseTweet() {
    baseTweets = new ArrayList<Tweet>();
    listCleanTweets = new ArrayList<Tweet>();
    listNegTweets = new ArrayList<Tweet>();
    listNeuTweets = new ArrayList<Tweet>();
    listPosTweets = new ArrayList<Tweet>();

    CSVReader reader = null;
    String[] nextLine;

    try {
      reader = new CSVReader(new FileReader(AppliSettings.filename), ';');

      try {
        while ((nextLine = reader.readNext()) != null) {
          Tweet t =
              new Tweet(
                  Long.parseLong(nextLine[0]),
                  nextLine[1],
                  nextLine[2],
                  nextLine[3],
                  Integer.parseInt(nextLine[4]));
          baseTweets.add(t);
          listCleanTweets.add(t);

          switch (t.getNote()) {
            case 0:
              listNegTweets.add(t);
              break;
            case 2:
              listNeuTweets.add(t);
              break;
            case 4:
              listPosTweets.add(t);
              break;
          }
        }
      } catch (NumberFormatException | IOException e) {
        System.out.println("load:numFormatExc");
        System.out.println(e.getMessage());
      }
    } catch (FileNotFoundException e) {
      System.out.println("load:fileExc");
      System.out.println(e.getMessage());
    }
  }
예제 #21
0
 public static Result list(int page, int pageSize) {
   Page<Tweet> currentPage = Tweet.page(page - 1, pageSize);
   // List<Tweet> tweets = Tweet.find.where().eq("conformsToTerms",true).orderBy("date
   // desc").findList();
   StreamConfig config = getConfig();
   String terms = config.listTermsAsString();
   return ok(stream_result_list.render(currentPage, page, pageSize, terms));
 }
  public static Tweet fromStatus(Status status) {

    Tweet tweet = new Tweet();

    tweet.setUser(fromUser(status.getUser()));

    if (status.getPlace() != null) {

      tweet.setLocation(fromPlace(status.getPlace()));
    }

    tweet.setTimeOfTweet(status.getCreatedAt().toString());
    tweet.setRetweetCount(status.getRetweetCount());

    ArrayList<User> lusers = new ArrayList<User>();

    String statusText = status.getText();

    for (UserMentionEntity entity : status.getUserMentionEntities()) {

      lusers.add(fromUserMentionEntity(entity));

      statusText = stripMentionedUserFromStatus(statusText, entity);
    }

    tweet.setMessage(statusText);

    tweet.setMentioned(lusers.toArray(new User[] {}));

    return tweet;
  }
  /*
   * (non-Javadoc)
   * @see com.socialize.networks.AbstractSocialNetworkSharer#doShare(android.app.Activity, com.socialize.entity.Entity, com.socialize.entity.PropagationUrlSet, java.lang.String, com.socialize.networks.SocialNetworkListener, com.socialize.api.action.ActionType)
   */
  @Override
  protected void doShare(
      Activity context,
      Entity entity,
      PropagationInfo urlSet,
      String comment,
      SocialNetworkListener listener,
      ActionType type) {

    Tweet tweet = new Tweet();

    switch (type) {
      case SHARE:
        if (StringUtils.isEmpty(comment)) comment = "Shared " + entity.getDisplayName();
        break;
      case LIKE:
        comment = "\u2764 likes " + entity.getDisplayName();
        break;
      case VIEW:
        comment = "Viewed " + entity.getDisplayName();
        break;
    }

    StringBuilder status = new StringBuilder();

    if (StringUtils.isEmpty(comment)) {
      status.append(entity.getDisplayName());
    } else {
      status.append(comment);
    }

    status.append(", ");
    status.append(urlSet.getEntityUrl());

    tweet.setText(status.toString());

    UserSettings settings = UserUtils.getUserSettings(context);

    if (settings != null && settings.isLocationEnabled()) {
      tweet.setLocation(LocationUtils.getLastKnownLocation(context));
      tweet.setShareLocation(true);
    }

    TwitterUtils.tweet(context, tweet, listener);
  }
  @RequestMapping(value = "/tweet/comment", method = RequestMethod.POST)
  public void comment(@RequestBody Message message) {

    Tweet tweet = tweetRepo.findOne(message.getTid());
    tweet.setCommentCount(tweet.getCommentCount() + 1);
    tweetRepo.saveAndFlush(tweet);

    // 保存评论
    UserTweet userTweet = new UserTweet();
    userTweet.setUid(message.getUid());
    userTweet.setTid(message.getTid());
    userTweet.setUserTweetType(UserTweet.UserTweetType.COMMENT);
    userTweetRepo.saveAndFlush(userTweet);

    message.setMessageType(Message.MessageType.COMMENT);
    message.setTime(Utils.getTime());
    message.setDate(System.currentTimeMillis());
    Utils.message(messageRepo.saveAndFlush(message));
  }
예제 #25
0
  @Override
  public List<Tweet> getMentions() {

    /*
     * to avoid duplicates (we have to search and get mentions,
     * because mentions by themselves are broken  / sometimes
     * don't update on a timely basis.
     */

    Set<Tweet> result = new TreeSet<Tweet>();
    // FIXME or 200 mentions = DOS
    try {
      List<Status> mentions = twitter.getMentions();

      for (Status s : mentions) {
        Tweet t = new Tweet(s.getId(), s.getText(), s.getUser().getScreenName());
        t.setInReplyToId(s.getInReplyToStatusId());
        result.add(t);
      }
      // mentions should be fixed now?
      //            Query q = new Query("@"+screenName);
      //
      //            QueryResult r = twitter.search(q);
      //
      //			for(twitter4j.Tweet t : r.getTweets()) {
      //				//compute hashcodes like in mockimpl
      //			    Tweet tt = new Tweet(t.getId(), t.getText(), t.getFromUser());
      //			    if(t.get){
      //			        tt.setInReplyToId(t.getInReplyToStatusId()))
      //			    }
      //			    t.
      //				result.add(tt);
      //			}

    } catch (TwitterException e) {
      throw new ScriptusRuntimeException(e);
    }

    return new ArrayList<Tweet>(result);
  }
  @Override
  protected List<Tweet> doInBackground(Void... params) {

    try {
      Thread.sleep(5000);
      for (int i = 0; i < 30; i++) {
        Tweet tweet = new Tweet();
        tweet.setTitle("A nice header for Tweet # " + i);
        tweet.setBody("Some random body text for the tweet # " + i);
        tweets.add(tweet);
      }

      Log.d("Calling AsynchWriteTweets", "Call()");
      AsyncWriteTweets test1 = new AsyncWriteTweets(test);
      test1.execute(tweets);
      Log.d("AsyncWriteTweets Finished", "Finished");

    } catch (Exception e) {
      Log.d("Error in Asynch Task", "" + e.toString());
    }
    return tweets;
  }
  public void grab(Date timeLimit) {
    log.info("Twitter grabber started...");
    Twitter twitter = new TwitterFactory().getInstance();

    List<Brand> brandList = handler.getBrandProvider().getAllBrands();
    ArticleProvider articleProvider = handler.getArticleProvider();

    for (Brand b : brandList) {
      Query query = new Query(b.getName());
      query.setRpp(PAGE_SIZE);
      query.setLang("ru");
      query.setResultType(Query.MIXED);

      List<Tweet> resultTweets = new LinkedList<Tweet>();
      QueryResult queryResult;
      int pageNumber = 1;

      try {
        do {
          query.setPage(pageNumber);
          queryResult = twitter.search(query);
          resultTweets.addAll(queryResult.getTweets());
          pageNumber++;
          log.info(pageNumber);
        } while (ISSUANCE_SIZE > resultTweets.size());
      } catch (TwitterException e) {
        throw new RuntimeException(e);
      }
      log.info("tweets in da111y: " + resultTweets.size());
      twitter = null;
      twitter = new TwitterFactory().getInstance();

      for (Tweet t : resultTweets) {
        articleProvider.writeArticleToDataStore(
            new Article(-1, b.getId(), 2, "", t.getText(), "", getSimpleTime(t.getCreatedAt()), 1));
      }
    }
    log.info("twitter grabber finished succesful.");
  }
  @RequestMapping(value = "/tweet/star", method = RequestMethod.POST)
  public void star(
      @RequestParam("uid") long uid,
      @RequestParam("tid") long tid,
      @RequestParam("star") boolean star) {
    Tweet tweet = tweetRepo.findOne(tid);
    if (star) {
      if (userTweetRepo.findByUidAndTidAndUserTweetType(uid, tid, UserTweet.UserTweetType.STAR)
          == null) {
        UserTweet userTweet = new UserTweet();
        userTweet.setUid(uid);
        userTweet.setTid(tid);
        userTweet.setUserTweetType(UserTweet.UserTweetType.STAR);
        userTweetRepo.saveAndFlush(userTweet);

        User user = userRepo.findOne(uid);
        Message message = new Message();
        message.setUid(uid);
        message.setUid2(tweet.getUid());
        message.setTid(tid);
        message.setMessageType(Message.MessageType.STAR);
        message.setTitle(user.getName());
        message.setContent(user.getName());
        message.setIcon(user.getAvatar());
        message.setTime(Utils.getTime());
        message.setDate(System.currentTimeMillis());
        Utils.message(messageRepo.saveAndFlush(message));
      } else {
        return;
      }
    } else {
      userTweetRepo.deleteByUidAndTidAndUserTweetType(uid, tid, UserTweet.UserTweetType.STAR);
    }
    tweet.setStarCount(star ? tweet.getStarCount() + 1 : tweet.getStarCount() - 1);
    tweetRepo.saveAndFlush(tweet);
  }
    /**
     * Sets tweet position randomly within radius
     *
     * @param tweet the tweet data
     */
    private void randomPlaceWithinRadius(Tweet tweet) {
      double radius = config.getRadius();
      double maxDegreeDiff = radius / SURFACE_DISTANCE;
      double latR = random.nextDouble();
      double lonR = random.nextDouble();

      latR = (latR - 0.5) * 2; // -1 to 1
      lonR = (lonR - 0.5) * 2; // -1 to 1
      GeoCoordinate sc = config.getPosition();
      GeoCoordinate gc =
          new GeoCoordinate(
              sc.getLatitude() + latR * maxDegreeDiff, sc.getLongitude() + lonR * maxDegreeDiff, 0);

      tweet.setUserCoordinate(gc);
    }
예제 #30
0
  public void execute() throws Exception {
    BlockingQueue<Tweet> queue = new LinkedBlockingQueue<Tweet>(MAX_BUFFER_SIZE);
    queue.addAll(
        readFromFile(
            "/Users/semimac/git/se560/se560/src/main/java/edu/metu/se560/twitter/1394470743403.txt"));
    for (int i = 0; i < clusters.size(); i++) {
      Tweet msg = queue.take();
      clusters.get(i).addTweet(msg);
    }

    for (int msgRead = 0; msgRead < 100; msgRead++) {
      Tweet msg = queue.take();
      int maxSimilarityIndex = -1;
      double maxSimilarity = 0;

      for (int j = 0; j < clusters.size(); j++) {
        double jaccardSimilarity = msg.jaccardSimilarity(clusters.get(j).getPrototype());
        if (maxSimilarity < jaccardSimilarity) {
          maxSimilarityIndex = j;
          maxSimilarity = jaccardSimilarity;
        }
      }
      if (maxSimilarityIndex > -1) { // Yeni cluster olußturmak Ÿzere baßka clustera al
        clusters.get(maxSimilarityIndex).addTweet(msg);
      }
    }
    for (Iterator iterator = clusters.iterator(); iterator.hasNext(); ) {
      Cluster cluster = (Cluster) iterator.next();
      System.out.println("Cluster");
      System.out.println(cluster.getPrototype().toString());
      for (Iterator iterator2 = cluster.getTweets().iterator(); iterator2.hasNext(); ) {
        Tweet tweet = (Tweet) iterator2.next();
        System.out.println(tweet.toString());
      }
    }
  }