Reputation: 43
Working on analyzing some comments using R Studio. I'm using Bing Sentiment lexicon from tidytext package right now.
I have some additional words that I wish to add to Bing (runtime or offline). For instance I can add them with level of positivity or negativity or any other sentiment. How can I do that?
Upvotes: 4
Views: 1246
Reputation: 16277
sentiment
is a tibble
, so adding new words is simply an 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
Upvotes: 2