Marc Kupietz | 381cb98 | 2023-05-13 15:06:32 +0200 | [diff] [blame^] | 1 | library(RKorAPClient) |
| 2 | library(httr2) |
| 3 | library(kableExtra) |
| 4 | |
| 5 | demo_kor_app_id = "773NHGM76N7P9b6rLfmpM4" |
| 6 | |
| 7 | oauthorizeDemo <- function(kco, app_id = demo_kor_app_id) { |
| 8 | if (is.null(kco@accessToken) || is.null(kco@welcome)) { # if access token is not set or invalid |
| 9 | kco@accessToken <- ( # request one |
| 10 | oauth_client( |
| 11 | id = app_id, # for the demo application |
| 12 | token_url = paste0(kco@apiUrl, "oauth2/token") |
| 13 | ) %>% |
| 14 | oauth_flow_auth_code( |
| 15 | scope = "search match_info", |
| 16 | auth_url = paste0(kco@KorAPUrl, "settings/oauth/authorize") |
| 17 | ) |
| 18 | )$access_token |
| 19 | } |
| 20 | print(kco@accessToken) |
| 21 | return(kco) |
| 22 | } |
| 23 | |
| 24 | new("KorAPConnection", verbose = TRUE) %>% |
| 25 | oauthorizeDemo() %>% |
| 26 | collocationAnalysis("focus([marmot/p=ADJA] {Gendern})", leftContextSize=1, rightContextSize=0) %>% |
| 27 | mutate(collocate = paste0('<a href="', webUIRequestUrl, '">', collocate, '</a>')) %>% |
| 28 | select(collocate, O, pmi, mi2, mi3, logDice, ll) %>% |
| 29 | kable(escape = FALSE, caption = "Adjective collocates of 'Gendern'") %>% |
| 30 | kable_styling() %>% |
| 31 | print() |
| 32 | |