blob: 2094490f0696f66d6164ae890e1eb88a754cb6ed [file] [log] [blame]
Marc Kupietz3df159b2021-03-05 08:51:54 +01001hc_theme <- if(require(idsThemeR)) {
2 idsThemeR::hc_theme_ids_light()
3} else {
4 hc_theme_hcrt()
5}
Marc Kupietz9bb50082022-02-18 16:38:10 +01006rsr <- new("KorAPConnection", verbose = TRUE, accessToken = NULL)
Marc Kupietzb925f042021-03-02 07:45:30 +01007vc <- "(textType = /Zeit.*/ | textTypeRef=Plenarprotokoll) & availability!=QAO-NC-LOC:ids & creationDate in"
Marc Kupietzf46a1372022-08-29 13:54:48 +02008years <- c(2005:2021)
Marc Kupietzfc715182021-03-02 08:12:59 +01009from <- 2005
Marc Kupietzf46a1372022-08-29 13:54:48 +020010to <- 2021
Marc Kupietz00455202020-10-21 14:13:36 +020011query <- "Aluhut"
12logfile <- file("frequency_curves.log", open = "a")
13
Marc Kupietza47d1502023-04-18 15:26:47 +020014# override log_info in RKorAPClient to get some progress info
15log_info <- function(v, ...) {
Marc Kupietz00455202020-10-21 14:13:36 +020016 original = paste0(...)
Marc Kupietz584ae5d2021-03-02 08:14:04 +010017 detail <- if (str_detect(original, "Searching.*in ([0-9]{4})")) {
Marc Kupietz00455202020-10-21 14:13:36 +020018 str_replace(original, ".*in ([0-9]{4}).*", "Suche in \\1")
Marc Kupietz584ae5d2021-03-02 08:14:04 +010019 } else if (str_detect(original, "Getting size.*in ([0-9]{4})")) {
20 str_replace(original, ".*in ([0-9]{4}).*", "Korpusgröße \\1")
Marc Kupietz00455202020-10-21 14:13:36 +020021 } else {
22 "Randverteilung"
23 }
Marc Kupietz584ae5d2021-03-02 08:14:04 +010024 incProgress(1 / (2 * length(query) * length(years) + length(years)), detail = detail)
Marc Kupietz00455202020-10-21 14:13:36 +020025 cat(original, file = logfile)
26 flush(logfile)
27}
28
Marc Kupietza47d1502023-04-18 15:26:47 +020029assignInNamespace("log_info", log_info, "RKorAPClient")
Marc Kupietz00455202020-10-21 14:13:36 +020030
31plotHighchart <- function(query = c("Tolpatsch", "Tollpatsch"),
Marc Kupietzb925f042021-03-02 07:45:30 +010032 vc = "(textType = /Zeit.*/ | textTypeRef=Plenarprotokoll) & availability!=QAO-NC-LOC:ids & creationDate in"
33,
Marc Kupietz00455202020-10-21 14:13:36 +020034 years = years,
35 as.alternatives = F,
36 conf.level = 0.95,
37 kco = rsr) {
38 hc <- frequencyQuery(kco,
39 query,
40 paste(vc, years),
41 as.alternatives = as.alternatives) %>%
42 hc_freq_by_year_ci(as.alternatives, smooth = T) %>%
Marc Kupietzf7f5b392021-03-02 08:13:36 +010043 hc_yAxis(title = list(text = "Instanzen pro Million Wörter")) %>%
Marc Kupietz3df159b2021-03-05 08:51:54 +010044 hc_add_theme(hc_theme) %>%
Marc Kupietzb925f042021-03-02 07:45:30 +010045 hc_caption(text = paste(
46 "Frequenzverläufe (mit 95%-Konfidenzbändern) im",
47 "<a href='http://www.dereko.de'>Deutschen Referenzkorpus DeReKo</a>",
Marc Kupietzf46a1372022-08-29 13:54:48 +020048 "(virtuelles Korpus: <a href='https://korap.ids-mannheim.de/doc/corpus'>DeReKo-KorAP-2022-I</a>",
Marc Kupietzb925f042021-03-02 07:45:30 +010049 "eingegrenzt auf Zeitungen, Zeitschriften und Plenarprotokolle).",
50 "Klicken sie die einzelnen Datenpunkte an, um entsprechende KorAP-Suchen zu starten."
51 ))
52
Marc Kupietz00455202020-10-21 14:13:36 +020053 hc
54}
55
Marc Kupietzf46a1372022-08-29 13:54:48 +020056generateHighchart <- function(wordParam, from=2005, to=2021) {
Marc Kupietzfc715182021-03-02 08:12:59 +010057 years <<- c(from:to)
Marc Kupietz00455202020-10-21 14:13:36 +020058 if (wordParam != "") {
Marc Kupietz133b6272022-02-18 16:38:39 +010059 query <<- strsplit(wordParam, " *, *")
Marc Kupietz00455202020-10-21 14:13:36 +020060 withProgress(message = 'Berechnung läuft: ', value = 0, {
61 hc <- plotHighchart(query, vc , years)
62 })
63 hc
64 }
65}
66
67
68function(input, output, session) {
69 observe({
70 queryParams <- parseQueryString(session$clientData$url_search)
Marc Kupietzfc715182021-03-02 08:12:59 +010071 if (!is.null(queryParams[['from']])) {
72 from <- queryParams[['from']]
73 updateSliderInput(session, "from", value = from)
74 } else {
75 from <- 2005
76 }
77 if (!is.null(queryParams[['to']])) {
78 to <- queryParams[['to']]
79 updateSliderInput(session, "to", value = to)
80 } else {
Marc Kupietzf46a1372022-08-29 13:54:48 +020081 to <- 2021
Marc Kupietzfc715182021-03-02 08:12:59 +010082 }
Marc Kupietz00455202020-10-21 14:13:36 +020083 if (!is.null(queryParams[['q']])) {
84 paramWord <- queryParams[['q']]
85 updateTextInput(session, "q", value = paramWord)
86 output$hcontainer <-
Marc Kupietzfc715182021-03-02 08:12:59 +010087 renderHighchart(generateHighchart(paramWord, from, to))
Marc Kupietz00455202020-10-21 14:13:36 +020088 }
89 })
Marc Kupietzfc715182021-03-02 08:12:59 +010090
Marc Kupietz00455202020-10-21 14:13:36 +020091 observeEvent(input$goButton,
92 {
93 output$hcontainer <-
Marc Kupietzfc715182021-03-02 08:12:59 +010094 renderHighchart(generateHighchart(isolate(input$q), isolate(input$from), isolate(input$to)))
Marc Kupietz00455202020-10-21 14:13:36 +020095 })
Marc Kupietzfc715182021-03-02 08:12:59 +010096
Marc Kupietz00455202020-10-21 14:13:36 +020097}