fix errors from refactoring and add documentation to all remaining functions in analyze.R

This commit is contained in:
2021-08-07 00:31:56 +02:00
parent 5f9343bf7f
commit 5e9f70627d
10 changed files with 237 additions and 16 deletions
+10 -8
View File
@@ -59,7 +59,7 @@ repair_talks <- function(talks) {
#' unique (luckily :D)
#'
#' @param tb tibble
#' @param redner tibble
#' @param speaker tibble
#' @param name_variable name
#'
#' Tries to match the name_variable column with speaker names
@@ -83,29 +83,31 @@ lookup_speaker <- function(tb, speaker, name_variable) {
mutate(speaker = Vectorize(find_match)(str_replace_all({{name_variable}}, tobereplaced, "")))
}
repair_comments <- function(comments, redner) {
repair_comments <- function(comments, speaker) {
cat(paste0("Looking up speaker id's for names in comments. This may take a while ...\n",
"Use repair(, repair_commments = FALSE) to skip this.\n"))
# try to find a redner id for each actual comment
# try to find a speaker id for each actual comment
comments %>%
filter(!is.na(kommentator)) %>%
lookup_redner(redner, kommentator) %>%
lookup_speaker(speaker, kommentator) %>%
left_join(comments, ., by="kommentator") %>%
select(-kommentator)
}
#' Repair parsed tables
#'
#' TODO: Explain repair_comments argument
#' (if TRUE, we try to lookup redner names in redner table)
#' @param parse_output tibble
#' @param repair_comments bool
#'
#' If repair_comments is TRUE, members of the parliament mentioned in comments are looked up in speaker table.
#'
#' Possible test: check identical(repair(res), repair(repair(res))) == TRUE
#' Since repaired tables should be a fixpoint of repair.
#' @export
repair <- function(parse_output, repair_comments = FALSE) {
list(redner = repair_speaker(parse_output$speaker),
reden = repair_speeches(parse_output$speeches),
list(speaker = repair_speaker(parse_output$speaker),
speeches = repair_speeches(parse_output$speeches),
talks = repair_talks(parse_output$talks),
comments = if(repair_comments) repair_comments(parse_output$comments,
parse_output$speaker)