Présentation du package sentometrics d'analyse chronologique de sentiments
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

103 lines
2.5KB

  1. ---
  2. title: "Analyse BD"
  3. author: "François Pelletier"
  4. date: "07/10/2019"
  5. output: html_document
  6. ---
  7. ```{r setup, include=FALSE}
  8. knitr::opts_chunk$set(echo = TRUE)
  9. ```
  10. ```{r}
  11. library("sentometrics")
  12. library("tidyverse")
  13. library("plotly")
  14. ```
  15. ```{r}
  16. core_features_corpus.RDS <- readRDS("core_features_corpus.RDS")
  17. top_10_country <- readRDS("top_10_country.RDS")
  18. top_10_sites <- readRDS("top_10_sites.RDS")
  19. corpusSample <- quanteda::corpus_sample(core_features_corpus.RDS, size = 200)
  20. ```
  21. # Définition des lexiques
  22. ```{r}
  23. data("list_valence_shifters", package = "sentometrics")
  24. data("list_lexicons", package = "sentometrics")
  25. lexIn <- list_lexicons[c("FEEL_en_tr")]
  26. valIn <- list_valence_shifters[["en"]]
  27. l1 <- sento_lexicons(lexIn,valIn)
  28. ```
  29. # Calcul des sentiments
  30. ```{r}
  31. c_sentiments_sample <- compute_sentiment(x = corpusSample,
  32. lexicons = l1,
  33. how = "counts",
  34. nCore = 8)
  35. c_sentiments_sample
  36. ```
  37. ```{r}
  38. c_control_compute <- ctr_agg(howWithin = "proportional",
  39. howDocs = "equal_weight",
  40. howTime = "equal_weight",
  41. lag = 7,
  42. by = "day")
  43. c_sentiments <- sento_measures(sento_corpus = core_features_corpus.RDS,
  44. lexicons = l1,
  45. ctr = c_control_compute)
  46. ```
  47. ```{r}
  48. c_measures <- as.data.table(c_sentiments)
  49. ```
  50. ```{r}
  51. c_measures_g <- measures_global(c_sentiments)
  52. ```
  53. # Sentiment par site
  54. ```{r}
  55. c_measures_melt <- c_measures %>%
  56. select(date,starts_with("FEEL_en_tr--site")) %>%
  57. `colnames<-`(c("date",top_10_sites$site)) %>%
  58. melt(id="date",variable.name = "site")
  59. plot_site <- ggplot(data=c_measures_melt,
  60. aes(x=date, y=value, colour=site))+
  61. geom_line()
  62. ggplotly(plot_site)
  63. ```
  64. # Sentiment par pays
  65. ```{r}
  66. c_measures_melt <- c_measures %>%
  67. select(date,starts_with("FEEL_en_tr--country")) %>%
  68. `colnames<-`(c("date",top_10_country$country)) %>%
  69. melt(id="date",variable.name = "country")
  70. plot_country <- ggplot(data=c_measures_melt,
  71. aes(x=date, y=value, colour=country))+
  72. geom_line()
  73. ggplotly(plot_country)
  74. ```
  75. # Sentiment par compteur d'entités
  76. ```{r}
  77. c_measures_melt <- c_measures %>%
  78. select(date,starts_with("FEEL_en_tr--entity")) %>%
  79. melt(id="date",variable.name = "entity")
  80. plot_entity <- ggplot(data=c_measures_melt,
  81. aes(x=date, y=value, colour=entity))+
  82. geom_line()
  83. ggplotly(plot_entity)
  84. ```