【发布时间】:2020-09-01 14:29:37
【问题描述】:
我想使用 python 对 COVID-19 主题进行情感分析。问题出现了,像“positive testing”这样的条目接收一个正极性,尽管这个声明是一个否定声明。我目前的代码如下:
import nltk
from textblob import TextBlob
from nltk.stem import WordNetLemmatizer
# Setting the test string
test_string = "He was tested positive on Covid-19"
tokens = nltk.word_tokenize(test_string)
# Lemmatizer
wordnet_lemmatizer = WordNetLemmatizer()
tokens_lem_list = []
for word in tokens:
lem_tokens = wordnet_lemmatizer.lemmatize(word, pos="v")
tokens_lem_list.append(lem_tokens)
# List to string
tokens_lem_str = ' '.join(tokens_lem_list)
# Print the polarity of the string
print(TextBlob(tokens_lem_str).sentiment.polarity)
输出如下:
0.22727272727272727
Process finished with exit code 0
因此,我想删除标记“test”和“positive”,如果它们一起使用,并用单词“ill”替换它们。我应该使用循环还是只会用大量文本消耗我的计算能力?
非常感谢您的帮助!
【问题讨论】:
-
您的具体问题是什么?关于将
positive test或test positive改成disease的代码,或者关于时间复杂度问题? -
而是第一个。但我已经解决了。感谢您的留言。 :)
标签: python nlp nltk token sentiment-analysis