public static String stripMentionedUserFromStatus(String status, UserMentionEntity mention) {
    String newStatus = status.replace(mention.getScreenName(), Long.toString(mention.getId()));

    System.out.println(newStatus);

    return newStatus;
  }
  public static User fromUserMentionEntityComplete(UserMentionEntity tuser) {

    User user = fromUserMentionEntity(tuser);

    user.setUser(tuser.getName());
    user.setAccountName(tuser.getScreenName());

    return user;
  }
  public static User fromUserMentionEntity(UserMentionEntity tuser) {

    User user = new User();

    user.setUserId(tuser.getId());

    return user;
  }
Ejemplo n.º 4
0
  public void onStatus(Status status) {

    String username = status.getUser().getScreenName();
    String userLocale = status.getUser().getLocation();
    String message = status.getText();
    Date timestamp = status.getCreatedAt();
    UserMentionEntity[] userMentions = status.getUserMentionEntities();

    List<String> userMentionList = new ArrayList<String>();

    for (int i = 0; i < userMentions.length; i++) {
      UserMentionEntity e = userMentions[i];
      userMentionList.add(e.getScreenName());
    }

    TwitterEvent event =
        new TwitterEvent(timestamp, message, username, userLocale, userMentionList);

    // System.out.println(message + "---------" );

    CepEngine.getInstance().addEvent(event);
  }
Ejemplo n.º 5
0
 /**
  * CONSTRUCTOR
  *
  * @param status : the actual tweet present in the portion of the stream received
  * @param mention : one of the multiple mentions present in the status
  */
 public TwitterTuple(Status status, UserMentionEntity mention) {
   this.user = status.getUser().getScreenName();
   this.lang = status.getUser().getLang();
   this.mentions = mention;
   this.mentionedUser = mention.getScreenName();
   if (status.getGeoLocation() == null) {
     this.latitude = -999.0;
     this.longitude = -999.0;
   } else {
     this.latitude = status.getGeoLocation().getLatitude();
     this.longitude = status.getGeoLocation().getLongitude();
   }
 }
Ejemplo n.º 6
0
  @Override
  public void onStatus(Status status) {
    Set<String> mentions = new HashSet<String>(status.getUserMentionEntities().length);
    for (UserMentionEntity mention : status.getUserMentionEntities())
      mentions.add(mention.getScreenName());

    Set<String> hashtags = new HashSet<String>(status.getHashtagEntities().length);
    for (HashtagEntity hashtag : status.getHashtagEntities()) hashtags.add(hashtag.getText());

    Debug.logln(
        "onStatus id: "
            + status.getId()
            + " sender: "
            + status.getUser().getScreenName()
            + " mentions: "
            + mentions.toString()
            + " hashtags: "
            + hashtags.toString()
            + " in reply: "
            + status.getInReplyToStatusId()
            + " text: "
            + status.getText());
  }
Ejemplo n.º 7
0
  private static Record buildEntities(Schema schemaEntities, Status status) {
    GenericRecordBuilder builderEntities = new GenericRecordBuilder(schemaEntities);

    if (status.getHashtagEntities().length > 0) {
      Schema schemaHashtagObject = schemaEntities.getField("hashtags").schema().getElementType();
      List<GenericRecord> listHashtagObjects = new ArrayList<>();
      for (HashtagEntity hashtagEntity : status.getHashtagEntities()) {
        GenericRecordBuilder builderHashtagObject = new GenericRecordBuilder(schemaHashtagObject);
        builderHashtagObject.set("text", hashtagEntity.getText());
        builderHashtagObject.set("start", hashtagEntity.getStart());
        builderHashtagObject.set("end", hashtagEntity.getEnd());
        listHashtagObjects.add(builderHashtagObject.build());
      }
      builderEntities.set("hashtags", listHashtagObjects);
    } else builderEntities.set("hashtags", Collections.emptyList());

    if (status.getSymbolEntities().length > 0) {
      Schema schemaSymbolObject = schemaEntities.getField("symbols").schema().getElementType();
      List<GenericRecord> listSymbolObject = new ArrayList<>();
      for (SymbolEntity symbolEntity : status.getSymbolEntities()) {
        GenericRecordBuilder builderSymbolObject = new GenericRecordBuilder(schemaSymbolObject);
        builderSymbolObject.set("text", symbolEntity.getText());
        builderSymbolObject.set("start", symbolEntity.getStart());
        builderSymbolObject.set("end", symbolEntity.getEnd());
        listSymbolObject.add(builderSymbolObject.build());
      }
      builderEntities.set("symbols", listSymbolObject);
    } else builderEntities.set("symbols", Collections.emptyList());

    if (status.getMediaEntities().length > 0) {
      Schema schemaMediaObject = schemaEntities.getField("media").schema().getElementType();
      List<GenericRecord> listMediaObject = new ArrayList<>();
      for (MediaEntity mediaEntity : status.getMediaEntities()) {
        GenericRecordBuilder builderMediaObject = new GenericRecordBuilder(schemaMediaObject);
        builderMediaObject.set("url", mediaEntity.getURL());
        builderMediaObject.set("display_url", mediaEntity.getDisplayURL());
        builderMediaObject.set("expanded_url", mediaEntity.getExpandedURL());
        builderMediaObject.set("id", mediaEntity.getId());
        builderMediaObject.set("media_url", mediaEntity.getMediaURL());
        builderMediaObject.set("media_url_https", mediaEntity.getMediaURLHttps());
        builderMediaObject.set("type", mediaEntity.getType());
        builderMediaObject.set("text", mediaEntity.getText());
        builderMediaObject.set("start", mediaEntity.getStart());
        builderMediaObject.set("end", mediaEntity.getEnd());

        Schema schemaSize = schemaMediaObject.getField("sizes").schema().getValueType();
        GenericRecordBuilder builderSize = new GenericRecordBuilder(schemaSize);
        Map<String, GenericRecord> mapSizes = new HashMap<>(4);
        for (int key : mediaEntity.getSizes().keySet()) {
          Size size = mediaEntity.getSizes().get(key);
          builderSize.set("h", size.getHeight());
          builderSize.set("w", size.getWidth());
          builderSize.set("resize", size.getResize());
          mapSizes.put(Integer.toString(key), builderSize.build());
        }
        builderMediaObject.set("sizes", mapSizes);
        listMediaObject.add(builderMediaObject.build());
      }
      builderEntities.set("media", listMediaObject);
    } else builderEntities.set("media", Collections.emptyList());

    if (status.getURLEntities().length > 0) {
      Schema schemaURLObject = schemaEntities.getField("urls").schema().getElementType();
      List<GenericRecord> listURLObject1 = new ArrayList<>();
      for (URLEntity urlEntity : status.getURLEntities())
        listURLObject1.add(buildURLEntity(schemaURLObject, urlEntity));
      builderEntities.set("urls", listURLObject1);
    } else builderEntities.set("urls", Collections.emptyList());

    if (status.getUserMentionEntities().length > 0) {
      Schema schemaUserMentionObject =
          schemaEntities.getField("user_mentions").schema().getElementType();
      List<GenericRecord> listUserMentionObject = new ArrayList<>();
      for (UserMentionEntity userMentionEntity : status.getUserMentionEntities()) {
        GenericRecordBuilder builderUserMentionObject =
            new GenericRecordBuilder(schemaUserMentionObject);
        builderUserMentionObject.set("name", userMentionEntity.getName());
        builderUserMentionObject.set("screen_name", userMentionEntity.getScreenName());
        builderUserMentionObject.set("text", userMentionEntity.getText());
        builderUserMentionObject.set("id", userMentionEntity.getId());
        builderUserMentionObject.set("start", userMentionEntity.getStart());
        builderUserMentionObject.set("end", userMentionEntity.getEnd());
        listUserMentionObject.add(builderUserMentionObject.build());
      }
      builderEntities.set("user_mentions", listUserMentionObject);
    } else builderEntities.set("user_mentions", Collections.emptyList());

    if (status.getExtendedMediaEntities().length > 0) {
      Schema schemaExtendedMediaObject =
          schemaEntities.getField("extended_entities").schema().getElementType();
      List<GenericRecord> listExtendedMediaObject = new ArrayList<>();
      for (ExtendedMediaEntity extendedMediaEntity : status.getExtendedMediaEntities()) {
        GenericRecordBuilder builderExtendedMediaObject =
            new GenericRecordBuilder(schemaExtendedMediaObject);
        builderExtendedMediaObject.set("url", extendedMediaEntity.getURL());
        builderExtendedMediaObject.set("display_url", extendedMediaEntity.getDisplayURL());
        builderExtendedMediaObject.set("expanded_url", extendedMediaEntity.getExpandedURL());
        builderExtendedMediaObject.set("id", extendedMediaEntity.getId());
        builderExtendedMediaObject.set("media_url", extendedMediaEntity.getMediaURL());
        builderExtendedMediaObject.set("media_url_https", extendedMediaEntity.getMediaURLHttps());
        builderExtendedMediaObject.set("type", extendedMediaEntity.getType());
        builderExtendedMediaObject.set("text", extendedMediaEntity.getText());
        builderExtendedMediaObject.set("start", extendedMediaEntity.getStart());
        builderExtendedMediaObject.set("end", extendedMediaEntity.getEnd());

        Schema schemaSize = schemaExtendedMediaObject.getField("sizes").schema().getValueType();
        GenericRecordBuilder builderSize = new GenericRecordBuilder(schemaSize);
        Map<String, GenericRecord> mapSizes = new HashMap<>(4);
        for (int key : extendedMediaEntity.getSizes().keySet()) {
          Size size = extendedMediaEntity.getSizes().get(key);
          builderSize.set("h", size.getHeight());
          builderSize.set("w", size.getWidth());
          builderSize.set("resize", size.getResize());
          mapSizes.put(Integer.toString(key), builderSize.build());
        }
        builderExtendedMediaObject.set("sizes", mapSizes);

        Schema schemaVideoInfo = schemaExtendedMediaObject.getField("video_info").schema();
        GenericRecordBuilder builderVideoInfo = new GenericRecordBuilder(schemaVideoInfo);
        builderVideoInfo.set("h", extendedMediaEntity.getVideoAspectRatioHeight());
        builderVideoInfo.set("w", extendedMediaEntity.getVideoAspectRatioWidth());
        builderVideoInfo.set("duration_millis", extendedMediaEntity.getVideoDurationMillis());

        Schema schemaVideoVariants = schemaVideoInfo.getField("variants").schema().getElementType();
        List<GenericRecord> listVideoVariants = new ArrayList<>();
        for (Variant extendedVideoVariant : extendedMediaEntity.getVideoVariants()) {
          GenericRecordBuilder builderVideoVariant = new GenericRecordBuilder(schemaVideoVariants);
          builderVideoVariant.set("bitrate", extendedVideoVariant.getBitrate());
          builderVideoVariant.set("content_type", extendedVideoVariant.getContentType());
          builderVideoVariant.set("url", extendedVideoVariant.getUrl());
          listVideoVariants.add(builderVideoVariant.build());
        }
        builderVideoInfo.set("variants", listVideoVariants);
        builderExtendedMediaObject.set("video_info", builderVideoInfo.build());

        listExtendedMediaObject.add(builderExtendedMediaObject.build());
      }
      builderEntities.set("extended_entities", listExtendedMediaObject);
    } else builderEntities.set("extended_entities", Collections.emptyList());
    return builderEntities.build();
  }
Ejemplo n.º 8
0
 protected boolean checkMatch(twitter4j.Status status) {
   boolean result = false;
   if (matchPattern.matcher(status.getText()).find()) result = true;
   if (result) {
     Logger.debug("Terms found in text");
     Logger.debug("    \"" + status.getText() + "\"");
     return result;
   }
   for (URLEntity ue : status.getURLEntities()) {
     if (matchPattern.matcher(ue.getDisplayURL()).find()) result = true;
     if (matchPattern.matcher(ue.getExpandedURL()).find()) result = true;
   }
   if (result) {
     Logger.debug("Terms found in URL entities");
     for (URLEntity ue : status.getURLEntities()) {
       Logger.debug("    " + ue.getDisplayURL());
       Logger.debug("    " + ue.getExpandedURL());
     }
     return result;
   }
   for (URLEntity ue : status.getMediaEntities()) {
     if (matchPattern.matcher(ue.getDisplayURL()).find()) result = true;
     if (matchPattern.matcher(ue.getExpandedURL()).find()) result = true;
   }
   if (result) {
     Logger.debug("Terms found in Media entities");
     for (URLEntity ue : status.getMediaEntities()) {
       Logger.debug("    " + ue.getDisplayURL());
       Logger.debug("    " + ue.getExpandedURL());
     }
     return result;
   }
   for (HashtagEntity he : status.getHashtagEntities()) {
     if (matchPattern.matcher(he.getText()).find()) result = true;
   }
   if (result) {
     Logger.debug("Terms found in Hashtag entities");
     for (HashtagEntity he : status.getHashtagEntities()) {
       Logger.debug("    " + he.getText());
     }
     return result;
   }
   for (UserMentionEntity me : status.getUserMentionEntities()) {
     if (matchPattern.matcher(me.getScreenName()).find()) result = true;
   }
   if (result) {
     Logger.debug("Terms found in User mention entities");
     for (UserMentionEntity me : status.getUserMentionEntities()) {
       Logger.debug("    " + me.getScreenName());
     }
     return result;
   }
   Logger.debug("Terms NOT FOUND");
   Logger.debug("    Terms not found in URL entities");
   for (URLEntity ue : status.getURLEntities()) {
     Logger.debug("    " + ue.getDisplayURL());
     Logger.debug("    " + ue.getExpandedURL());
   }
   Logger.debug("    Terms not found in Media entities");
   for (URLEntity ue : status.getMediaEntities()) {
     Logger.debug("    " + ue.getDisplayURL());
     Logger.debug("    " + ue.getExpandedURL());
   }
   Logger.debug("    Terms not found in Hashtag entities");
   for (HashtagEntity he : status.getHashtagEntities()) {
     Logger.debug("    " + he.getText());
   }
   Logger.debug("    Terms not found in User mention entities");
   for (UserMentionEntity me : status.getUserMentionEntities()) {
     Logger.debug("    " + me.getScreenName());
   }
   return result;
 }