refactor rede -> speech, redner -> speaker
This commit is contained in:
+16
-16
@@ -21,10 +21,10 @@ longest_titel <- function(titel) {
|
||||
# takes character vector, removes duplicates and collapses
|
||||
collect_unique <- function(xs) xs %>% clear_na() %>% unique() %>% str_c(collapse="&") %>% na_if("")
|
||||
|
||||
# expects a tibble of redner and repairs
|
||||
repair_redner <- function(redner) {
|
||||
if (nrow(redner) == 0) return(redner)
|
||||
redner %>%
|
||||
# expects a tibble of speaker and repairs
|
||||
repair_speaker <- function(speaker) {
|
||||
if (nrow(speaker) == 0) return(speaker)
|
||||
speaker %>%
|
||||
filter(id != "10000") %>% # invalid id's
|
||||
mutate(fraktion = Vectorize(repair_fraktion)(fraktion)) %>% # fix fraktion
|
||||
group_by(id) %>%
|
||||
@@ -39,10 +39,10 @@ repair_redner <- function(redner) {
|
||||
# distinct(vorname, nachname, fraktion, titel)
|
||||
}
|
||||
|
||||
repair_reden <- function(reden) {
|
||||
if (nrow(reden) == 0) return(reden)
|
||||
repair_speeches <- function(speeches) {
|
||||
if (nrow(speeches) == 0) return(speeches)
|
||||
# TODO: fill with content
|
||||
reden
|
||||
speeches
|
||||
}
|
||||
|
||||
repair_talks <- function(talks) {
|
||||
@@ -51,13 +51,13 @@ repair_talks <- function(talks) {
|
||||
filter(talks, str_length(content) > 0)
|
||||
}
|
||||
|
||||
# tries to find the correct redner id given a name
|
||||
# tries to find the correct speaker id given a name
|
||||
# this is sufficient since every prename lastname combination in the bundestag is
|
||||
# unique (luckily :D)
|
||||
# returns a lookup table
|
||||
lookup_redner <- function(comments, redner) {
|
||||
lookup_speaker <- function(comments, speaker) {
|
||||
tobereplaced <- "[-–—‑- ]"
|
||||
redner %>%
|
||||
speaker %>%
|
||||
unite(name, vorname, nachname, sep=".*") %>%
|
||||
mutate(name = str_replace_all(name, tobereplaced, ".*")) ->
|
||||
rs
|
||||
@@ -70,14 +70,14 @@ lookup_redner <- function(comments, redner) {
|
||||
}
|
||||
comments %>%
|
||||
distinct(kommentator) %>%
|
||||
mutate(redner = Vectorize(find_match)(str_replace_all(kommentator, tobereplaced, "")))
|
||||
mutate(speaker = Vectorize(find_match)(str_replace_all(kommentator, tobereplaced, "")))
|
||||
}
|
||||
|
||||
repair_comments <- function(comments, redner) {
|
||||
# try to find a redner id for each actual comment
|
||||
repair_comments <- function(comments, speaker) {
|
||||
# try to find a speaker id for each actual comment
|
||||
comments %>%
|
||||
filter(!is.na(kommentator)) %>%
|
||||
lookup_redner(redner) %>%
|
||||
lookup_speaker(speaker) %>%
|
||||
left_join(comments, ., by="kommentator") %>%
|
||||
select(-kommentator)
|
||||
}
|
||||
@@ -86,8 +86,8 @@ repair_comments <- function(comments, redner) {
|
||||
#'
|
||||
#' @export
|
||||
repair <- function(parse_output) {
|
||||
list(redner = repair_redner(parse_output$redner),
|
||||
reden = repair_reden(parse_output$reden),
|
||||
list(speaker = repair_speaker(parse_output$speaker),
|
||||
speeches = repair_speeches(parse_output$speeches),
|
||||
talks = repair_talks(parse_output$talks),
|
||||
#comments = repair_comments(parse_output$comments)
|
||||
comments = parse_output$comments,
|
||||
|
||||
Reference in New Issue
Block a user