textblob.sentiments只给出积极的情绪

时间:2015-12-01 18:34:14

标签: python twitter sentiment-analysis textblob

我开始使用textblob(0.11)进行python(2.7)的情感分析程序。 我从twitter获取推文并解码json以从推文中提取文本,然后将此文本提供给情感分析代码。 代码工作正常,但每次都会将情绪输出为“pos”。对于许多显然是否定的文本,该程序将情绪显示为“Pos”

import tweepy
import json
import csv
import textblob
import unicodedata
from tweepy import Stream
from tweepy.streaming import StreamListener
from textblob.sentiments import NaiveBayesAnalyzer
import sys
consumer_key = ''
consumer_secret = ''
access_token = ''
access_token_secret = ''

class listener(StreamListener):

def on_data(self,data):
    decoded = json.loads(data)
   decoded=decoded['text']
    print decoded

   blob = textblob.TextBlob(decoded, analyzer=NaiveBayesAnalyzer())
    print (blob.sentiment)


def on_error(self,status):
    print status


if __name__ == '__main__':

auth = tweepy.OAuthHandler(consumer_key, consumer_secret)
auth.set_access_token(access_token, access_token_secret)

api = tweepy.API(auth)

def on_error(self,status):
    print status


twitterStream = Stream(auth,listener())

twitterStream.filter(track=["#Trend"])

请帮助

0 个答案:

没有答案