Mood analysis receives tweets matching the search query and analysis

I want to do a sentiment analysis on Twitter. I don’t want to store any of the tweets, but do an analysis on them, for example, tweets that say positive things about a particular hashtag, etc. The problem I have here is that access to tweets is too slow. What will be the access to tweets and their analysis, as well as the results for the user. Good example: http://www.sentiment140.com/search?query=hello&hl=en

Despite the fact that the guy in the above link accepts only 10 tweets and analyzes them. I want to know how I can do this to access the api so that the user can respond quickly.

Even this is a good example: http://snapbird.org/ Even if I know how I can access tweets and automatically analyze them without having to store them anywhere, it would be an ideal solution.

Please note that I am just asking how you can access tweets without storage so that I can directly analyze for users and display in my web application.

+6
source share
3 answers

Sentiment140 is located in the GoogleApp Engine, so you can bet they use Python to complete the task. Python is really good at this and has excellent libraries for Sentiment Analysis (NLTK) and consumes twitter APIs. There are also great tutorials. You can do the following:

  • Take the last N tweets for your keyword (with tweepy lib). The given example.
  • Store them in an array
  • Pass the array to a Bayesian classifier built using Python NLTK [see links]
  • Get real-time analysis result
  • Submit them to the user if you want (in the Django / Flask template, etc.)


Getting N tweets from twitter API

Tweepy example (returns the last 10 tweets with the keyword "Lionel Messi")

#!/usr/bin/env python import tweepy ckey = 'xxx' csecret = 'xxx' atoken = 'xxx' asecret = 'xxx' auth = tweepy.OAuthHandler(ckey, csecret) auth.set_access_token(atoken, asecret) api = tweepy.API(auth) tweets = [] # You pass this array to the Bayesian Classifier for tweet in tweepy.Cursor(api.search, q="Lionel Messi", result_type="recent", include_entities=True, lang="en").items(10): print tweet.created_at, tweet.text tweets.append(tweet.text) # Store the tweets in your array 


Building a naive Bayes classifier

Examples of creating your classifier and good resources:

http://ravikiranj.net/drupal/201205/code/machine-learning/how-build-twitter-sentiment-analyzer https://github.com/ravikiranj/twitter-sentiment-analyzer

Please keep in mind that you will have to train and fine tune the bots / classifiers. You have additional information and boilerplate code in these resources.

PS: Alternatively, you can pass your array / dict tweets to services like the text-processing.com API, and they will do a mood analysis for you ...

http://text-processing.com/demo/sentiment/
https://www.mashape.com/japerk/text-processing/pricing#!documentation


Display results on a simple website

You can use flask-tweepy for this task. Just read their demo and you will see how easy it is to include the above scripts inside the flask and display the results in the view.


Hope this helps!

+6
source

You want to use the Twitter Streaming API .

With this, you can get a real-time feed from Twitter, filtered to any text text you want.

You will not need to make multiple queries or save the results; just flow and analysis.

+5
source
 1) You have to go for some realtime engine like twitter strom api 2) strom has twitter spout(which connects to twitter and pull the tweets) 3) write your own bolt which can take a tweet and perform sentiment and throw(publish) the result to some Q mechanism(like Rabbitmq) 4) from your web app consume the Q(so no persistent layer required here). 5) for sentiment engine, you have to write some Machine learning classifier. 

Hope answered your question.

+1
source

All Articles