El anĂ¡lisis de sentimientos, o minerĂa de opiniĂ³n, es utilizado para extraer de forma automĂ¡tica informaciĂ³n sobre la connotaciĂ³n positiva o negativa del lenguaje de un documento.
El anĂ¡lisis mostrarĂ¡ el resultado de 8 emociones bĂ¡sicas y 2
sentimientos.
Emociones BĂ¡sicas:
1. AlegrĂa (joy).
2. Tristeza (sadness).
3. Ira (anger).
4. Sorpresa (surprise).
5. Asco (disgust).
6. Miedo (fear).
7. AnticipaciĂ³n (anticipation).
8. Confianza (trust).
Sentimientos:
1. Positivo (positive).
2. Negativo (negative).
# install.packages("syuzhet")
library(syuzhet)
# install.packages("RColorBrewer")
library(RColorBrewer)
# file.choose()
texto_cadena <- read.delim("/Users/KarlaCastillo/Desktop/Datos/eltriste.txt", header = FALSE)
texto_palabras <- get_tokens(texto_cadena)
head(texto_palabras)
## [1] "c" "quĂ©" "triste" "fue" "decirnos" "adiĂ³s"
length(texto_palabras)
## [1] 183
sentimientos_df <- get_nrc_sentiment(texto_palabras, language = "spanish")
# Idiomas disponibles: spanish, english, french, german, italian, portuguese, etc.
head(sentimientos_df)
## anger anticipation disgust fear joy sadness surprise trust negative positive
## 1 0 0 0 0 0 0 0 0 0 0
## 2 0 0 0 0 0 0 0 0 0 0
## 3 1 0 1 2 0 5 0 0 5 0
## 4 0 0 0 0 0 0 0 0 0 0
## 5 0 0 0 0 0 0 0 0 0 0
## 6 0 0 0 0 0 0 0 0 0 0
# 1 es menos presente, y 5 es mĂ¡s presente
barplot(
colSums(prop.table(sentimientos_df[,1:8])),
space = 0.2,
horiz = FALSE,
las = 1,
cex.names = 0.7,
col = brewer.pal(n=8, name="Set3"),
main="AnĂ¡lisis de sentimientos de la canciĂ³n El Triste",
xlab = "Emociones"
)
palabras_tristeza <- texto_palabras[sentimientos_df$sadness >0]
palabras_tristeza_orden <- sort(table(unlist(palabras_tristeza)), decreasing = TRUE)
head(palabras_tristeza_orden, n=10)
##
## triste dolor azul gris soledad
## 4 2 1 1 1
secuencia_sentimientos <- (sentimientos_df$negative*-1)+sentimientos_df$positive
simple_plot(secuencia_sentimientos)
# file.choose()
texto_himno <- read.delim("/Users/KarlaCastillo/Desktop/Datos/himnomexicano.txt", header = FALSE)
texto_himnopalabras <- get_tokens(texto_himno)
head(texto_himnopalabras)
## [1] "c" "mexicanos" "al" "grito" "de" "guerra"
length(texto_himnopalabras)
## [1] 497
sentimientos_himno <- get_nrc_sentiment(texto_himnopalabras, language = "spanish")
# Idiomas disponibles: spanish, english, french, german, italian, portuguese, etc.
head(sentimientos_himno)
## anger anticipation disgust fear joy sadness surprise trust negative positive
## 1 0 0 0 0 0 0 0 0 0 0
## 2 0 0 0 0 0 0 0 0 0 0
## 3 0 0 0 0 0 0 0 0 0 0
## 4 2 0 0 1 0 1 2 0 2 0
## 5 0 0 0 0 0 0 0 0 0 0
## 6 1 0 0 2 0 1 0 0 2 0
# 1 es menos presente, y 5 es mĂ¡s presente
barplot(
colSums(prop.table(sentimientos_himno[,1:8])),
space = 0.2,
horiz = FALSE,
las = 1,
cex.names = 0.7,
col = brewer.pal(n=8, name="Set3"),
xlab = "Emociones Himno Nacional"
)
palabras_fear <- texto_palabras[sentimientos_himno$fear >0]
palabras_fear_orden <- sort(table(unlist(palabras_tristeza)), decreasing = TRUE)
head(palabras_fear_orden, n=10)
##
## triste dolor azul gris soledad
## 4 2 1 1 1
secuenciah_sentimientos <- (sentimientos_himno$negative*-1)+sentimientos_himno$positive
simple_plot(secuenciah_sentimientos)