Example usage for twitter4j Status getGeoLocation

List of usage examples for twitter4j Status getGeoLocation

Introduction

In this page you can find the example usage for twitter4j Status getGeoLocation.

Prototype

GeoLocation getGeoLocation();

Source Link

Document

Returns The location that this tweet refers to if available.

Usage

From source file:org.talend.spark.utils.twitter.TwitterUtil.java

License:Open Source License

public static Object parse(TwitterParameter parameter, Status status) {
    if (parameter == TwitterParameter.USERNAME) {
        return status.getUser().getName();
    } else if (parameter == TwitterParameter.TEXT) {
        return status.getText();
    } else if (parameter == TwitterParameter.SOURCE) {
        return status.getSource();
    } else if (parameter == TwitterParameter.ACCESSLEVEL) {
        return status.getAccessLevel();
    } else if (parameter == TwitterParameter.DATE) {
        return status.getCreatedAt();
    } else if (parameter == TwitterParameter.ID) {
        return status.getId();
    } else if (parameter == TwitterParameter.GEOLOCATION_LATITUDE) {
        return status.getGeoLocation().getLatitude();
    } else if (parameter == TwitterParameter.GEOLOCATION_LONGITUDE) {
        return status.getGeoLocation().getLongitude();
    } else if (parameter == TwitterParameter.HASHTAG) {
        String hashTags = "";
        HashtagEntity[] hashTagArray = status.getHashtagEntities();
        for (int i = 0; i < hashTagArray.length; i++) {
            if (hashTags.equals("")) {
                hashTags = hashTagArray[i].getText();
            } else {
                hashTags = hashTags + "," + hashTagArray[i].getText();
            }/* ww  w .  ja  v a2 s.  c  o  m*/
        }
        return hashTags;
    }
    return null;
}

From source file:org.unimonk.flume.source.twitter.TwitterSource.java

License:Apache License

@Override
public void start() {

    final ChannelProcessor channel = getChannelProcessor();

    StatusListener listener = new StatusListener() {
        @Override// w  w  w . j  av  a 2s. co  m
        public void onStatus(Status status) {

            Tweet tweet = new Tweet();
            tweet.setId(status.getId());
            tweet.setUserId(status.getUser().getId());
            tweet.setLatitude(status.getGeoLocation().getLatitude());
            tweet.setLongitude(status.getGeoLocation().getLongitude());
            tweet.setText(status.getText());
            tweet.setCreatedAt(new Timestamp(status.getCreatedAt().getTime()));

            Event event = EventBuilder.withBody(tweet.toString(), Charsets.UTF_8);
            sourceCounter.incrementAppendReceivedCount();
            try {
                channel.processEvent(event);
                sourceCounter.incrementEventAcceptedCount();
            } catch (ChannelException ex) {
                logger.error("In Twitter source {} : Unable to process event due to exception {}.", getName(),
                        ex);

            }
        }

        // This listener will ignore everything except for new tweets
        @Override
        public void onDeletionNotice(StatusDeletionNotice statusDeletionNotice) {
        }

        @Override
        public void onTrackLimitationNotice(int numberOfLimitedStatuses) {
        }

        @Override
        public void onScrubGeo(long userId, long upToStatusId) {
        }

        @Override
        public void onException(Exception ex) {
        }

        @Override
        public void onStallWarning(StallWarning arg0) {
        }
    };

    logger.debug("Setting up Twitter sample stream using consumer key {} and" + " access token {}",
            new String[] { consumerKey, accessToken });

    twitterStream = new TwitterStreamFactory().getInstance();
    twitterStream.addListener(listener);
    twitterStream.setOAuthConsumer(consumerKey, consumerSecret);
    AccessToken token = new AccessToken(accessToken, accessTokenSecret);
    twitterStream.setOAuthAccessToken(token);

    if (keywords.length == 0) {
        logger.debug("Starting up Twitter sampling...");
        twitterStream.sample();
    } else {
        logger.debug("Starting up Twitter filtering...");
        FilterQuery query = new FilterQuery().track(keywords);
        twitterStream.filter(query);
    }
    this.sourceCounter.start();
    super.start();
}

From source file:org.vsepml.storm.twitter.StormTwitterHashtagSplitter.java

License:Apache License

@Override
public void execute(Tuple tuple) {
    Status tweet = (Status) tuple.getValueByField("tweet");
    HashtagEntity[] heTab = tweet.getHashtagEntities();
    for (int i = 0; i < heTab.length; i++)
        collector.emit(new Values(tweet.getGeoLocation(), heTab[i].getText()));
}

From source file:org.wandora.application.tools.extractors.twitter.AbstractTwitterExtractor.java

License:Open Source License

public Topic reifyTweet(Status t, TopicMap tm) {
    Topic tweetTopic = null;//  ww  w .j a  v  a  2 s  .co m
    try {
        long tId = t.getId();
        String msg = t.getText();
        User user = t.getUser();

        if (user == null) {
            tweetTopic = reifyTweet(tId, null, msg, tm);
        }

        else {
            String userScreenName = user.getScreenName();

            tweetTopic = reifyTweet(tId, userScreenName, msg, tm);

            Topic userTopic = reifyTwitterUser(user, tm);

            if (tweetTopic != null && userTopic != null) {
                Association a = tm.createAssociation(getTwitterFromUserType(tm));
                a.addPlayer(tweetTopic, getTweetType(tm));
                a.addPlayer(userTopic, getTwitterUserType(tm));
            }
        }

        /*
        String toUser = t.getToUser();
        if(toUser != null) {
        long toUid = t.getToUserId();       
        Topic toUserTopic = reifyTwitterUser(toUser, toUid, tm);
        if(tweetTopic != null && toUserTopic != null) {
            Association a = tm.createAssociation(getTwitterToUserType(tm));
            a.addPlayer(tweetTopic, getTweetType(tm));
            a.addPlayer(toUserTopic, getTwitterUserType(tm));
        }
        }
        */

        Date d = t.getCreatedAt();
        if (tweetTopic != null && d != null) {
            SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
            String dateStr = df.format(d);
            tweetTopic.setData(getTweetDateType(tm), TMBox.getLangTopic(tweetTopic, DEFAULT_LANG), dateStr);

            SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
            dateStr = sdf.format(d);
            Topic dateTopic = ExtractHelper.getOrCreateTopic(DATE_SI_BODY + dateStr, dateStr,
                    getTweetDateType(tm), tm);
            if (dateTopic != null) {
                Association a = tm.createAssociation(getTweetDateType(tm));
                a.addPlayer(tweetTopic, getTweetType(tm));
                a.addPlayer(dateTopic, getTweetDateType(tm));
            }
        }

        /*
        String l = t.getIsoLanguageCode();
        if(l != null) {
        Topic tweetLangTopic = TMBox.getLangTopic(tweetTopic, l);
        if(tweetLangTopic != null) {
            Association a = tm.createAssociation(getTweetLangType(tm));
            a.addPlayer(tweetTopic, getTweetType(tm));
            a.addPlayer(tweetLangTopic, getTweetLangType(tm));
        }
        }
        */

        GeoLocation geo = t.getGeoLocation();
        if (geo != null) {
            double lat = geo.getLatitude();
            double lon = geo.getLongitude();
            String geoLocStr = lat + "," + lon;
            tweetTopic.setData(getTweetGeoLocationType(tm), TMBox.getLangTopic(tweetTopic, DEFAULT_LANG),
                    geoLocStr);
        }

        HashtagEntity[] entities = t.getHashtagEntities();
        if (entities != null && entities.length > 0) {
            for (int i = 0; i < entities.length; i++) {
                Topic entityTopic = reifyHashtagEntity(entities[i], tm);
                if (entityTopic != null) {
                    Association a = tm.createAssociation(getHashtagType(tm));
                    a.addPlayer(tweetTopic, getTweetType(tm));
                    a.addPlayer(entityTopic, getHashtagType(tm));
                }
            }
        }

        MediaEntity[] mediaEntities = t.getMediaEntities();
        if (mediaEntities != null && mediaEntities.length > 0) {
            for (int i = 0; i < mediaEntities.length; i++) {
                Topic entityTopic = reifyMediaEntity(mediaEntities[i], tm);
                if (entityTopic != null) {
                    Association a = tm.createAssociation(getMediaEntityType(tm));
                    a.addPlayer(tweetTopic, getTweetType(tm));
                    a.addPlayer(entityTopic, getMediaEntityType(tm));
                }
            }
        }

        URLEntity[] urlEntities = t.getURLEntities();
        if (urlEntities != null && urlEntities.length > 0) {
            for (int i = 0; i < urlEntities.length; i++) {
                Topic entityTopic = reifyUrlEntity(urlEntities[i], tm);
                if (entityTopic != null) {
                    Association a = tm.createAssociation(getURLEntityType(tm));
                    a.addPlayer(tweetTopic, getTweetType(tm));
                    a.addPlayer(entityTopic, getURLEntityType(tm));
                }
            }
        }
    } catch (Exception e) {
        log(e);
    }
    return tweetTopic;
}

From source file:org.xmlsh.twitter.util.TwitterWriter.java

License:BSD License

public void write(Status t) throws XMLStreamException {
    startElement("tweet");
    attribute("id", t.getId());

    // write("annotations",t.getAnnotations());
    write("created-at", t.getCreatedAt());
    write("from-user", sanitizeID(t.getUser().getId()), sanitizeUser(t.getUser().getName()));
    write("geo-location", t.getGeoLocation());
    write("hash-tags", t.getHashtagEntities());
    write("iso-language-code", t.getUser().getLang());
    write("location", t.getUser().getLocation());
    write("media", t.getMediaEntities());
    write("place", t.getPlace());
    write("profile-image-url", sanitizeUser(t.getUser().getProfileImageURL()));
    write("source", t.getSource());
    write("text", t.getText());
    write("to-user", sanitizeID(t.getInReplyToUserId()), sanitizeUser(t.getInReplyToScreenName()));
    write("url-entities", t.getURLEntities());
    write("user-mention-entities", t.getUserMentionEntities());

    endElement();/*from w  w  w  .j av a 2s  .  c om*/

}

From source file:org.xmlsh.twitter.util.TwitterWriter.java

License:BSD License

public void write(String localName, Status status) throws XMLStreamException {
    if (status != null) {
        startElement(localName);/*from  ww  w  .java2  s  . c o  m*/
        attribute("id", status.getId());

        // write("annotations",t.getAnnotations());
        write("created-at", status.getCreatedAt());

        write("user", status.getUser());
        write("geo-location", status.getGeoLocation());
        write("hash-tags", status.getHashtagEntities());

        write("media", status.getMediaEntities());
        write("place", status.getPlace());

        write("source", status.getSource());
        write("text", status.getText());

        write("url-entities", status.getURLEntities());
        write("user-mention-entities", status.getUserMentionEntities());

        endElement();
    }
}

From source file:org.zoneproject.extractor.twitterreader.TwitterApi.java

License:Open Source License

/**
 * create an item by his twitter Status description, will add hashtags and others "metas"
 * @param s the twitter Status/*  w  w  w.  j av a  2 s .  c o  m*/
 * @param source the Uri of the source
 * @return the item created
 */
private static Item getItemFromStatus(Status s, String source) {
    String text = s.getText();
    if (s.isRetweet()) {
        text = s.getRetweetedStatus().getText();
    }
    Item res = new Item(source,
            "https://twitter.com/" + s.getUser().getScreenName() + "/status/" + Long.toString(s.getId()), text,
            text, s.getCreatedAt());
    String[] hashtags = getHashTags(res.getDescription());
    for (String hashtag : hashtags) {
        res.addProp(new Prop(ZoneOntology.PLUGIN_TWITTER_HASHTAG, hashtag, true, true));
    }
    for (String mentioned : TwitterApi.extractor.extractMentionedScreennames(s.getText())) {
        res.addProp(new Prop(ZoneOntology.PLUGIN_TWITTER_MENTIONED, "@" + mentioned, true, true));
    }
    if (s.getGeoLocation() != null) {
        res.addProp(new Prop(ZoneOntology.PLUGIN_TWITTER_POSITION_LONGITUDE,
                Double.toString(s.getGeoLocation().getLongitude()), true, true));
        res.addProp(new Prop(ZoneOntology.PLUGIN_TWITTER_POSITION_LATITUDE,
                Double.toString(s.getGeoLocation().getLatitude()), true, true));
    }
    res.addProp(new Prop(ZoneOntology.PLUGIN_TWITTER_AUTHOR, "@" + s.getUser().getScreenName(), true, true));
    return res;
}

From source file:spout.Twitter.java

License:Apache License

@Override
public void nextTuple() {
    Status ret = queue.poll();
    if (ret == null) {
        Utils.sleep(50);/*from  w ww.  j ava 2 s  .  c o m*/
    } else {

        Object[] values = new Object[this.fields.length];
        for (int i = 0; i < this.fields.length; i++) {
            if (this.fields[i].equalsIgnoreCase("place")) {
                values[i] = ret.getGeoLocation();
            } else if (this.fields[i].equalsIgnoreCase("retweet_count")) {
                values[i] = ret.getRetweetCount();
            } else if (this.fields[i].equalsIgnoreCase("text")) {
                values[i] = ret.getText();
            } else if (this.fields[i].equalsIgnoreCase("hashtags")) {
                values[i] = ret.getHashtagEntities();
            }

        }

        _collector.emit(new Values(values));

    }

}

From source file:testtweet.TweetUsingTwitter4jExample.java

/**
 * @param args the command line arguments
 *//*from   w  ww .  j a  v  a 2s  . c  o  m*/
public static void main(String[] args) throws IOException, TwitterException {

    //Instantiate a re-usable and thread-safe factory
    TwitterFactory twitterFactory = new TwitterFactory(Data.getConf().build());

    //Instantiate a new Twitter instance
    Twitter twitter = twitterFactory.getInstance();

    /*
    //setup OAuth Consumer Credentials
    twitter.setOAuthConsumer(consumerKey, consumerSecret);
            
    //setup OAuth Access Token
    twitter.setOAuthAccessToken(new AccessToken(accessToken, accessTokenSecret));
    */

    //Instantiate and initialize a new twitter status update
    StatusUpdate statusUpdate = new StatusUpdate(
            //your tweet or status message
            "Twitter API #Hacked");
    //attach any media, if you want to
    /*
    statusUpdate.setMedia(
    //title of media
    "http://h1b-work-visa-usa.blogspot.com"
    , new URL("http://lh6.ggpht.com/-NiYLR6SkOmc/Uen_M8CpB7I/AAAAAAAAEQ8/tO7fufmK0Zg/h-1b%252520transfer%252520jobs%25255B4%25255D.png?imgmax=800").openStream());
    */
    //tweet or update status
    Status status = twitter.updateStatus(statusUpdate);

    //response from twitter server
    System.out.println("status.toString() = " + status.toString());
    System.out.println("status.getInReplyToScreenName() = " + status.getInReplyToScreenName());
    System.out.println("status.getSource() = " + status.getSource());
    System.out.println("status.getText() = " + status.getText());
    System.out.println("status.getContributors() = " + Arrays.toString(status.getContributors()));
    System.out.println("status.getCreatedAt() = " + status.getCreatedAt());
    System.out.println("status.getCurrentUserRetweetId() = " + status.getCurrentUserRetweetId());
    System.out.println("status.getGeoLocation() = " + status.getGeoLocation());
    System.out.println("status.getId() = " + status.getId());
    System.out.println("status.getInReplyToStatusId() = " + status.getInReplyToStatusId());
    System.out.println("status.getInReplyToUserId() = " + status.getInReplyToUserId());
    System.out.println("status.getPlace() = " + status.getPlace());
    System.out.println("status.getRetweetCount() = " + status.getRetweetCount());
    System.out.println("status.getRetweetedStatus() = " + status.getRetweetedStatus());
    System.out.println("status.getUser() = " + status.getUser());
    System.out.println("status.getAccessLevel() = " + status.getAccessLevel());
    System.out.println("status.getHashtagEntities() = " + Arrays.toString(status.getHashtagEntities()));
    System.out.println("status.getMediaEntities() = " + Arrays.toString(status.getMediaEntities()));
    if (status.getRateLimitStatus() != null) {
        System.out
                .println("status.getRateLimitStatus().getLimit() = " + status.getRateLimitStatus().getLimit());
        System.out.println(
                "status.getRateLimitStatus().getRemaining() = " + status.getRateLimitStatus().getRemaining());
        System.out.println("status.getRateLimitStatus().getResetTimeInSeconds() = "
                + status.getRateLimitStatus().getResetTimeInSeconds());
        System.out.println("status.getRateLimitStatus().getSecondsUntilReset() = "
                + status.getRateLimitStatus().getSecondsUntilReset());
        System.out.println("status.getRateLimitStatus().getRemainingHits() = "
                + status.getRateLimitStatus().getRemaining());
    }
    System.out.println("status.getURLEntities() = " + Arrays.toString(status.getURLEntities()));
    System.out.println("status.getUserMentionEntities() = " + Arrays.toString(status.getUserMentionEntities()));
}

From source file:traffickarmasent.TweetCollection.java

public static void main(String[] args) throws FileNotFoundException, IOException, Exception {
    // loading slang dictionary with key as slang and value as its full form
    slangMap = new HashMap<String, String>();
    BufferedReader slangRead = new BufferedReader(new FileReader("extras/out.txt"));
    String line = "";
    while ((line = slangRead.readLine()) != null) {
        String parts[] = line.split("\t");
        slangMap.put(parts[0], parts[1]);
    }//ww  w.ja  v a2 s.co  m
    slangRead.close();

    //loading entity list
    BufferedReader htm_in = new BufferedReader(new FileReader("extras/html_ent.txt"));
    entityList = new ArrayList<String>();
    while ((line = htm_in.readLine()) != null) {
        entityList.add(line);
    }
    FileInputStream fos1 = new FileInputStream(new File("extras/hash1.dat")); // loading emoticon dictionary, with key as emoticon and value as its sentiment score
    ObjectInputStream out1 = new ObjectInputStream(fos1);
    emohash1 = (HashMap<String, Double>) out1.readObject();
    //System.out.println(hm1);

    FileInputStream fos2 = new FileInputStream(new File("extras/hash2.dat")); // loading emoticon dictionary, with key as emoticon and value as its sentiment score
    ObjectInputStream out2 = new ObjectInputStream(fos2);
    emohash2 = (HashMap<String, Double>) out2.readObject();
    //System.out.println(hm2);

    //loading senti-wordnet
    FileReader fr2 = new FileReader("extras/SentiWordNet_scores_final.txt");
    BufferedReader br2 = new BufferedReader(fr2);
    String str2;
    senti_map = new HashMap<String, Double>();
    while ((str2 = br2.readLine()) != null) {
        StringTokenizer st = new StringTokenizer(str2, "^");
        senti_map.put(st.nextToken(), Double.parseDouble(st.nextToken()));
    }

    String serializedClassifier = "english.all.3class.distsim.crf.ser.gz"; //NER configuration
    AbstractSequenceClassifier classifier = CRFClassifier.getClassifierNoExceptions(serializedClassifier);
    DocumentBuilder db = DocumentBuilderFactory.newInstance().newDocumentBuilder();
    InputSource is = new InputSource();

    MaxentTagger tagger = new MaxentTagger("taggers/english-left3words-distsim.tagger");

    ConfigurationBuilder cb = new ConfigurationBuilder();
    cb.setDebugEnabled(true);
    cb.setOAuthConsumerKey("ufulV3imKoYNzdh58LotTC1YD");
    cb.setOAuthConsumerSecret("2A781ma736HTenAXXYn9tRIelQYJkbCqY0GLi7W71ZwwDmNU59");
    cb.setOAuthAccessToken("2564905075-MY9osfHabaRnonQVHHhHeA1vCLSOhuHWjBNBiIY");
    cb.setOAuthAccessTokenSecret("JsD8Woc7iiFiDSwoCwjNAb6KNEurz7tBqSj9pJV8WXabr");
    twitter4j.TwitterStream twitterStream = new TwitterStreamFactory(cb.build()).getInstance();

    StatusListener listener = new StatusListener() {
        double score = 0.0;
        double count = 0;
        ArrayList<String> locArray = new ArrayList<String>();

        @Override

        public void onStatus(Status status) {
            String text = status.getText();

            double geoLat = 0.0;
            double geoLng = 0.0;
            String tweetId = status.getId() + "";
            String userName = status.getUser().getName();
            String userId = status.getUser().getId() + "";
            if (status.getGeoLocation() != null) {
                geoLat = status.getGeoLocation().getLatitude();
                geoLng = status.getGeoLocation().getLongitude();
            }

            tweetClean(text, status.getGeoLocation());
            System.out.println(text + "\n" + tweetId + " " + userName + " " + userId);

        }

        @Override
        public void onDeletionNotice(StatusDeletionNotice sdn) {
            throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
        }

        @Override
        public void onTrackLimitationNotice(int i) {
            throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
        }

        @Override
        public void onScrubGeo(long l, long l1) {
            throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
        }

        @Override
        public void onStallWarning(StallWarning sw) {
            throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
        }

        @Override
        public void onException(Exception excptn) {
            throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
        }

        public void tweetClean(String message, GeoLocation loc) {
            try {

                // URL removal 
                message = removeUrl(message);
                System.out.println("lalala" + message);
                //removing user mentions
                message = userMentions(message);
                //slang removal
                String[] acro = slangRemoval(message);
                //entity removal
                String[] finaldata = entityRemoval(acro);
                message = "";
                for (String word : finaldata) {
                    message += word + " ";
                }
                //System.out.println(message);
                //Ner Taggging
                String XmlData = classifier.classifyWithInlineXML(message);
                message = XmlData;

                //handling words to the spell_checked
                String[] data = message.split("<");
                String val = "";
                for (String word : data) {
                    if (word.startsWith("PER") || word.startsWith("LOC")) {
                        word = word.replaceAll("PERSON>", "");
                        word = word.replaceAll("/PERSON>", "");
                        word = word.replaceAll("LOCATION>", "");
                        word = word.replaceAll("/LOCATION>", "");
                        //insert word into database here 
                        locArray.add(word);
                    } else {
                        word = word.replaceAll("/PERSON>", "");
                        word = word.replaceAll("/LOCATION>", "");
                        //System.out.println(word);
                        val += word;
                    }
                }
                //System.out.println("see" + val);
                if (loc != null || locArray.size() > 0) {
                    val = val.replaceAll("\\s+", " ");
                    String[] temp = val.split(" ");
                    String match = "";
                    //spell_check
                    for (String word : temp) {
                        //System.out.println(word);
                        if (emohash2.containsKey(word)) {
                            score += emohash2.get(word);
                            count++;
                            message = message.replace(word, "");
                        }
                        Process p = Runtime.getRuntime().exec("python extras/text_blob.py " + word);
                        BufferedReader in = new BufferedReader(new InputStreamReader(p.getInputStream()));
                        //System.out.println(in.readLine());
                        match = in.readLine();
                        //match = spell_check(word);
                        //System.out.println(match);
                        if (!match.equals(word)) {
                            message = message.replaceAll(word, match);
                        }

                    }
                    System.out.println(message);
                    //UTF-8 emoji's
                    emojiDetection(message);
                    //handle NerTags
                    message = af_spellcheck(message);
                    //System.out.println(a);

                    //removing irrelevant chars         
                    message = removeChars(message);
                    //System.out.println(a);

                    //POS- TAGGING
                    message = posTagging(message);

                    // removing prepositions and nouns
                    message = removePrepn(message);
                    //System.out.println(a);

                    sentiScores(message);
                    System.out.println(score);
                    System.out.println(score / count);
                }

            } catch (Exception ex) {
                System.out.println(ex.getMessage());
            }

        }

        public String removeUrl(String message) {
            String urlPattern = "((https?|ftp|gopher|telnet|file|Unsure|http):((//)|(\\\\))+[\\w\\d:#@%/;$()~_?\\+-=\\\\\\.&]*)";
            Pattern p = Pattern.compile(urlPattern, Pattern.CASE_INSENSITIVE);
            Matcher m = p.matcher(message);
            int i = 0;
            while (m.find()) {
                message = message.replaceAll(m.group(i), "").trim();
                i++;
            }
            return message;
        }

        public String af_spellcheck(String message) {

            message = message.replaceAll("<PERSON>", "");
            message = message.replaceAll("</PERSON>", "");
            message = message.replaceAll("<LOCATION>", "");
            message = message.replaceAll("</LOCATION>", "");
            return message;
        }

        public String removeChars(String message) {

            message = message.replaceAll("\\.", "");
            message = message.replaceAll("\\!", "");
            message = message.replaceAll("\\$", "");
            message = message.replaceAll("\\%", "");
            message = message.replaceAll("\\^", "");
            message = message.replaceAll("\\|", "");
            message = message.replaceAll("\\+", "");
            message = message.replaceAll("\\:", "");
            message = message.replaceAll("\\(", "");
            message = message.replaceAll("\\)", "");
            message = message.replaceAll("\\*", "");
            message = message.replaceAll("\\{", "");
            return message;
        }

        public void sentiScores(String message) {

            message = message.replaceAll("_NNS", "_n");
            message = message.replaceAll("_NN", "_n");
            message = message.replaceAll("_RBR", "_r");
            message = message.replaceAll("_RBS", "_r");
            message = message.replaceAll("_RB", "_r");
            message = message.replaceAll("_JJR", "_a");
            message = message.replaceAll("_JJS", "_a");
            message = message.replaceAll("_JJ", "_a");
            message = message.replaceAll("_VBD", "_v");
            message = message.replaceAll("_VBG", "_v");
            message = message.replaceAll("_VBN", "_v");
            message = message.replaceAll("_VBP", "_v");
            message = message.replaceAll("_VBZ", "_vs");
            message = message.replaceAll("_VB", "_v");

            message = message.replaceAll("\\s+", " ");
            // System.out.println(message);
            String[] senti_token = message.split(" ");

            for (String word : senti_token) {
                word = word.toLowerCase();
                System.out.println(word);
                if (senti_map.containsKey(word)) {

                    score += senti_map.get(word);
                    //System.out.println(score);
                    count++;
                }

            }

        }

        public void emojiDetection(String message) {
            Pattern emo = Pattern.compile("[\\uD83D\\uDE01-\\uD83D\\uDE4F]");
            Matcher m_emo = emo.matcher(message);
            while (m_emo.find()) {
                if (emohash1.containsKey(m_emo.group())) //System.out.println("llalala");
                {
                    score += emohash1.get(m_emo.group());
                }
                count++;
            }
        }

        public String userMentions(String message) {
            Pattern p = Pattern.compile("\\@\\w+");
            Matcher m = p.matcher(message);
            while (m.find()) {
                //System.out.println(m.group());
                message = message.replaceAll(m.group(), "");
            }
            return message;

        }

        public String[] slangRemoval(String message) {
            ArrayList<String> slangRemovalList = new ArrayList<String>();
            String[] words = message.split(" ");
            for (String single : words) {
                if (slangMap.containsKey(single.toUpperCase())) {
                    slangRemovalList.add(slangMap.get(single.toUpperCase()));
                } else {
                    slangRemovalList.add(single);
                }
            }
            String[] myArray = new String[slangRemovalList.size()];
            slangRemovalList.toArray(myArray);
            return myArray;
        }

        public String posTagging(String message) throws Exception {

            String tagged = tagger.tagString(message);

            return tagged;
        }

        public String removePrepn(String message) {
            String delims = " ";
            String[] tokens = message.split(delims);
            for (String word : tokens) {
                if (word.endsWith("_IN") || word.endsWith("_NNP") || word.endsWith("_NNPS")) {
                    message = message.replace(word, "");
                }

            }
            return message;
        }

        public String[] entityRemoval(String[] message) {
            List<String> finalList = new ArrayList<String>();
            for (String word : message) {
                if (!entityList.contains(word.trim())) {
                    finalList.add(word);
                }
            }
            String[] myArray = new String[finalList.size()];
            finalList.toArray(myArray);
            return myArray;
        }

    };
    FilterQuery fq = new FilterQuery();

    String keywords[] = { "Mumbai traffic", "@TrafflineMUM", "TrafficMum", "MumbaiTrafficPol",
            "avoid traffic Mumbai", "Breakdown Mumbai traffic", "@smart_mumbaikar", "@TrafficBOM",
            "#StreetSmartWithTraffline mumbai", "#mumbai #TRAFFICALERT ", "#mumbai #TRAFFIC" };

    fq.track(keywords);
    twitterStream.addListener(listener);
    twitterStream.filter(fq);
}