Просмотр исходного кода

improve applause party parsing

genderequality-alternative
flavis 4 лет назад
Родитель
Сommit
2abb3467e8
2 измененных файлов: 4 добавлений и 1 удалений
  1. +1
    -0
      R/helpers.R
  2. +3
    -1
      R/parse.R

+ 1
- 0
R/helpers.R Просмотреть файл

@@ -1,4 +1,5 @@
`%$%` <- function(f, x) f(x) `%$%` <- function(f, x) f(x)
`%.%` <- function(f, g) function(...) f(g(...)) `%.%` <- function(f, g) function(...) f(g(...))
flip <- function(f) function(x, y) f(y, x)


clear_na <- function(xs) xs[!is.na(xs)] clear_na <- function(xs) xs[!is.na(xs)]

+ 3
- 1
R/parse.R Просмотреть файл

@@ -137,12 +137,14 @@ parse_rede <- function(rede_xml) {
comments = comments) comments = comments)
} }


fraktionspattern <- "BÜNDNIS 90/DIE GRÜNEN|CDU/CSU|AfD|SPD|DIE LINKE|FDP"
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")


parse_comment <- function(comment, rede_id, on_redner) { parse_comment <- function(comment, rede_id, on_redner) {
base <- c(rede_id = rede_id, on_redner = on_redner) base <- c(rede_id = rede_id, on_redner = on_redner)
str_extract_all(comment, fraktionspattern) %>% str_extract_all(comment, fraktionspattern) %>%
`[[`(1) %>% `[[`(1) %>%
sapply(partial(flip(head), 1) %.% agrep, x=fraktionsnames, max=0.2, value=T) %>%
str_c(collapse=",") -> str_c(collapse=",") ->
by by
# classify comment # classify comment


Загрузка…
Отмена
Сохранить