knitr::include_graphics("C:\\Users\\vicca\\OneDrive\\Documentos\\Imagenes\\4-emoties-3.gif")

Análisis Himno Nacional

Cargar texto

library("syuzhet")

archivo<- "C:\\Users\\vicca\\OneDrive\\Documentos\\7mo\\DATOS\\himnonacional.txt"

himno<- readLines(archivo)
## Warning in readLines(archivo): incomplete final line found on
## 'C:\Users\vicca\OneDrive\Documentos\7mo\DATOS\himnonacional.txt'

Tokenizar texto

texto <- get_tokens(himno)

head(texto)
## [1] "mexicanos" "al"        "grito"     "de"        "guerra"    "el"
length(texto)
## [1] 288
oracionesvector  <- get_sentences(himno)
length(oracionesvector)
## [1] 66

Analisis de sentimientos

df<- get_nrc_sentiment(texto, language = "spanish")
summary(df)
##      anger          anticipation        disgust             fear       
##  Min.   :0.00000   Min.   :0.00000   Min.   :0.00000   Min.   :0.0000  
##  1st Qu.:0.00000   1st Qu.:0.00000   1st Qu.:0.00000   1st Qu.:0.0000  
##  Median :0.00000   Median :0.00000   Median :0.00000   Median :0.0000  
##  Mean   :0.08333   Mean   :0.02431   Mean   :0.01736   Mean   :0.1076  
##  3rd Qu.:0.00000   3rd Qu.:0.00000   3rd Qu.:0.00000   3rd Qu.:0.0000  
##  Max.   :2.00000   Max.   :2.00000   Max.   :1.00000   Max.   :2.0000  
##       joy             sadness           surprise           trust        
##  Min.   :0.00000   Min.   :0.00000   Min.   :0.00000   Min.   :0.00000  
##  1st Qu.:0.00000   1st Qu.:0.00000   1st Qu.:0.00000   1st Qu.:0.00000  
##  Median :0.00000   Median :0.00000   Median :0.00000   Median :0.00000  
##  Mean   :0.04167   Mean   :0.06597   Mean   :0.03472   Mean   :0.03819  
##  3rd Qu.:0.00000   3rd Qu.:0.00000   3rd Qu.:0.00000   3rd Qu.:0.00000  
##  Max.   :2.00000   Max.   :1.00000   Max.   :2.00000   Max.   :2.00000  
##     negative         positive      
##  Min.   :0.0000   Min.   :0.00000  
##  1st Qu.:0.0000   1st Qu.:0.00000  
##  Median :0.0000   Median :0.00000  
##  Mean   :0.1285   Mean   :0.09722  
##  3rd Qu.:0.0000   3rd Qu.:0.00000  
##  Max.   :2.0000   Max.   :2.00000

Graficar resultados

library(RColorBrewer)
barplot(colSums(prop.table(df[,1:8])),
  space = 0.2,
  horiz = FALSE,
  las = 1,
  cex.names = 0.7,
  col = brewer.pal(n=8, name="Set3"),
  main = "Himno nacional análisis",
  xlab = "Emociones")

Profundizar

palabrasmiedo<- texto[df$fear >0]
palabrasmiedoorden<- sort(table(unlist(palabrasmiedo)), decreasing = TRUE)
head(palabrasmiedoorden, n=10)
## 
##  guerra   grito  sangre destino    dios enemigo 
##      10       4       3       1       1       1

Graficar resultados

secuenciasentimientos <- (df$negative*-1) + (df$positive)
simple_plot(secuenciasentimientos)

Análisis Novela Miau

Cargar texto

library("syuzhet")
novela <- scan(file = "https://raw.githubusercontent.com/programminghistorian/jekyll/gh-pages/assets/galdos_miau.txt", fileEncoding = "UTF-8", what = character(), sep = "\n", allowEscapes = T)

Tokenizar texto

texto2 <- get_tokens(novela)

head(texto2)
## [1] "miau"   "por"    "b"      "pérez"  "galdós" "14"
length(texto2)
## [1] 97254
oracionesvector  <- get_sentences(texto2)
length(oracionesvector)
## [1] 97254

Análisis de sentimientos

sdf <- get_nrc_sentiment(texto2, language = "spanish")
summary(sdf)
##      anger          anticipation        disgust             fear        
##  Min.   :0.00000   Min.   :0.00000   Min.   :0.00000   Min.   :0.00000  
##  1st Qu.:0.00000   1st Qu.:0.00000   1st Qu.:0.00000   1st Qu.:0.00000  
##  Median :0.00000   Median :0.00000   Median :0.00000   Median :0.00000  
##  Mean   :0.01596   Mean   :0.02114   Mean   :0.01263   Mean   :0.02243  
##  3rd Qu.:0.00000   3rd Qu.:0.00000   3rd Qu.:0.00000   3rd Qu.:0.00000  
##  Max.   :5.00000   Max.   :3.00000   Max.   :6.00000   Max.   :5.00000  
##       joy             sadness           surprise           trust        
##  Min.   :0.00000   Min.   :0.00000   Min.   :0.00000   Min.   :0.00000  
##  1st Qu.:0.00000   1st Qu.:0.00000   1st Qu.:0.00000   1st Qu.:0.00000  
##  Median :0.00000   Median :0.00000   Median :0.00000   Median :0.00000  
##  Mean   :0.01929   Mean   :0.02564   Mean   :0.01035   Mean   :0.03004  
##  3rd Qu.:0.00000   3rd Qu.:0.00000   3rd Qu.:0.00000   3rd Qu.:0.00000  
##  Max.   :5.00000   Max.   :7.00000   Max.   :2.00000   Max.   :3.00000  
##     negative          positive      
##  Min.   :0.00000   Min.   :0.00000  
##  1st Qu.:0.00000   1st Qu.:0.00000  
##  Median :0.00000   Median :0.00000  
##  Mean   :0.04658   Mean   :0.05153  
##  3rd Qu.:0.00000   3rd Qu.:0.00000  
##  Max.   :7.00000   Max.   :5.00000
head(sdf)
##   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     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

Graficar resultados

library(RColorBrewer)
barplot(colSums(prop.table(sdf[,1:8])),
  space = 0.2,
  horiz = FALSE,
  las = 1,
  cex.names = 0.7,
  col = brewer.pal(n=8, name="Set3"),
  main = "Análisis Novela Miau",
  xlab = "Emociones"
)

Profundizar analisis

palabrasconfianza<- texto2[sdf$trust >0]
palabrasconfianzaorden<- sort(table(unlist(palabrasconfianza)), decreasing = TRUE)
head(palabrasconfianzaorden, n=10)
## 
##    dios   amigo   padre  abuelo   hecho  puerta  verdad   bueno palabra iglesia 
##     142      97      77      69      56      53      51      41      41      37

Graficar resultados

secuencia <- (sdf$negative*-1) + (sdf$positive)
simple_plot(secuencia)