Um die Transkriptionen in R herunterzuladen und zu analysieren, benötigen wir die folgenden packages.

#install.packages('youtubecaption')
library(youtubecaption)
library(quanteda)
## Package version: 2.1.2
## Parallel computing: 2 of 4 threads used.
## See https://quanteda.io for tutorials and examples.
## 
## Attaching package: 'quanteda'
## The following object is masked from 'package:utils':
## 
##     View
library(tidyverse)
## ── Attaching packages ─────────────────────────────────────── tidyverse 1.3.0 ──
## ✓ ggplot2 3.3.3     ✓ purrr   0.3.4
## ✓ tibble  3.0.5     ✓ dplyr   1.0.3
## ✓ tidyr   1.1.2     ✓ stringr 1.4.0
## ✓ readr   1.4.0     ✓ forcats 0.5.0
## ── Conflicts ────────────────────────────────────────── tidyverse_conflicts() ──
## x dplyr::filter() masks stats::filter()
## x dplyr::lag()    masks stats::lag()

1.) Im ersten Schritt laden wir die Untertitel herunter.

url <- "https://www.youtube.com/watch?v=WAlP39a5LUU"
caption <- get_caption(url, language ="de")
caption

2. Im zweiten Schritt erstellen wir aus dem Text einen Korpus

my_corpus <- corpus(caption$text)
summary(my_corpus)

3.) Erstellung einer erweiterten Liste von Stopwörtern

ger_stopwords <- read_lines("https://raw.githubusercontent.com/stopwords-iso/stopwords-de/master/stopwords-de.txt")
custom_stopwords <- setdiff(ger_stopwords, stopwords("german"))

4.) Erstellung einer Dokumenten-Term-Matrix und Reduzierung

meine.dfm <- dfm(my_corpus, remove_numbers = TRUE, remove_punct = TRUE, remove = c(stopwords("german"), custom_stopwords))
meine.dfm.trim <- dfm_trim(meine.dfm, min_docfreq = 5, min_nchar = 3)

5.) Visualisierung der meist vorkommenden Wörter

textplot_wordcloud(meine.dfm.trim, min_size = 1, max_size = 2, max_words = 100)