情绪分析R syuzhet NRC Word-Emotion Association Lexicon

时间:2018-03-04 08:08:37

标签: text-mining sentiment-analysis corpus

当使用使用syuzhet包的get_nrc_sentiment时,如何找到八种基本情绪(愤怒,恐惧,期待,信任,惊讶,悲伤,喜悦和厌恶)(NRC Word-Emotion Association Lexicon)的关联词语?

a <- c("I hate going to work it is dull","I love going to work it is fun")

a_corpus = Corpus(VectorSource(a))

a_tm <- TermDocumentMatrix(a_corpus)

a_tmx <- as.matrix(a_tm)

a_df<-data.frame(text=unlist(sapply(a, `[`)), stringsAsFactors=F)

a_sent<-get_nrc_sentiment(a_df$text) 

e.g。我们可以在a_sent中看到一个术语被归类为愤怒,但我们如何找到该术语的含义?所以我想列出我的例子中的所有情绪和相关术语。

感谢。

1 个答案:

答案 0 :(得分:0)

library(tidytext)

library(tm)

a <- c("I hate going to work it is dull","I love going to work it is fun")

a_corpus = Corpus(VectorSource(a))

a_tm <- TermDocumentMatrix(a_corpus)

a_tmx <- as.matrix(a_tm)

a_df<-data.frame(text=unlist(sapply(a, `[`)), stringsAsFactors=F)

a_sent<-get_nrc_sentiment(a_df$text) 

lexicon <- get_sentiments("nrc")

v <- sort(rowSums(a_tmx),decreasing=TRUE)

d <- data.frame(word = names(v),freq=v)

# List the words in common between the text provided and NRC lexicon
intersect(lexicon$word, d$word)

# Show the words in common and their sentiments
s <- cbind(lexicon$word[lexicon$word%in%d$word], lexicon$sentiment[lexicon$word%in%d$word])

print(s)