Как сделать анализ настроений с помощью Python и библиотеки AFINN из данных Twitter?
ВОПРОС ЗАКЛЮЧАЕТСЯ В СЛЕДУЮЩЕМ:
Find out the views of different people on the demonetization by analysing the tweets from twitter. Use the Twitter API to extract all tweets related to demonetisation in India by using appropriate filters. Divide each tweet text into words to calculate the sentiment of the whole tweet. Rate the word as per its meaning from +5 to -5 using the dictionary AFINN. The AFINN is a dictionary which consists of 2500 words which are rated from +5 to -5 depending on their meaning. You can download the dictionary from the following link: **AFINN dictionary ( https://drive.google.com/file/d/1AjcJCNH2Oc9j-bJgjdELaUMlWZ3pXyfZ/view )** Now, you have to generate a sentiment rating for each tweet. After that, perform the sentiment analysis by filtering out positive sentiment tweets from negative sentiment tweets.
Что я уже пробовал:
Я извлек данные twitter, которые находятся в формате JSON. Но я не знаю, как действовать дальше, так как не знаю о JSON. Может ли кто-нибудь дать мне код о том, что делать дальше?
import tweepy import json import time #Twitter API credentials consumer_key = "tUnfouXORfnaVNEAyTrLmW2ZU" consumer_secret = "Yxmd1sLKqp2YwXzJ5IJjaVO6PtrOeq1lKyl5AS2Zu2zktjYZKQ" access_key = "1215780002-2fC55jHbZ4X7NDHgKFJMO1g63Aw0jn1zdmhJjs8" access_secret = "MJfwXrZ9hKvfb8EUba7eoKlu5BIPDwRDKAXHZOBPdPc2p" auth = tweepy.OAuthHandler(consumer_key, consumer_secret) auth.set_access_token(access_key, access_secret) api = tweepy.API(auth, wait_on_rate_limit=True, wait_on_rate_limit_notify=True) #refer http://docs.tweepy.org/en/v3.2.0/api.html#API #tells tweepy.API to automatically wait for rate limits to replenish #Put your search term searchquery = "#Demonetisation" users =tweepy.Cursor(api.search,q=searchquery).items() count = 0 errorCount=0 file = open('search.json', 'w') while True: try: user = next(users) count += 1 #use count-break during dev to avoid twitter restrictions #if (count>10): # break except tweepy.TweepError: #catches TweepError when rate limiting occurs, sleeps, then restarts. #nominally 15 minnutes, make a bit longer to avoid attention. print ("sleeping....") user = next(users) except StopIteration: break try: print ("Writing to JSON tweet number:"+str(count)) json.dump(user._json,file,sort_keys = True,indent = 4) except UnicodeEncodeError: errorCount += 1 print ("UnicodeEncodeError,errorCount ="+str(errorCount)) print ("completed, errorCount ="+str(errorCount)+" total tweets="+str(count))