【发布时间】:2013-08-07 15:10:37
【问题描述】:
我正在学习 Python,并试图用它来进行情绪分析。我正在关注此链接中的在线教程:http://www.alex-hanna.com/tworkshops/lesson-6-basic-sentiment-analysis/。我取了一段代码作为映射器类,摘录如下:
sentimentDict = {
'positive': {},
'negative': {}
}
def loadSentiment():
with open('Sentiment/positive_words.txt', 'r') as f:
for line in f:
sentimentDict['positive'][line.strip()] = 1
with open('Sentiment/negative_words.txt', 'r') as f:
for line in f:
sentimentDict['negative'][line.strip()] = 1
在这里,我可以看到创建了一个新字典,其中包含正负两个键,但没有值。
随后,打开两个文本文件,每行都被剥离并映射到字典。
但是,= 1 部分是做什么用的?为什么需要这样做(如果不是,如何删除?)
【问题讨论】:
标签: python mapreduce nltk sentiment-analysis