An R package to analyze the parliamentary records of the 19th legislative period of the Bundestag, the German parliament.
Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

52 lignes
1.6KB

  1. source("../utils/helpers.R")
  2. fraktionen <- c("AFD" = "AfD",
  3. "BÜNDNIS90/" = "BÜNDNIS 90 / DIE GRÜNEN",
  4. "BÜNDNIS90/DIEGRÜNEN" = "BÜNDNIS 90 / DIE GRÜNEN",
  5. "FRAKTIONSLOS" = "Fraktionslos",
  6. "DIELINKE" = "DIE LINKE",
  7. "SPD" = "SPD",
  8. "CDU/CSU" = "CDU/CSU",
  9. "FDP" = "FDP")
  10. repair_fraktion <- function(fraktion) {
  11. cleaned <- str_to_upper %$% str_replace_all(fraktion, "\\s", "")
  12. fraktionen[cleaned]
  13. }
  14. # takes vector of titel and keeps longest
  15. longest_titel <- function(titel) {
  16. if (all(is.na(titel))) NA_character_
  17. else titel[which.max %$% str_length(titel)]
  18. }
  19. # takes character vector, removes duplicates and collapses
  20. collect_unique <- function(xs) xs %>% clear_na() %>% unique() %>% str_c(collapse="&") %>% na_if("")
  21. # expects a tibble of redner and repairs
  22. repair_redner <- function(redner) {
  23. redner %>% mutate(fraktion = Vectorize(repair_fraktion)(fraktion)) %>% # fix fraktion
  24. group_by(id, vorname, nachname) %>%
  25. summarize(fraktion = collect_unique(fraktion),
  26. titel = longest_titel(titel),
  27. rolle_kurz = collect_unique(str_squish(rolle_kurz)),
  28. rolle_lang = collect_unique(str_squish(rolle_lang)))
  29. }
  30. repair_reden <- function(reden) {
  31. # TODO: fill with content
  32. reden
  33. }
  34. repair_talks <- function(talks) {
  35. # TODO: fill with content
  36. talks
  37. }
  38. # repairs all tables
  39. repair <- function(parse_output) {
  40. list(redner = repair_redner(parse_output$redner),
  41. reden = repair_reden(parse_output$reden),
  42. talks = repair_talks(parse_output$talks))
  43. }