【发布时间】:2016-03-02 09:44:04
【问题描述】:
我正在从各种网站提取评论并将它们存储在一个文件中,然后在 senti-wordnet 的帮助下将每个句子分类为正面或负面(它给出了某些分数)。我使用的是 python 2.7。我不知道它对存储在文件中的评论是如何工作的。有人知道python中的代码吗?
f1=open("foodP.txt","r")
word_features =[]
words = []
for line in f1:
word_features.append(line)
s=str(word_features)
tokens=nltk.word_tokenize(s)
for i,j in nltk.pos_tag(tokens):
if j in ['VBN','VBP','VB','JJ', 'JJR', 'JJS', 'RB', 'RBR', 'RBS']:
words.append(i)
print words
这段代码只会给出我需要的形容词、副词和动词。我想将这些词分类为正面或负面。
【问题讨论】:
-
请发布您尝试过的代码。您写的消息正是您想要的,但到目前为止您已经尝试过的,是本论坛所需要的。
-
我已经发布了我现在使用的代码。
标签: python sentiment-analysis pos-tagger senti-wordnet