使用TextBlob进行荷兰语情感分析

问题描述 投票:1回答:1

我想对基于特定关键字获取的推文列表进行情感分析。传入的推文主要是荷兰语,TextBlob需要将它们转换为英文才能计算出推文的极性和主观性值。如何将推文转换为英语?我基本上需要一个免费的API来进行翻译。使用MS Bing转换器时遇到问题。我尝试使用goslatelangdetecttranslatetranslation库,但是它们都不起作用。这是我正在使用的代码:

#!/usr/bin/env python
import tweepy
import goslate
from langdetect import detect
from translation import baidu, google, youdao, iciba
from translate import Translator
import os
import time
import sys
reload(sys)
sys.setdefaultencoding('utf-8')
t=time.time()
#karan's api keys 
consumer_key = 'xxx'
consumer_secret = 'xxx'
access_key = 'xxx'
access_secret = 'xxx'

gs=goslate.Goslate()
translator= Translator(to_lang="en")
auth = tweepy.OAuthHandler(consumer_key, consumer_secret)
auth.set_access_token(access_key, access_secret)
api = tweepy.API(auth)
search_results = api.search(q="football", count=2, geocode="52.132633,5.2912659999999505,300km")
f=open('tweets_football.txt','wb')

for i in range(0,len(search_results)):
    try:
        print search_results[i].text        
        print search_results[i].id
        print search_results[i].user.screen_name
        trans=search_results[i].text
        #print(gs.translate(trans,'en'))
        print(translator.translate(trans))
        if search_results[i].text not in search_results:
            f.write(search_results[i].text)
            f.write("\n")
            print "Written to file!"
    except Exception as e:
         print str(e)



f.close()
print time.time()-t

请指出正确的方向。如果有更简单的方法来进行此处理,请也建议这样做。预先感谢。

python-2.7 twitter translation sentiment-analysis textblob
1个回答
0
投票

您可以尝试此代码:

来自翻译导入翻译从googletrans导入翻译器

text ='hallo_allemaal'

entext = Translator()。translate(text,src ='nl',dest ='en')。text

print(entext)

Google API对来自一个IP的匹配数有一些限制。如果收到该错误。也可以查看。

© www.soinside.com 2019 - 2024. All rights reserved.