【发布时间】:2021-11-29 23:26:18
【问题描述】:
我使用来自 twitter 的 python 进行情感分析来判断它是消极的、积极的还是中性的,代码如下:
hasilAnalisis = []
for tweets in hasilUser:
tweets_properties = {}
tweets_properties['tanggal_tweet'] = tweets.created_at
tweets_properties['pengguna'] = tweets.user.screen_name
tweets_properties['isi_tweet'] = tweets.text
tweets_full_cleansing = ' '.join(re.sub("(@[A-Za-z0-9]+)|([^0-9A-Za-z \t])|(\w+:\/\/\S+)"," ",tweets.text).split())
analysis = TextBlob(tweets_full_cleansing)
try:
analysis = analysis.translate(to='en')
except Exception as e:
print(e)
if analysis.sentiment.polarity > 0.0:
tweets_properties["sentimen"] = "positif"
elif analysis.sentiment.polarity == 0.0:
tweets_properties["sentimen"] = "Netral"
else:
tweets_properties["sentimen"] = "Negatif"
if tweets.retweet_count > 0:
if tweets_properties not in hasilAnalisis:
hasilAnalisis.append(tweets_properties)
else:
hasilAnalisis.append(tweets_properties)
问题是,由于我要查找的推文是印度尼西亚语,所以我必须先使用此代码将其翻译成英文
try:
analysis = analysis.translate(to='en')
except Exception as e:
print(e)
之后代码可以根据情绪来判断或评估,因为已经转换为英文并且可以完成analysis.sentiment.polarity。
有没有什么办法可以在不先翻译成英文的情况下做到这一点?
基于此https://ksnugroho.medium.com/dasar-text-preprocessing-dengan-python-a4fa52608ffe
我可以使用sastrawi 进行标记化,但不知道如何在印度尼西亚语中使用情感极性。
【问题讨论】:
标签: python tokenize sentiment-analysis