How to edit NLTKs VADER sentiment lexicon without modifying a txt file

旧街凉风 提交于 2019-12-10 11:58:45

问题


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}

回答1:


For anyone else:

from nltk.sentiment.vader import SentimentIntensityAnalyzer

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

SIA = SentimentIntensityAnalyzer()

SIA.lexicon.update(new_words)



回答2:


I think this is the answer.

 sia.lexicon.update({u'word': 3.1})


来源:https://stackoverflow.com/questions/49863520/how-to-edit-nltks-vader-sentiment-lexicon-without-modifying-a-txt-file

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!