簡體   English   中英

在R中添加新詞到Bing情感Lexicon

[英]Add new words to Bing sentiment Lexicon in R

使用R Studio分析一些注釋。 我現在正在使用來自tidytext包的Bing Sentiment詞典。

我還有一些其他的話要添加到Bing(運行時或離線)。 例如,我可以添加積極性或消極性或任何其他情緒。 我怎樣才能做到這一點?

sentiment是一種tibble ,因此添加新詞簡直是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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM