-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path4_Analyses_articles_Nature_Science.R
74 lines (58 loc) · 1.89 KB
/
4_Analyses_articles_Nature_Science.R
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
# analyses scientific corpus =>
# only opinion/perspectives in Nature and Science
# Query = PhD student OR PhD cancidate in title
# n = 93 papiers
# remove obituaries
# some papers were in image format => not included for now
rm(list=ls())
library(dplyr)
library(tidyr)
library(ggplot2)
library(wordcloud)
library(reshape2)
library(syuzhet)
library(qdap)
library(tidytext)
# install.packages("pdftools")
# library(pdftools)
# setwd(dir = paste0(getwd(), "/data_pdf"))
# files <- list.files(pattern = "pdf$")
#
# papers_pdf <- lapply(files, pdf_text)
#
# papers_pdf[[5]]
# files
# => ne fonctionne aps bien pbm de police de certains pdf
# + bcp sont inclus avec d'autres papiers dans le meme pdf
# ça aurait diminué la pertience de la sélection
papers_excel <- read.csv("data_pdf/all_papers_filtered.csv", sep = ";")
papers_to_keep <- papers_excel %>%
filter(integration=="oui") %>%
distinct()
papers_to_keep[duplicated(papers_to_keep$title),"title"]
abs_text <- papers_to_keep$text
abs_title <- papers_to_keep$title
plain_text <- iconv(abs_text, from="UTF-8", to="ASCII", sub="")
plain_text_stm <- get_sentiment(plain_text, method = "bing")
plain_text_nrc <- get_nrc_sentiment(plain_text)
length(which(plain_text_stm<0))
length(which(plain_text_stm>0))
abs_words <- papers_to_keep %>%
select(text) %>%
unnest_tokens(word, text) %>%
anti_join(stop_words)
abs_words %>%
inner_join(get_sentiments("bing")) %>%
count(word, sentiment, sort = TRUE) %>%
acast(word ~ sentiment, value.var = "n", fill = 0) %>%
comparison.cloud(colors = c("firebrick", "chartreuse3"),
max.words = 100)
nb_stmt <- abs_words %>%
inner_join(get_sentiments("bing")) %>%
count(word, sentiment, sort = TRUE)
table(nb_stmt$sentiment)
nb_stmt %>% group_by(sentiment) %>% summarise(total = sum(n), mean = mean(n))
hist(nb_stmt$n)
abs_words %>%
count(word) %>%
with(wordcloud(word, n, max.words = 150))