【问题标题】:Add new words to Bing sentiment Lexicon in R将新词添加到 R 中的 Bing 情感词典
【发布时间】:2017-11-20 01:20:24
【问题描述】:

正在使用 R Studio 分析一些 cmets。我现在正在使用 tidytext 包中的 Bing Sentiment 词典。

我有一些额外的词要添加到必应(运行时或离线)。例如,我可以将它们添加为积极或消极或任何其他情绪的水平。我该怎么做?

【问题讨论】:

    标签: r rstudio tidytext


    【解决方案1】:

    sentimenttibble,所以添加新词只是 rbind

    additional_sentiment <- tibble(word=c("verygood","verybad"),
                                   sentiment=c("positive","negative"))
    
    new_sentiment <- get_sentiments("bing")%>%
                        rbind(additional_sentiment)
    
    tail(new_sentiment)
    # A tibble: 6 x 2
          word sentiment
         <chr>     <chr>
    1   zenith  positive
    2     zest  positive
    3    zippy  positive
    4   zombie  negative
    5 verygood  positive
    6  verybad  negative
    
    joined <- austen_books() %>%
      unnest_tokens(word, text) %>%
      left_join(new_sentiment)
    
    head(joined[!is.na(joined$sentiment),])
    # A tibble: 6 x 3
                     book        word sentiment
                   <fctr>       <chr>     <chr>
    1 Sense & Sensibility respectable  positive
    2 Sense & Sensibility        good  positive
    3 Sense & Sensibility    advanced  positive
    4 Sense & Sensibility       death  negative
    5 Sense & Sensibility       great  positive
    6 Sense & Sensibility        loss  negative
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-07-25
      • 2018-06-07
      • 2023-03-10
      相关资源
      最近更新 更多