refactor fraktion -> fraction
This commit is contained in:
+6
-6
@@ -6,9 +6,9 @@ find_word <- function(res, word) {
|
||||
}
|
||||
|
||||
#' @export
|
||||
join_speaker <- function(tb, res, fraktion_only = F) {
|
||||
join_speaker <- function(tb, res, fraction_only = F) {
|
||||
joined <- left_join(tb, res$speaker, by=c("speaker" = "id"))
|
||||
if (fraktion_only) select(joined, "fraktion")
|
||||
if (fraction_only) select(joined, "fraction")
|
||||
else joined
|
||||
}
|
||||
|
||||
@@ -30,9 +30,9 @@ party_order <- factor(c("Fraktionslos", "AfD&Fraktionslos",
|
||||
|
||||
#' @export
|
||||
bar_plot_fractions <- function(tb,
|
||||
x_variable = NULL, # default is fraktion
|
||||
x_variable = NULL, # default is fraction
|
||||
y_variable = NULL, # default is n
|
||||
fill = NULL, # default is fraktion
|
||||
fill = NULL, # default is fraction
|
||||
title = NULL,
|
||||
xlab = "Fraction",
|
||||
ylab = "n",
|
||||
@@ -46,9 +46,9 @@ bar_plot_fractions <- function(tb,
|
||||
x_variable <- enexpr(x_variable)
|
||||
|
||||
# set default values
|
||||
if (is.null(fill)) fill <- expr(fraktion)
|
||||
if (is.null(fill)) fill <- expr(fraction)
|
||||
if (is.null(y_variable)) y_variable <- expr(n)
|
||||
if (is.null(x_variable)) x_variable <- expr(fraktion)
|
||||
if (is.null(x_variable)) x_variable <- expr(fraction)
|
||||
|
||||
# either reorder fraction factor by variable value
|
||||
if (reorder) maps <- aes(x = reorder(!!x_variable, -!!y_variable),
|
||||
|
||||
@@ -42,13 +42,13 @@ read_all <- function(path="records/") {
|
||||
comments
|
||||
filter(commentsandapplause, type == "applause") %>%
|
||||
select(-type, -kommentator, -content) %>%
|
||||
mutate("CDU_CSU" = str_detect(fraktion, "CDU/CSU"),
|
||||
"SPD" = str_detect(fraktion, "SPD"),
|
||||
"FDP" = str_detect(fraktion, "FDP"),
|
||||
"DIE_LINKE" = str_detect(fraktion, "DIE LINKE"),
|
||||
"BÜNDNIS_90_DIE_GRÜNEN" = str_detect(fraktion, "BÜNDNIS 90/DIE GRÜNEN"),
|
||||
"AfD" = str_detect(fraktion, "AfD")) %>%
|
||||
select(-fraktion) ->
|
||||
mutate("CDU_CSU" = str_detect(fraction, "CDU/CSU"),
|
||||
"SPD" = str_detect(fraction, "SPD"),
|
||||
"FDP" = str_detect(fraction, "FDP"),
|
||||
"DIE_LINKE" = str_detect(fraction, "DIE LINKE"),
|
||||
"BÜNDNIS_90_DIE_GRÜNEN" = str_detect(fraction, "BÜNDNIS 90/DIE GRÜNEN"),
|
||||
"AfD" = str_detect(fraction, "AfD")) %>%
|
||||
select(-fraction) ->
|
||||
applause
|
||||
|
||||
list(speaker = speaker, speeches = speeches, talks = talks, comments = comments, applause = applause)
|
||||
@@ -90,14 +90,14 @@ parse_speaker <- function(speaker_xml) {
|
||||
nm <- xml_child(speaker_xml)
|
||||
vorname <- xml_get(nm, "vorname")
|
||||
nachname <- xml_get(nm, "nachname")
|
||||
fraktion <- xml_get(nm, "fraktion")
|
||||
fraction <- xml_get(nm, "fraction")
|
||||
titel <- xml_get(nm, "titel")
|
||||
rolle <- xml_find_all(nm, "rolle")
|
||||
if (length(rolle) > 0) {
|
||||
rolle_lang <- xml_get(rolle, "rolle_lang")
|
||||
rolle_kurz <- xml_get(rolle, "rolle_kurz")
|
||||
} else rolle_kurz <- rolle_lang <- NA_character_
|
||||
c(id = speaker_id, vorname = vorname, nachname = nachname, fraktion = fraktion, titel = titel,
|
||||
c(id = speaker_id, vorname = vorname, nachname = nachname, fraction = fraction, titel = titel,
|
||||
rolle_kurz = rolle_kurz, rolle_lang = rolle_lang)
|
||||
}
|
||||
|
||||
@@ -155,22 +155,22 @@ parse_speech <- function(speech_xml, date) {
|
||||
comments = comments)
|
||||
}
|
||||
|
||||
fraktionspattern <- "BÜNDNIS(SES)?\\W*90/DIE\\W*GRÜNEN|CDU/CSU|AfD|SPD|DIE LINKE|FDP|LINKEN"
|
||||
fraktionsnames <- c("BÜNDNIS 90/DIE GRÜNEN", "CDU/CSU", "AfD", "SPD", "DIE LINKE", "FDP")
|
||||
fractionpattern <- "BÜNDNIS(SES)?\\W*90/DIE\\W*GRÜNEN|CDU/CSU|AfD|SPD|DIE LINKE|FDP|LINKEN"
|
||||
fractionnames <- c("BÜNDNIS 90/DIE GRÜNEN", "CDU/CSU", "AfD", "SPD", "DIE LINKE", "FDP")
|
||||
|
||||
parse_comment <- function(comment, speech_id, on_speaker) {
|
||||
base <- c(speech_id = speech_id, on_speaker = on_speaker)
|
||||
# classify comment
|
||||
if(str_detect(comment, "Beifall")) {
|
||||
str_extract_all(comment, fraktionspattern) %>%
|
||||
str_extract_all(comment, fractionpattern) %>%
|
||||
`[[`(1) %>%
|
||||
sapply(partial(flip(head), 1) %.% agrep, x=fraktionsnames, max=0.2, value=T) %>%
|
||||
sapply(partial(flip(head), 1) %.% agrep, x=fractionnames, max=0.2, value=T) %>%
|
||||
str_c(collapse=",") ->
|
||||
by
|
||||
c(base, type = "applause", fraktion = by, kommentator = NA_character_, content = comment)
|
||||
c(base, type = "applause", fraction = by, kommentator = NA_character_, content = comment)
|
||||
} else {
|
||||
ps <- str_match(comment, "(.*) \\[(.*?)\\]: (.*)")[1,]
|
||||
c(base, type = "comment", fraktion = ps[3], kommentator = ps[2], content = ps[4])
|
||||
c(base, type = "comment", fraction = ps[3], kommentator = ps[2], content = ps[4])
|
||||
}
|
||||
}
|
||||
|
||||
@@ -188,7 +188,7 @@ parse_speechlist <- function(speechlist_xml, date) {
|
||||
comments = tibble(speech_id = comments["speech_id",],
|
||||
on_speaker = comments["on_speaker",],
|
||||
type = comments["type",],
|
||||
fraktion = comments["fraktion",],
|
||||
fraction = comments["fraction",],
|
||||
kommentator = comments["kommentator",],
|
||||
content = comments["content", ]))
|
||||
}
|
||||
@@ -199,7 +199,7 @@ parse_speakerliste <- function(speakerliste_xml) {
|
||||
tibble(id = d["id",],
|
||||
vorname = d["vorname",],
|
||||
nachname = d["nachname",],
|
||||
fraktion = d["fraktion",],
|
||||
fraction = d["fraction",],
|
||||
titel = d["titel",],
|
||||
rolle_kurz = d["rolle_kurz",],
|
||||
rolle_lang = d["rolle_lang",])
|
||||
|
||||
+7
-7
@@ -1,4 +1,4 @@
|
||||
fraktionen <- c("AFD" = "AfD",
|
||||
fractions <- c("AFD" = "AfD",
|
||||
"BÜNDNIS90/" = "BÜNDNIS 90 / DIE GRÜNEN",
|
||||
"BÜNDNIS90/DIEGRÜNEN" = "BÜNDNIS 90 / DIE GRÜNEN",
|
||||
"FRAKTIONSLOS" = "Fraktionslos",
|
||||
@@ -7,9 +7,9 @@ fraktionen <- c("AFD" = "AfD",
|
||||
"CDU/CSU" = "CDU/CSU",
|
||||
"FDP" = "FDP")
|
||||
|
||||
repair_fraktion <- function(fraktion) {
|
||||
cleaned <- str_to_upper %$% str_replace_all(fraktion, "\\s", "")
|
||||
fraktionen[cleaned]
|
||||
repair_fraction <- function(fraction) {
|
||||
cleaned <- str_to_upper %$% str_replace_all(fraction, "\\s", "")
|
||||
fractions[cleaned]
|
||||
}
|
||||
|
||||
# takes vector of titel and keeps longest
|
||||
@@ -26,17 +26,17 @@ 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
|
||||
mutate(fraction = Vectorize(repair_fraction)(fraction)) %>% # fix fraction
|
||||
group_by(id) %>%
|
||||
summarize(vorname = head(vorname, 1),
|
||||
nachname = head(nachname, 1),
|
||||
fraktion = collect_unique(fraktion),
|
||||
fraction = collect_unique(fraction),
|
||||
titel = longest_titel(titel),
|
||||
rolle_kurz = collect_unique(str_squish(rolle_kurz)),
|
||||
rolle_lang = collect_unique(str_squish(rolle_lang))) %>%
|
||||
ungroup() #%>%
|
||||
# arrange(id) %>%
|
||||
# distinct(vorname, nachname, fraktion, titel)
|
||||
# distinct(vorname, nachname, fraction, titel)
|
||||
}
|
||||
|
||||
repair_speeches <- function(speeches) {
|
||||
|
||||
Reference in New Issue
Block a user