-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathagile-rr-yearly-textanalysis.Rmd
571 lines (451 loc) · 17.6 KB
/
agile-rr-yearly-textanalysis.Rmd
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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
---
title: 'Text-analysis and visualisations for AGILE conference papers 2018-2019'
author: "Daniel Nüst"
date: "`r format(Sys.time(), '%Y-%m-%d')`"
output:
html_document:
df_print: paged
toc: yes
abstract: Text analysis of [AGILE conference](https://agile-online.org/conference/) papers - source code at [https://github.com/nuest/reproducible-research-and-giscience](https://github.com/nuest/reproducible-research-and-giscience).
---
## Prerequisites
### Software dependencies
This document does not install the required R packages by default.
You can run the script `install.R` to install all required dependencies on a new R installation, or use `install.packages(..)` to install missing R packages.
```{r install_r, eval=FALSE}
source("install.R")
```
The text analysis is based the R package [`tidytext`](https://cran.r-project.org/package=tidytext) from the [`tidyverse`](https://www.tidyverse.org/) suite of packages and uses the [`dplyr`](http://dplyr.tidyverse.org/) grammar.
Read the [`tidytext` tutorial](https://cran.r-project.org/web/packages/tidytext/vignettes/tidytext.html) to learn about the used functions and concepts.
The plots and tables of survey data and evaluation use the packages [`ggplot2`](http://ggplot2.tidyverse.org/).
Required libraries and runtime environment description.
```{r load_libraries, echo=TRUE, message=FALSE, warning=FALSE}
library("pdftools")
library("stringr")
library("knitr")
library("tibble")
library("tidytext")
library("purrr")
library("dplyr")
library("wordcloud")
library("RColorBrewer")
library("readr")
library("ggplot2")
library("rvest")
library("ggthemes")
library("grid")
library("gridBase")
library("gridExtra")
library("devtools")
library("rlang")
library("huxtable")
library("here")
library("httr")
library("googledrive")
library("SnowballC")
```
### Seed
Seed is set for making word cloud generation reproducible.
```{r seed}
set.seed(1)
```
### Data
```{r data_path}
data_path <- "all-manuscripts"
```
The data for the analysis is required in form of directories with PDF files of all conference papers and poster abstracts.
Due to copyright of full papers, the full paper PDFs must be manually added to the respective directory.
Short papers and poster abstracts are dowloaded automatically.
Add the PDFs to a directory called ` `r data_path` ` this file with one subdirectoy per year:
```{r years}
list.files("all-manuscripts/")
```
The following downloads of AGILE short papers are _not_ executed by default.
```{r data_2018,eval=FALSE}
dir.create(here::here(data_path, "2018"))
page <- read_html("https://agile-online.org/programme-2018/accepted-papers-and-posters-2018")
all_links <- page %>%
html_nodes(css = "a") %>%
html_attr("href") %>%
as.list()
drive_links <- all_links[str_detect(string = all_links, pattern = "drive.google")]
drive_links[sapply(drive_links, is.null)] <- NULL
drive_ids <- lapply(drive_links, as_id)
lapply(drive_ids, drive_download, overwrite = TRUE)
```
```{r data_2019,eval=FALSE}
dir.create(here::here(data_path, "2019"))
page <- read_html("https://agile-online.org/conference-2019/programme-2019/accepted-papers-and-posters-2019")
all_links <- page %>%
html_nodes(css = "a") %>%
html_attr("href") %>%
as.list()
pdf_links <- all_links[str_detect(string = all_links, pattern = ".*Upload_your_PDF.*")]
pdf_links[sapply(pdf_links, is.null)] <- NULL
pdf_links <- paste0("https://agile-online.org", pdf_links)
for (link in pdf_links) {
download.file(url = link,
destfile = here::here(data_path,
"2019",
stringr::str_extract(link, "([^/]+$)")))
}
```
## 2018
### Loading and cleaning
```{r load_filenames_2018}
files_2018 <- dir(path = here::here(data_path, "2018"), pattern = ".pdf$", full.names = TRUE)
```
This analysis was created with the following `r length(files_2018)` documents:
```{r list_files_2018,echo=FALSE}
# remove base name
sapply(X = files_2018, FUN = stringr::str_remove, USE.NAMES = FALSE, pattern = here::here(data_path, "2018"))
```
Count the types of submissions:
```{r manuscript_counts_2018}
full_papers_2018 <- length(str_match(files_2018, "10.100")[!is.na(str_match(files_2018, "10.100"))])
other_papers_2018 <- length(str_match(files_2018, "10.100")[is.na(str_match(files_2018, "10.100"))])
```
There are `r full_papers_2018` full papers and `r other_papers_2018` short papers/posters.
Read the data from PDFs and preprocess to create a [tidy](https://www.jstatsoft.org/article/view/v059i10) data structure without [stop words](https://en.wikipedia.org/wiki/Stop_words):
```{r stop_words}
my_stop_words <- tibble(
word = c(
"et",
"al",
"fig",
"e.g",
"i.e",
"http",
"ing",
"pp",
"figure",
"table",
"based",
"lund", # location of conference 2018
"https"
),
lexicon = "agile"
)
all_stop_words <- stop_words %>%
bind_rows(my_stop_words)
```
```{r tidy_data_2018}
texts <- lapply(files_2018, pdf_text)
texts <- unlist(lapply(texts, str_c, collapse = TRUE))
infos <- lapply(files_2018, pdf_info)
make_id <- function(files) {
str_extract(files, "([^/]+$)")
}
tidy_texts_2018 <- tibble(id = make_id(files_2018),
file = files_2018,
text = texts,
pages = map_chr(infos, function(info) {info$pages}))
papers_words <- tidy_texts_2018 %>%
select(file, text) %>%
unnest_tokens(word, text)
suppressWarnings({
no_numbers <- papers_words %>%
filter(is.na(as.numeric(word)))
})
no_stop_words_2018 <- no_numbers %>%
anti_join(all_stop_words, by = "word") %>%
mutate(id = make_id(file))
# https://github.com/juliasilge/tidytext/issues/17
no_stop_stems_2018 <- no_stop_words_2018 %>%
mutate(word_stem = wordStem(word))
```
About `r round(nrow(no_stop_words_2018)/nrow(papers_words) * 100)` % of the words are considered stop words.
There are `r length(unique(no_stop_stems_2018$word_stem))` unique word stems of `r length(unique(no_stop_words_2018$word))` words.
_How many non-stop words does each document have?_
```{r stop_words_2018}
no_stop_words_2018 %>%
group_by(id) %>%
summarise(words = n()) %>%
arrange(desc(words))
```
### Text analysis
_How often do the following terms on reproducible research appear in each paper?_
The detection matches full words using regex option `\b`.
- reproduc (`reproduc.*`, reproducibility, reproducible, reproduce, reproduction)
- replic (`replicat.*`, i.e. replication, replicate)
- repeatab (`repeatab.*`, i.e. repeatability, repeatable)
- software
- (pseudo) code/script(s) [column name _code_]
- algorithm (`algorithm.*`, i.e. algorithms, algorithmic)
- process (`process.*`, i.e. processing, processes, preprocessing)
- data (`data.*`, i.e. dataset(s), database(s))
- result(s)
- repository(ies)
```{r keywords_per_paper_2018}
tidy_texts_2018_lower <- str_to_lower(tidy_texts_2018$text)
word_counts <- tibble(
id = tidy_texts_2018$id,
`reproduc..` = str_count(tidy_texts_2018_lower, "\\breproduc.*\\b"),
`replic..` = str_count(tidy_texts_2018_lower, "\\breplicat.*\\b"),
`repeatab..` = str_count(tidy_texts_2018_lower, "\\brepeatab.*\\b"),
`code` = str_count(tidy_texts_2018_lower, "(\\bcode\\b|\\bscript.*\\b|\\bpseudo\ code\\b)"),
`software` = str_count(tidy_texts_2018_lower, "\\bsoftware\\b"),
`algorithm(s)` = str_count(tidy_texts_2018_lower, "\\balgorithm.*\\b"),
`(pre)process..` = str_count(tidy_texts_2018_lower, "(\\bprocess.*\\b|\\bpreprocess.*\\b|\\bpre-process.*\\b)"),
`data.*` = str_count(tidy_texts_2018_lower, "\\bdata.*\\b"),
`result(s)` = str_count(tidy_texts_2018_lower, "\\bresults?\\b"),
`repository/ies` = str_count(tidy_texts_2018_lower, "\\brepositor(y|ies)\\b")
) %>%
mutate(all = rowSums(.[-1]))
word_counts_sums_total_2018 <- word_counts %>%
summarise_if(is.numeric, funs(sum)) %>%
add_column(id = "Total", .before = 0)
rbind(word_counts, word_counts_sums_total_2018)
```
_What are top used words (not stems)?_
```{r top_words_2018}
countPapersUsingWord <- function(the_word) {
sapply(the_word, function(w) {
no_stop_words_2018 %>%
filter(word == w) %>%
group_by(id) %>%
count %>%
nrow
})
}
top_words_2018 <- no_stop_words_2018 %>%
group_by(word) %>%
tally %>%
arrange(desc(n)) %>%
head(20) %>%
mutate(`# papers` = countPapersUsingWord(word)) %>%
add_column(place = c(1:nrow(.)), .before = 0)
top_words_2018
```
_What are the top word stems?_
```{r top_stems_2018}
countPapersUsingStem <- function(the_stem) {
sapply(the_stem, function(s) {
no_stop_stems_2018 %>%
filter(word_stem == s) %>%
group_by(id) %>%
count %>%
nrow
})
}
top_stems_2018 <- no_stop_stems_2018 %>%
group_by(word_stem) %>%
tally %>%
arrange(desc(n)) %>%
head(20) %>%
mutate(`# papers` = countPapersUsingStem(word_stem)) %>%
add_column(place = c(1:nrow(.)), .before = 0)
top_stems_2018
```
### Word cloud based on word stems
```{r plot_function}
wordStemPlot <- function(word_stem_data, top_stem_data, year, minimum_occurence, fp_count, op_count) {
cloud_words <- word_stem_data %>%
group_by(word_stem) %>%
tally %>%
filter(n >= minimum_occurence) %>%
arrange(desc(n))
def.par <- par(no.readonly = TRUE)
par(mar = rep(0,4))
layout(mat = matrix(data = c(1,2,3,4), nrow = 2, ncol = 2, byrow = TRUE),
widths = c(lcm(8),lcm(8)),
heights = c(lcm(2),lcm(11)))
# -> nf
#layout.show(nf)
plot.new()
text(0.5, 0.5, paste0("Word stem cloud of AGILE ", year, " Submissions"), font = 2)
text(0.5, 0.15, paste0("Based on ", fp_count, " full papers and ", op_count, " short papers/posters.\n",
"Showing ", nrow(cloud_words), " of ", sum(cloud_words$n),
" word stems occuring at least ", minimum_occurence, " times."), font = 1, cex = 0.7)
plot.new()
text(0.5, 0.5, paste0("Top word stems of AGILE ", year, " Submissions"), font = 2)
text(0.5, 0.15, paste0("Code available at https://github.com/nuest/\nreproducible-research-and-giscience"), font = 1, cex = 0.7)
wordcloud(cloud_words$word_stem, cloud_words$n,
max.words = Inf,
random.order = FALSE,
fixed.asp = FALSE,
rot.per = 0,
color = brewer.pal(8,"Dark2"))
frame() # thx to https://stackoverflow.com/a/25194694/261210
vps <- baseViewports()
pushViewport(vps$inner, vps$figure, vps$plot)
grid.table(as.matrix(top_stem_data),
theme = ttheme_minimal(base_size = 11,
padding = unit(c(10,5), "pt"))
)
popViewport(3)
par(def.par)
}
```
```{r plot_2018,dpi=600,fig.width=7,fig.asp=0.85}
# minimum occurence manually tested so that all words could be plotted
wordStemPlot(no_stop_stems_2018, top_stems_2018, "2018", 200, full_papers_2018, other_papers_2018)
```
--------
## 2019
### Loading and cleaning
```{r load_filenames_2019}
files_2019 <- dir(path = here::here(data_path, "2019"), pattern = ".pdf$", full.names = TRUE)
```
This analysis was created with the following `r length(files_2019)` documents:
```{r list_files_2019,echo=FALSE}
# remove base name
sapply(X = files_2019, FUN = stringr::str_remove, USE.NAMES = FALSE, pattern = here::here(data_path, "2019"))
```
Count the types of submissions:
```{r manuscript_counts_2019}
full_papers_2019 <- length(str_match(files_2019, "10.100")[!is.na(str_match(files_2019, "10.100"))])
other_papers_2019 <- length(str_match(files_2019, "10.100")[is.na(str_match(files_2019, "10.100"))])
```
Read the data from PDFs and preprocess to create a [tidy](https://www.jstatsoft.org/article/view/v059i10) data structure without [stop words](https://en.wikipedia.org/wiki/Stop_words):
```{r tidy_data_2019}
texts <- lapply(files_2019, pdf_text)
texts <- unlist(lapply(texts, str_c, collapse = TRUE))
infos <- lapply(files_2019, pdf_info)
tidy_texts_2019 <- tibble(id = make_id(files_2019),
file = files_2019,
text = texts,
pages = map_chr(infos, function(info) {info$pages}))
papers_words <- tidy_texts_2019 %>%
select(file, text) %>%
unnest_tokens(word, text)
suppressWarnings({
no_numbers <- papers_words %>%
filter(is.na(as.numeric(word)))
})
no_stop_words_2019 <- no_numbers %>%
anti_join(all_stop_words, by = "word") %>%
mutate(id = make_id(file))
# https://github.com/juliasilge/tidytext/issues/17
no_stop_stems_2019 <- no_stop_words_2019 %>%
mutate(word_stem = wordStem(word))
```
About `r round(nrow(no_stop_words_2019)/nrow(papers_words) * 100)` % of the words are considered stop words.
There are `r length(unique(no_stop_stems_2019$word_stem))` unique word stems of `r length(unique(no_stop_words_2019$word))` words.
**Note:** In the original paper corpus there was an issue with reading in one paper, which only had 1 word, `10.1007@978-3-030-14745-710.pdf`.
Since it was not possible to copy or extract text, it was send through an OCR process (using [OCRmyPDF](https://github.com/jbarlow83/OCRmyPDF)) and the original file renamed to `10.1007@978-3-030-14745-710__pdf`:
```{bash ocr_2019,eval=FALSE}
docker run -v $(pwd)/all-manuscripts/2019:/home/docker -it jbarlow83/ocrmypdf --force-ocr 10.1007@978-3-030-14745-710.pdf 10.1007@978-3-030-14745-710_ocr.pdf
mv all-manuscripts/2019/10.1007@978-3-030-14745-710.pdf all-manuscripts/2019/10.1007@978-3-030-14745-710pdf.orig
```
_How many non-stop words does each document have?_
```{r stop_words_2019}
no_stop_words_2019 %>%
group_by(id) %>%
summarise(words = n()) %>%
arrange(desc(words))
```
### Text analysis
_How often do the following terms on reproducible research appear in each paper?_
The detection matches full words using regex option `\b`.
- reproduc (`reproduc.*`, reproducibility, reproducible, reproduce, reproduction)
- replic (`replicat.*`, i.e. replication, replicate)
- repeatab (`repeatab.*`, i.e. repeatability, repeatable)
- software
- (pseudo) code/script(s) [column name _code_]
- algorithm (`algorithm.*`, i.e. algorithms, algorithmic)
- process (`process.*`, i.e. processing, processes, preprocessing)
- data (`data.*`, i.e. dataset(s), database(s))
- result(s)
- repository(ies)
```{r keywords_per_paper_2019}
tidy_texts_2019_lower <- str_to_lower(tidy_texts_2019$text)
word_counts <- tibble(
id = tidy_texts_2019$id,
`reproduc..` = str_count(tidy_texts_2019_lower, "\\breproduc.*\\b"),
`replic..` = str_count(tidy_texts_2019_lower, "\\breplicat.*\\b"),
`repeatab..` = str_count(tidy_texts_2019_lower, "\\brepeatab.*\\b"),
`code` = str_count(tidy_texts_2019_lower, "(\\bcode\\b|\\bscript.*\\b|\\bpseudo\ code\\b)"),
`software` = str_count(tidy_texts_2019_lower, "\\bsoftware\\b"),
`algorithm(s)` = str_count(tidy_texts_2019_lower, "\\balgorithm.*\\b"),
`(pre)process..` = str_count(tidy_texts_2019_lower, "(\\bprocess.*\\b|\\bpreprocess.*\\b|\\bpre-process.*\\b)"),
`data.*` = str_count(tidy_texts_2019_lower, "\\bdata.*\\b"),
`result(s)` = str_count(tidy_texts_2019_lower, "\\bresults?\\b"),
`repository/ies` = str_count(tidy_texts_2019_lower, "\\brepositor(y|ies)\\b")
) %>%
mutate(all = rowSums(.[-1]))
word_counts_sums_total_2019 <- word_counts %>%
summarise_if(is.numeric, funs(sum)) %>%
add_column(id = "Total", .before = 0)
rbind(word_counts, word_counts_sums_total_2019)
```
_What are top used words (not stems)?_
```{r top_words_2019}
countPapersUsingWord <- function(the_word) {
sapply(the_word, function(w) {
no_stop_words_2019 %>%
filter(word == w) %>%
group_by(id) %>%
count %>%
nrow
})
}
top_words_2019 <- no_stop_words_2019 %>%
group_by(word) %>%
tally %>%
arrange(desc(n)) %>%
head(20) %>%
mutate(`# papers` = countPapersUsingWord(word)) %>%
add_column(place = c(1:nrow(.)), .before = 0)
top_words_2019
```
_What are the top word stems?_
```{r top_stems_2019}
countPapersUsingStem <- function(the_stem) {
sapply(the_stem, function(s) {
no_stop_stems_2019 %>%
filter(word_stem == s) %>%
group_by(id) %>%
count %>%
nrow
})
}
top_stems_2019 <- no_stop_stems_2019 %>%
group_by(word_stem) %>%
tally %>%
arrange(desc(n)) %>%
head(20) %>%
mutate(`# papers` = countPapersUsingStem(word_stem)) %>%
add_column(place = c(1:nrow(.)), .before = 0)
top_stems_2019
```
### Word cloud based on word stems
```{r plot_2019,dpi=600,fig.width=7,fig.asp=0.85}
# minimum occurence manually tested so that all words could be plotted
wordStemPlot(no_stop_stems_2019, top_stems_2019, "2019", 145, full_papers_2019, other_papers_2019)
```
## Reproducibility keywords per year - absolute
```{r keywords_per_year_abs}
keywords_2018 <- word_counts_sums_total_2018
keywords_2019 <- word_counts_sums_total_2019
names(keywords_2018)[[1]] <- names(keywords_2019)[[1]] <- "year"
keywords_2018$year <- "2018"
keywords_2019$year <- "2019"
rbind(keywords_2018, keywords_2019)
```
## Reproducibility keywords per year - per paper
```{r keywords_per_year_per_paper}
cbind(year = c("2018", "2019"),
round(rbind(
dplyr::bind_cols(keywords_2018[-(1)] / (full_papers_2018 + other_papers_2018)),
dplyr::bind_cols(keywords_2019[-(1)] / (full_papers_2019 + other_papers_2019))
), digits = 2)
)
```
## Reproducibility keywords per year - per 1000 words
```{r keywords_per_year_per_word}
cbind(year = c("2018", "2019"),
round(rbind(
dplyr::bind_cols(keywords_2018[-(1)] / nrow(no_stop_words_2018) * 1000),
dplyr::bind_cols(keywords_2019[-(1)] / nrow(no_stop_words_2019) * 1000)
), digits = 2)
)
```
--------
## License
This document is licensed under a [Creative Commons Attribution 4.0 International License](https://creativecommons.org/licenses/by/4.0/).
All contained code is licensed under the [Apache License 2.0](https://choosealicense.com/licenses/apache-2.0/).
## Metadata
```{r session_info}
devtools::session_info(include_base = TRUE)
```