我提取了一大套JSON文件,需要更改代码以打印列表中所有JSON文件中的文本,然后通过情感分析器运行它们。然后,我需要将这些文本文件输入到Vader情绪分析器中,以创建情绪极性值的列表。
我试图在单个推特上迭代当前可打印并运行情感分析器的功能,但是我需要一种有效的方法来处理特定主题上的100多个推特。
import tweepy
import json
from vaderSentiment.vaderSentiment import SentimentIntensityAnalyzer
analyser = SentimentIntensityAnalyzer()
auth=tweepy.OAuthHandler(consumer_key, consumer_secret)
auth.set_access_token(access_key, access_secret)
## Builds the API Call
api=tweepy.API(auth, parser=tweepy.parsers.JSONParser())
## Here is where you define the parameters of your search. The full documentation is available here: https://developer.twitter.com/en/docs/api-reference-index
searchquery = '"Mueller" -filter:retweets'
data=api.search(q=searchquery, count=1000, lang='en', result_type='mixed')
###in python 3.6 data.values is not iterable so you need to define it with a list, which I have done with the variabel v
v=list(data.values())
###a test to make sure that we are saving data and we can search the json file by datatypes
### This prints the text for the 12th tweet in the dataset
print(v[0][12]['text'])
###Now we are building the senitment analyzer
###This runs the vader senitment analysis on the frist tweet in my dataset
print(analyser.polarity_scores(v[0][12]['text']))
我想用这段代码作为概念验证,以演示如何衡量Twitter上某个主题的情绪。我想为我的推文列表打印情感极性得分,然后用它们来计算该主题的平均情感评分。