Class Tweet


  • public class Tweet
    extends Message
    • Field Detail

      • SOURCE_TWITTER

        public static java.lang.String SOURCE_TWITTER
      • ATTR_SCREEN_NAME

        public static final java.lang.String ATTR_SCREEN_NAME
        See Also:
        Constant Field Values
      • timestamp_parser

        public static final org.joda.time.format.DateTimeFormatter timestamp_parser
      • iso_date_formatter

        public static final org.joda.time.format.DateTimeFormatter iso_date_formatter
      • geoEnabled

        public boolean geoEnabled
      • retweet

        public boolean retweet
      • retweetID

        public java.lang.String retweetID
      • authorDesc

        public java.lang.String authorDesc
      • tweetStore

        protected boolean tweetStore
        Is TweetStore the main repository of data?
      • entitiesKey

        protected java.lang.String entitiesKey
      • authorGender

        public java.lang.String authorGender
        M=male, F=female, T=transitional, transgender? Other? Gender is a string, could be an enum, but its no longer two values, I bet.
      • LOCATION_FLD

        public static java.lang.String LOCATION_FLD
      • COORD_FLD

        public static java.lang.String COORD_FLD
      • mentions

        protected java.util.Set<java.lang.String> mentions
    • Constructor Detail

      • Tweet

        public Tweet()
      • Tweet

        public Tweet​(java.lang.String sid)
      • Tweet

        public Tweet​(java.lang.String _id,
                     java.lang.String text,
                     java.util.Date tm)
    • Method Detail

      • isGeolocated

        public boolean isGeolocated()
        indicate if tweet is geolocated by an accurate coordinate.
        Returns:
      • isGeoinferenced

        public boolean isGeoinferenced()
        indicate if tweet has any Geo resolution at all, wether it was a given Lat/Lon or derived. Careful -- authorGeo and statusGeo are both mutable. If you geocode them directly while still on the Tweet instance, they will look like they were part of the given data.
        Returns:
      • setGeoMethod

        public void setGeoMethod​(java.lang.String m)
      • getGeoMethod

        public java.lang.String getGeoMethod()
        TODO: this is not clear.
        Returns:
      • applyGenericRules

        public void applyGenericRules()
      • fixNull

        public static java.lang.String fixNull​(java.lang.String v)
      • setDate

        public void setDate​(long d)
        Set the date and an the standard "CREATED_AT" date/time format.
        Parameters:
        d - epoch
      • getISOTimestamp

        public java.lang.String getISOTimestamp()
      • parseId

        public static java.lang.String parseId​(java.lang.String gnipId)
        Most commonly needed to parse TweetID from a GnipID
        Parameters:
        gnipId -
        Returns:
      • parseIds

        protected java.lang.String parseIds​(java.util.Map<?,​?> tw)
                                     throws MessageParseException
        Find a best ID from many possible places where ID, id, id_str, etc, reside.
        Parameters:
        tw -
        Returns:
        Throws:
        MessageParseException
      • fromJSON

        public void fromJSON​(jodd.json.JsonObject tw)
                      throws MessageParseException
        If "base data" has been filled in by other method, e.g., TW4J or other formal API, then avoid parsing the basics here: id, text ,author*, date, lang, are checked if null. Only if null will they each be found in JSON and parsed. throws MessageParseException
        Throws:
        MessageParseException
      • parseDate

        protected void parseDate​(java.util.Map<?,​?> tw)
      • parseLanguage

        public void parseLanguage​(java.lang.String lg)
      • parseURLs

        public void parseURLs​(java.util.List<?> jsonArray)
        supports gnip.urls or topsy.urls fields
        Parameters:
        jsonArray -
      • setUserGeo

        public static boolean setUserGeo​(jodd.json.JsonObject json,
                                         Tweet tw)
        Parameters:
        json -
        tw -
        Returns:
        true if a location metadata was found and set.
      • setStatusGeo

        public static void setStatusGeo​(jodd.json.JsonObject json,
                                        Tweet tw)
        TODO: investigate how close a user Profile geo compares with Status geo.
        Parameters:
        json -
        tw -
      • setPlace

        protected static void setPlace​(Place p,
                                       jodd.json.JsonObject aPlace)
        Parameters:
        p -
        aPlace -
      • setLatLon

        protected static void setLatLon​(Place p,
                                        jodd.json.JsonObject hasCoord,
                                        boolean latFirst)
        Order of coordinates is for geo = (LON, LAT) in twitter objects. for coordinates = (LAT, LON) see http://support.gnip.com/articles/filtering-twitter-data-by-location.html
        Parameters:
        p -
        hasCoord -
        latFirst - true if type of Point has lat as first field.
      • isValue

        public static boolean isValue​(jodd.json.JsonObject o)
        Parameters:
        o -
        Returns:
      • isValue

        public static boolean isValue​(java.util.List<?> o)
      • optString

        public static java.lang.String optString​(jodd.json.JsonObject o,
                                                 java.lang.String k)
        "", null, or "null" checking.
        Parameters:
        o -
        k -
        Returns:
      • getInteger

        public static int getInteger​(jodd.json.JsonObject o,
                                     java.lang.String k,
                                     int defVal)
      • isValue

        public static boolean isValue​(java.lang.String o)
      • setUser

        public void setUser​(jodd.json.JsonObject tw_user)
      • setPerson

        public void setPerson​(jodd.json.JsonObject tw_user)
      • addTag

        public void addTag​(java.lang.String t)
        add any tag you like. could be hash tags or entities
      • addURL

        public void addURL​(java.lang.String url)
      • getTags

        public java.util.Collection<java.lang.String> getTags()
      • getURLs

        public java.util.Collection<java.lang.String> getURLs()
      • getMentions

        public java.util.Collection<java.lang.String> getMentions()
        Found user screen_names, no user ID
        Returns:
        list of found screen names
      • getMentionIDs

        public java.util.List<Tweet.Mention> getMentionIDs()
        fully qualified Twitter user profiles: screen_name : user ID pairings. Multiple screen names could be associated with the same user ID (although not likley in a single tweet)
        Returns:
        map
      • addMention

        public void addMention​(java.lang.String uname,
                               java.lang.String uid)
        If adding mentions one at a time, then only mention IDS map is used. if profile uid is null, then screen_name, U = null will be mapped
        Parameters:
        uname -
        uid -
      • parseMentions

        public java.util.List<Tweet.Mention> parseMentions​(jodd.json.JsonObject entities)
        Gets a entities.user_mentions from a normal Tweet.
        Parameters:
        entities -
        Returns:
        map of screen_name to user profile ID
      • parseMentions

        public static java.util.Set<java.lang.String> parseMentions​(java.lang.String msg)
        From a tweet, get list of "@id"
        Parameters:
        msg - tweet or other text
        Returns:
      • toString

        public java.lang.String toString()
        Overrides:
        toString in class java.lang.Object
      • setLanguage

        public void setLanguage​(java.lang.String l)