refactor fraktion -> fraction
This commit is contained in:
+23
-23
@@ -52,7 +52,7 @@ talks <- res$talks
|
||||
Now we can start analysing our parsed dataset, e.g. find out which party gives the most talks:
|
||||
```{r, fig.width=7}
|
||||
join_speaker(res$speeches, res) %>%
|
||||
group_by(fraktion) %>%
|
||||
group_by(fraction) %>%
|
||||
summarize(n = n()) %>%
|
||||
arrange(n) %>%
|
||||
bar_plot_fractions(title="Number of speeches given by fraction",
|
||||
@@ -65,9 +65,9 @@ or counting the occurences of a given word:
|
||||
find_word(res, "Kohleausstieg") %>%
|
||||
filter(occurences > 0) %>%
|
||||
join_speaker(res) %>%
|
||||
select(content, fraktion) %>%
|
||||
filter(!is.na(fraktion)) %>%
|
||||
group_by(fraktion) %>%
|
||||
select(content, fraction) %>%
|
||||
filter(!is.na(fraction)) %>%
|
||||
group_by(fraction) %>%
|
||||
summarize(n = n()) %>%
|
||||
arrange(desc(n)) %>%
|
||||
bar_plot_fractions(title = "Parties using the word 'Kohleausstieg' the most (absolutely)",
|
||||
@@ -103,9 +103,9 @@ res$talks %>%
|
||||
```{r}
|
||||
res$applause %>%
|
||||
left_join(res$speaker, by=c("on_speaker" = "id")) %>%
|
||||
select(on_fraktion = fraktion, where(is.logical)) %>%
|
||||
group_by(on_fraktion) %>%
|
||||
arrange(on_fraktion) %>%
|
||||
select(on_fraction = fraction, where(is.logical)) %>%
|
||||
group_by(on_fraction) %>%
|
||||
arrange(on_fraction) %>%
|
||||
summarize("AfD" = sum(`AfD`),
|
||||
"BÜNDNIS 90 / DIE GRÜNEN" = sum(`BÜNDNIS_90_DIE_GRÜNEN`),
|
||||
"CDU/CSU" = sum(`CDU_CSU`),
|
||||
@@ -117,11 +117,11 @@ res$applause %>%
|
||||
For plotting our results we reorganize them a bit and produce a bar plot:
|
||||
|
||||
```{r, fig.width=7}
|
||||
pivot_longer(tb, where(is.numeric), "by_fraktion", "count") %>%
|
||||
filter(!is.na(on_fraktion)) %>%
|
||||
bar_plot_fractions(x_variable = on_fraktion,
|
||||
pivot_longer(tb, where(is.numeric), "by_fraction", "count") %>%
|
||||
filter(!is.na(on_fraction)) %>%
|
||||
bar_plot_fractions(x_variable = on_fraction,
|
||||
y_variable = value,
|
||||
fill = by_fraktion,
|
||||
fill = by_fraction,
|
||||
title = "Number of rounds of applauses from fractions to fractions",
|
||||
xlab = "Applauded fraction",
|
||||
ylab = "Rounds of applauses",
|
||||
@@ -135,23 +135,23 @@ pivot_longer(tb, where(is.numeric), "by_fraktion", "count") %>%
|
||||
```{r}
|
||||
res$comments %>%
|
||||
left_join(res$speaker, by=c("on_speaker" = "id")) %>%
|
||||
select(by_fraktion = fraktion.x, on_fraktion = fraktion.y) %>%
|
||||
group_by(on_fraktion) %>%
|
||||
summarize(`AfD` = sum(str_detect(by_fraktion, "AfD"), na.rm=T),
|
||||
`BÜNDNIS 90 / DIE GRÜNEN` = sum(str_detect(by_fraktion, "BÜNDNIS 90/DIE GRÜNEN"), na.rm=T),
|
||||
`CDU/CSU` = sum(str_detect(by_fraktion, "CDU/CSU"), na.rm = T),
|
||||
`DIE LINKE` = sum(str_detect(by_fraktion, "DIE LINKE"), na.rm=T),
|
||||
`FDP` = sum(str_detect(by_fraktion, "FDP"), na.rm=T),
|
||||
`SPD` = sum(str_detect(by_fraktion, "SPD"), na.rm=T)) -> tb
|
||||
select(by_fraction = fraction.x, on_fraction = fraction.y) %>%
|
||||
group_by(on_fraction) %>%
|
||||
summarize(`AfD` = sum(str_detect(by_fraction, "AfD"), na.rm=T),
|
||||
`BÜNDNIS 90 / DIE GRÜNEN` = sum(str_detect(by_fraction, "BÜNDNIS 90/DIE GRÜNEN"), na.rm=T),
|
||||
`CDU/CSU` = sum(str_detect(by_fraction, "CDU/CSU"), na.rm = T),
|
||||
`DIE LINKE` = sum(str_detect(by_fraction, "DIE LINKE"), na.rm=T),
|
||||
`FDP` = sum(str_detect(by_fraction, "FDP"), na.rm=T),
|
||||
`SPD` = sum(str_detect(by_fraction, "SPD"), na.rm=T)) -> tb
|
||||
```
|
||||
Analogously we plot the results:
|
||||
|
||||
```{r, fig.width=7}
|
||||
pivot_longer(tb, where(is.numeric), "by_fraktion", "count") %>%
|
||||
filter(!is.na(on_fraktion)) %>%
|
||||
bar_plot_fractions(x_variable = on_fraktion,
|
||||
pivot_longer(tb, where(is.numeric), "by_fraction", "count") %>%
|
||||
filter(!is.na(on_fraction)) %>%
|
||||
bar_plot_fractions(x_variable = on_fraction,
|
||||
y_variable = value,
|
||||
fill = by_fraktion,
|
||||
fill = by_fraction,
|
||||
title = "Number of comments from fractions to fractions",
|
||||
xlab = "Commented fraction",
|
||||
ylab = "Number of comments",
|
||||
|
||||
@@ -61,53 +61,53 @@ Now we extract the words that were used with higher frequency by one party and c
|
||||
```{r}
|
||||
talks %>%
|
||||
left_join(speaker, by=c(speaker='id')) %>%
|
||||
group_by(fraktion) %>%
|
||||
summarize(full_text=str_c(content, collapse="\n")) -> talks_by_fraktion
|
||||
group_by(fraction) %>%
|
||||
summarize(full_text=str_c(content, collapse="\n")) -> talks_by_fraction
|
||||
```
|
||||
For each party, we want to get a tibble of words with frequency.
|
||||
```{r}
|
||||
#AfD
|
||||
Worte <- str_extract_all(talks_by_fraktion$full_text[[1]], "\\b[a-zA-ZäöüÄÖÜß]+\\b")[[1]]
|
||||
Worte <- str_extract_all(talks_by_fraction$full_text[[1]], "\\b[a-zA-ZäöüÄÖÜß]+\\b")[[1]]
|
||||
afdtotal = length(Worte)
|
||||
tibble(Worte) %>% group_by(Worte) %>% count() %>% mutate(freq =n/afdtotal) -> afd_words
|
||||
|
||||
#AfD&Fraktionslos
|
||||
Worte <- str_extract_all(talks_by_fraktion$full_text[[2]], "\\b[a-zA-ZäöüÄÖÜß]+\\b")[[1]]
|
||||
Worte <- str_extract_all(talks_by_fraction$full_text[[2]], "\\b[a-zA-ZäöüÄÖÜß]+\\b")[[1]]
|
||||
afdundfraktionslostotal = length(Worte)
|
||||
tibble(Worte) %>% group_by(Worte) %>% count() %>% mutate(freq =n/afdundfraktionslostotal) -> afdundfraktionslos_words
|
||||
|
||||
#BÜNDNIS 90 / DIE GRÜNEN
|
||||
Worte <- str_extract_all(talks_by_fraktion$full_text[[3]], "\\b[a-zA-ZäöüÄÖÜß]+\\b")[[1]]
|
||||
Worte <- str_extract_all(talks_by_fraction$full_text[[3]], "\\b[a-zA-ZäöüÄÖÜß]+\\b")[[1]]
|
||||
grünetotal = length(Worte)
|
||||
tibble(Worte) %>% group_by(Worte) %>% count() %>% mutate(freq =n/grünetotal) -> grüne_words
|
||||
|
||||
#CDU/CSU
|
||||
Worte <- str_extract_all(talks_by_fraktion$full_text[[4]], "\\b[a-zA-ZäöüÄÖÜß]+\\b")[[1]]
|
||||
Worte <- str_extract_all(talks_by_fraction$full_text[[4]], "\\b[a-zA-ZäöüÄÖÜß]+\\b")[[1]]
|
||||
cdutotal = length(Worte)
|
||||
tibble(Worte) %>% group_by(Worte) %>% count() %>% mutate(freq =n/cdutotal) -> cdu_words
|
||||
|
||||
#DIE LINKE
|
||||
Worte <- str_extract_all(talks_by_fraktion$full_text[[5]], "\\b[a-zA-ZäöüÄÖÜß]+\\b")[[1]]
|
||||
Worte <- str_extract_all(talks_by_fraction$full_text[[5]], "\\b[a-zA-ZäöüÄÖÜß]+\\b")[[1]]
|
||||
linketotal = length(Worte)
|
||||
tibble(Worte) %>% group_by(Worte) %>% count() %>% mutate(freq =n/linketotal) -> linke_words
|
||||
|
||||
#FDP
|
||||
Worte <- str_extract_all(talks_by_fraktion$full_text[[6]], "\\b[a-zA-ZäöüÄÖÜß]+\\b")[[1]]
|
||||
Worte <- str_extract_all(talks_by_fraction$full_text[[6]], "\\b[a-zA-ZäöüÄÖÜß]+\\b")[[1]]
|
||||
fdptotal = length(Worte)
|
||||
tibble(Worte) %>% group_by(Worte) %>% count() %>% mutate(freq =n/fdptotal) -> fdp_words
|
||||
|
||||
#Fraktionslos
|
||||
Worte <- str_extract_all(talks_by_fraktion$full_text[[7]], "\\b[a-zA-ZäöüÄÖÜß]+\\b")[[1]]
|
||||
Worte <- str_extract_all(talks_by_fraction$full_text[[7]], "\\b[a-zA-ZäöüÄÖÜß]+\\b")[[1]]
|
||||
fraktionslostotal = length(Worte)
|
||||
tibble(Worte) %>% group_by(Worte) %>% count() %>% mutate(freq =n/fraktionslostotal) -> fraktionslos_words
|
||||
|
||||
#SPD
|
||||
Worte <- str_extract_all(talks_by_fraktion$full_text[[8]], "\\b[a-zA-ZäöüÄÖÜß]+\\b")[[1]]
|
||||
Worte <- str_extract_all(talks_by_fraction$full_text[[8]], "\\b[a-zA-ZäöüÄÖÜß]+\\b")[[1]]
|
||||
spdtotal = length(Worte)
|
||||
tibble(Worte) %>% group_by(Worte) %>% count() %>% mutate(freq =n/spdtotal) -> spd_words
|
||||
|
||||
#NA
|
||||
Worte <- str_extract_all(talks_by_fraktion$full_text[[9]], "\\b[a-zA-ZäöüÄÖÜß]+\\b")[[1]]
|
||||
Worte <- str_extract_all(talks_by_fraction$full_text[[9]], "\\b[a-zA-ZäöüÄÖÜß]+\\b")[[1]]
|
||||
natotal = length(Worte)
|
||||
tibble(Worte) %>% group_by(Worte) %>% count() %>% mutate(freq =n/natotal) -> na_words
|
||||
|
||||
@@ -117,34 +117,34 @@ total <- sum(all_words$n)
|
||||
all_words %>% group_by(Worte) %>% summarize(n = sum(n), part= sum(n)/total) -> all_words
|
||||
```
|
||||
|
||||
Now we want to extract the words that are more frequently used by a specific `fraktion`.
|
||||
Now we want to extract the words that are more frequently used by a specific fraction.
|
||||
```{r}
|
||||
afd_words %>% transmute(freq, fraktion_n = n) %>% left_join(all_words) %>% transmute(fraktion_freq = freq, total_freq = part, fraktion_n, total_n = n, rel_quotient = fraktion_freq/total_freq, abs_quotient = fraktion_n/total_n) %>% arrange(-abs_quotient, -fraktion_n) %>% filter(rel_quotient > 1) -> afd_high_frequent
|
||||
select(afd_high_frequent, fraktion_n, total_n, abs_quotient, rel_quotient) %>% filter(total_n > 80)
|
||||
afd_words %>% transmute(freq, fraction_n = n) %>% left_join(all_words) %>% transmute(fraction_freq = freq, total_freq = part, fraction_n, total_n = n, rel_quotient = fraction_freq/total_freq, abs_quotient = fraction_n/total_n) %>% arrange(-abs_quotient, -fraction_n) %>% filter(rel_quotient > 1) -> afd_high_frequent
|
||||
select(afd_high_frequent, fraction_n, total_n, abs_quotient, rel_quotient) %>% filter(total_n > 80)
|
||||
|
||||
afdundfraktionslos_words %>% transmute(freq, fraktion_n = n) %>% left_join(all_words) %>% transmute(fraktion_freq = freq, total_freq = part, fraktion_n, total_n = n, rel_quotient = fraktion_freq/total_freq, abs_quotient = fraktion_n/total_n) %>% arrange(-abs_quotient, -fraktion_n) %>% filter(rel_quotient > 1) -> afdundfraktionslos_high_frequent
|
||||
select(afdundfraktionslos_high_frequent, fraktion_n, total_n, abs_quotient, rel_quotient) %>% filter(total_n > 80)
|
||||
afdundfraktionslos_words %>% transmute(freq, fraction_n = n) %>% left_join(all_words) %>% transmute(fraction_freq = freq, total_freq = part, fraction_n, total_n = n, rel_quotient = fraction_freq/total_freq, abs_quotient = fraction_n/total_n) %>% arrange(-abs_quotient, -fraction_n) %>% filter(rel_quotient > 1) -> afdundfraktionslos_high_frequent
|
||||
select(afdundfraktionslos_high_frequent, fraction_n, total_n, abs_quotient, rel_quotient) %>% filter(total_n > 80)
|
||||
|
||||
grüne_words %>% transmute(freq, fraktion_n = n) %>% left_join(all_words) %>% transmute(fraktion_freq = freq, total_freq = part, fraktion_n, total_n = n, rel_quotient = fraktion_freq/total_freq, abs_quotient = fraktion_n/total_n) %>% arrange(-abs_quotient, -fraktion_n) %>% filter(rel_quotient > 1) -> grüne_high_frequent
|
||||
select(grüne_high_frequent, fraktion_n, total_n, abs_quotient, rel_quotient) %>% filter(total_n > 80)
|
||||
grüne_words %>% transmute(freq, fraction_n = n) %>% left_join(all_words) %>% transmute(fraction_freq = freq, total_freq = part, fraction_n, total_n = n, rel_quotient = fraction_freq/total_freq, abs_quotient = fraction_n/total_n) %>% arrange(-abs_quotient, -fraction_n) %>% filter(rel_quotient > 1) -> grüne_high_frequent
|
||||
select(grüne_high_frequent, fraction_n, total_n, abs_quotient, rel_quotient) %>% filter(total_n > 80)
|
||||
|
||||
cdu_words %>% transmute(freq, fraktion_n = n) %>% left_join(all_words) %>% transmute(fraktion_freq = freq, total_freq = part, fraktion_n, total_n = n, rel_quotient = fraktion_freq/total_freq, abs_quotient = fraktion_n/total_n) %>% arrange(-abs_quotient, -fraktion_n) %>% filter(rel_quotient > 1) -> cdu_high_frequent
|
||||
select(cdu_high_frequent, fraktion_n, total_n, abs_quotient, rel_quotient) %>% filter(total_n > 80)
|
||||
cdu_words %>% transmute(freq, fraction_n = n) %>% left_join(all_words) %>% transmute(fraction_freq = freq, total_freq = part, fraction_n, total_n = n, rel_quotient = fraction_freq/total_freq, abs_quotient = fraction_n/total_n) %>% arrange(-abs_quotient, -fraction_n) %>% filter(rel_quotient > 1) -> cdu_high_frequent
|
||||
select(cdu_high_frequent, fraction_n, total_n, abs_quotient, rel_quotient) %>% filter(total_n > 80)
|
||||
|
||||
linke_words %>% transmute(freq, fraktion_n = n) %>% left_join(all_words) %>% transmute(fraktion_freq = freq, total_freq = part, fraktion_n, total_n = n, rel_quotient = fraktion_freq/total_freq, abs_quotient = fraktion_n/total_n) %>% arrange(-abs_quotient, -fraktion_n) %>% filter(rel_quotient > 1) -> linke_high_frequent
|
||||
select(linke_high_frequent, fraktion_n, total_n, abs_quotient, rel_quotient) %>% filter(total_n > 80)
|
||||
linke_words %>% transmute(freq, fraction_n = n) %>% left_join(all_words) %>% transmute(fraction_freq = freq, total_freq = part, fraction_n, total_n = n, rel_quotient = fraction_freq/total_freq, abs_quotient = fraction_n/total_n) %>% arrange(-abs_quotient, -fraction_n) %>% filter(rel_quotient > 1) -> linke_high_frequent
|
||||
select(linke_high_frequent, fraction_n, total_n, abs_quotient, rel_quotient) %>% filter(total_n > 80)
|
||||
|
||||
fdp_words %>% transmute(freq, fraktion_n = n) %>% left_join(all_words) %>% transmute(fraktion_freq = freq, total_freq = part, fraktion_n, total_n = n, rel_quotient = fraktion_freq/total_freq, abs_quotient = fraktion_n/total_n) %>% arrange(-abs_quotient, -fraktion_n) %>% filter(rel_quotient > 1) -> fdp_high_frequent
|
||||
select(fdp_high_frequent, fraktion_n, total_n, abs_quotient, rel_quotient) %>% filter(total_n > 80)
|
||||
fdp_words %>% transmute(freq, fraction_n = n) %>% left_join(all_words) %>% transmute(fraction_freq = freq, total_freq = part, fraction_n, total_n = n, rel_quotient = fraction_freq/total_freq, abs_quotient = fraction_n/total_n) %>% arrange(-abs_quotient, -fraction_n) %>% filter(rel_quotient > 1) -> fdp_high_frequent
|
||||
select(fdp_high_frequent, fraction_n, total_n, abs_quotient, rel_quotient) %>% filter(total_n > 80)
|
||||
|
||||
fraktionslos_words %>% transmute(freq, fraktion_n = n) %>% left_join(all_words) %>% transmute(fraktion_freq = freq, total_freq = part, fraktion_n, total_n = n, rel_quotient = fraktion_freq/total_freq, abs_quotient = fraktion_n/total_n) %>% arrange(-abs_quotient, -fraktion_n) %>% filter(rel_quotient > 1) -> fraktionslos_high_frequent
|
||||
select(fraktionslos_high_frequent, fraktion_n, total_n, abs_quotient, rel_quotient) %>% filter(total_n > 80)
|
||||
fraktionslos_words %>% transmute(freq, fraction_n = n) %>% left_join(all_words) %>% transmute(fraction_freq = freq, total_freq = part, fraction_n, total_n = n, rel_quotient = fraction_freq/total_freq, abs_quotient = fraction_n/total_n) %>% arrange(-abs_quotient, -fraction_n) %>% filter(rel_quotient > 1) -> fraktionslos_high_frequent
|
||||
select(fraktionslos_high_frequent, fraction_n, total_n, abs_quotient, rel_quotient) %>% filter(total_n > 80)
|
||||
|
||||
spd_words %>% transmute(freq, fraktion_n = n) %>% left_join(all_words) %>% transmute(fraktion_freq = freq, total_freq = part, fraktion_n, total_n = n, rel_quotient = fraktion_freq/total_freq, abs_quotient = fraktion_n/total_n) %>% arrange(-abs_quotient, -fraktion_n) %>% filter(rel_quotient > 1) -> spd_high_frequent
|
||||
select(spd_high_frequent, fraktion_n, total_n, abs_quotient, rel_quotient) %>% filter(total_n > 80)
|
||||
spd_words %>% transmute(freq, fraction_n = n) %>% left_join(all_words) %>% transmute(fraction_freq = freq, total_freq = part, fraction_n, total_n = n, rel_quotient = fraction_freq/total_freq, abs_quotient = fraction_n/total_n) %>% arrange(-abs_quotient, -fraction_n) %>% filter(rel_quotient > 1) -> spd_high_frequent
|
||||
select(spd_high_frequent, fraction_n, total_n, abs_quotient, rel_quotient) %>% filter(total_n > 80)
|
||||
|
||||
na_words %>% transmute(freq, fraktion_n = n) %>% left_join(all_words) %>% transmute(fraktion_freq = freq, total_freq = part, fraktion_n, total_n = n, rel_quotient = fraktion_freq/total_freq, abs_quotient = fraktion_n/total_n) %>% arrange(-abs_quotient, -fraktion_n) %>% filter(rel_quotient > 1) -> na_high_frequent
|
||||
select(na_high_frequent, fraktion_n, total_n, abs_quotient, rel_quotient) %>% filter(total_n > 80)
|
||||
na_words %>% transmute(freq, fraction_n = n) %>% left_join(all_words) %>% transmute(fraction_freq = freq, total_freq = part, fraction_n, total_n = n, rel_quotient = fraction_freq/total_freq, abs_quotient = fraction_n/total_n) %>% arrange(-abs_quotient, -fraction_n) %>% filter(rel_quotient > 1) -> na_high_frequent
|
||||
select(na_high_frequent, fraction_n, total_n, abs_quotient, rel_quotient) %>% filter(total_n > 80)
|
||||
```
|
||||
|
||||
We compare these words with `hitlerwords`.
|
||||
@@ -161,7 +161,7 @@ spd_high_frequent %>% mutate(Worte = str_to_lower(Worte)) %>% inner_join(hitlerw
|
||||
na_high_frequent %>% mutate(Worte = str_to_lower(Worte)) %>% inner_join(hitlerwords) -> na_hitler_comparison
|
||||
|
||||
#not unique
|
||||
tibble(fraktion = c("AfD", "AfD&Fraktionslos", "BÜNDNIS 90 / DIE GRÜNEN", "CDU/CSU", "DIE LINKE", "FDP", "Fraktionslos", "SPD"),
|
||||
tibble(fraction = c("AfD", "AfD&Fraktionslos", "BÜNDNIS 90 / DIE GRÜNEN", "CDU/CSU", "DIE LINKE", "FDP", "Fraktionslos", "SPD"),
|
||||
absolute = c(nrow(afd_hitler_comparison), nrow(afdundfraktionslos_hitler_comparison), nrow(grüne_hitler_comparison), nrow(cdu_hitler_comparison), nrow(linke_hitler_comparison), nrow(fdp_hitler_comparison), nrow(fraktionslos_hitler_comparison), nrow(spd_hitler_comparison)),
|
||||
total = c(nrow(afd_words), nrow(afdundfraktionslos_words), nrow(grüne_words), nrow(cdu_words), nrow(linke_words), nrow(fdp_words), nrow(fraktionslos_words), nrow(spd_words))
|
||||
) %>% mutate(percent = 100*absolute/total) -> hitler_comparison
|
||||
|
||||
Reference in New Issue
Block a user