情感分析 R syuzhet NRC Word-Emotion Association Lexicon [英] Sentiment analysis R syuzhet NRC Word-Emotion Association Lexicon

查看:32
本文介绍了情感分析 R syuzhet NRC Word-Emotion Association Lexicon的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

How do you find the associated words to the eight basic emotions (anger, fear, anticipation, trust, surprise, sadness, joy, and disgust) (NRC Word-Emotion Association Lexicon) when using get_nrc_sentiment of the using the syuzhet package?

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) 

例如我们可以在 a_sent 中看到一个词被归类为愤怒,但是我们如何找到那个词是什么?因此,我想列出示例中的所有情绪和相关术语.

e.g. we can see in a_sent that one term has been classified as anger, but how do we find what that term was? So I want to list all the sentiments and the terms associated in my example.

谢谢.

推荐答案

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)

这篇关于情感分析 R syuzhet NRC Word-Emotion Association Lexicon的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆