根据Textblob在Python中的极性从Textblob中获取正负词(情感分析)

2024-06-07 12:02:17 发布

您现在位置:Python中文网/ 问答频道 /正文

我有一个文本blob,在这个blob中,如果极性大于等于0,则将文本分类为正;如果极性为0,则将其分为中性;如果为负,则将其分类。 我怎样才能得到正、负或中性的词呢?在


Tags: 文本分类blob中性极性
1条回答
网友
1楼 · 发布于 2024-06-07 12:02:17

希望以下代码能对您有所帮助:

from textblob import TextBlob
from textblob.sentiments import NaiveBayesAnalyzer
import nltk
nltk.download('movie_reviews')
nltk.download('punkt')

text          = "I feel the product is so good" 

sent          = TextBlob(text)
# The polarity score is a float within the range [-1.0, 1.0]
# where negative value indicates negative text and positive
# value indicates that the given text is positive.
polarity      = sent.sentiment.polarity
# The subjectivity is a float within the range [0.0, 1.0] where
# 0.0 is very objective and 1.0 is very subjective.
subjectivity  = sent.sentiment.subjectivity

sent          = TextBlob(text, analyzer = NaiveBayesAnalyzer())
classification= sent.sentiment.classification
positive      = sent.sentiment.p_pos
negative      = sent.sentiment.p_neg

print(polarity,subjectivity,classification,positive,negative)

相关问题 更多 >

    热门问题