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 = []
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!
SDude source share