【问题标题】:How to edit NLTKs VADER sentiment lexicon without modifying a txt file如何在不修改 txt 文件的情况下编辑 NLTKs VADER 情感词典
【发布时间】:2018-04-16 17:57:10
【问题描述】:

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

from nltk.sentiment.vader import SentimentIntensityAnalyzer as SIA

sia = SIA()
sia.lexicon

这将得到字典。想的是这样的:

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

【问题讨论】:

    标签: python nltk sentiment-analysis vader


    【解决方案1】:

    对于其他人:

    from nltk.sentiment.vader import SentimentIntensityAnalyzer
    
    new_words = {
        'foo': 2.0,
        'bar': -3.4,
    }
    
    SIA = SentimentIntensityAnalyzer()
    
    SIA.lexicon.update(new_words)
    

    【讨论】:

      【解决方案2】:

      我想这就是答案。

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

      【讨论】:

        猜你喜欢
        • 2017-03-21
        • 1970-01-01
        • 2016-08-23
        • 2018-11-25
        • 2019-10-17
        • 2012-11-02
        • 2018-12-01
        • 1970-01-01
        • 2018-02-05
        相关资源
        最近更新 更多