如何在不修改txt文件的情况下编辑NLTK的VADER情感词典 [英] How to edit NLTKs VADER sentiment lexicon without modifying a txt file
本文介绍了如何在不修改txt文件的情况下编辑NLTK的VADER情感词典的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我知道您可以通过将自己的单词手动添加到vader_lexicon.txt文件中来添加自己的单词.我想知道是否还有另一种方法可以在python代码中执行此操作,因为我不希望使用我的代码的人需要再修改其他.txt文件.
I know you can add your own words by manually adding them to the vader_lexicon.txt file. I was wondering if there was another way that you can do it in the python code as I don't want people who use my code need to then go modify other .txt files.
from nltk.sentiment.vader import SentimentIntensityAnalyzer as SIA
sia = SIA()
sia.lexicon
这将得到命令.在想类似的东西:
This will get the dict. Was thinking something like:
sia.lexicon.update{u'word': 3}
推荐答案
对于其他任何人:
from nltk.sentiment.vader import SentimentIntensityAnalyzer
new_words = {
'foo': 2.0,
'bar': -3.4,
}
SIA = SentimentIntensityAnalyzer()
SIA.lexicon.update(new_words)
这篇关于如何在不修改txt文件的情况下编辑NLTK的VADER情感词典的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文