refactor fraktion -> fraction

This commit is contained in:
2021-08-03 17:11:11 +02:00
parent 7315dd8793
commit a0df02dbed
6 changed files with 85 additions and 85 deletions
+17 -17
View File
@@ -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",])