An R package to analyze the parliamentary records of the 19th legislative period of the Bundestag, the German parliament.
Nelze vybrat více než 25 témat Téma musí začínat písmenem nebo číslem, může obsahovat pomlčky („-“) a může být dlouhé až 35 znaků.

52 řádky
1.6KB

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