0

我知道您可以通过手动将它们添加到 vader_lexicon.txt 文件来添加自己的单词。我想知道是否有另一种方法可以在 python 代码中执行此操作,因为我不希望使用我的代码的人需要修改其他 .txt 文件。

from nltk.sentiment.vader import SentimentIntensityAnalyzer as SIA

sia = SIA()
sia.lexicon

这将得到字典。正在考虑类似的事情:

sia.lexicon.update{u'word': 3}
4

2 回答 2

2

对于其他任何人:

from nltk.sentiment.vader import SentimentIntensityAnalyzer

new_words = {
    'foo': 2.0,
    'bar': -3.4,
}

SIA = SentimentIntensityAnalyzer()

SIA.lexicon.update(new_words)
于 2018-05-01T14:17:04.130 回答
0

我想这就是答案。

 sia.lexicon.update({u'word': 3.1})
于 2018-04-16T18:58:36.847 回答