Marc Kupietz | e95108e | 2019-09-18 13:23:58 +0200 | [diff] [blame] | 1 | % Generated by roxygen2: do not edit by hand |
| 2 | % Please edit documentation in R/KorAPConnection.R |
| 3 | \docType{class} |
| 4 | \name{KorAPConnection-class} |
| 5 | \alias{KorAPConnection-class} |
| 6 | \alias{KorAPConnection} |
Marc Kupietz | a8c40f4 | 2025-06-24 15:49:52 +0200 | [diff] [blame] | 7 | \title{Connect to KorAP Server} |
Marc Kupietz | f9914bb | 2025-06-25 09:57:55 +0200 | [diff] [blame] | 8 | \arguments{ |
| 9 | \item{KorAPUrl}{URL of the web user interface of the KorAP server instance you want to access. |
| 10 | Defaults to the environment variable \code{KORAP_URL} if set and to the IDS Mannheim KorAP main instance |
Marc Kupietz | 36117de | 2025-06-25 12:46:10 +0200 | [diff] [blame] | 11 | to query DeReKo, otherwise. In order to access the KorAP instance at the German |
| 12 | National Library (DNB) to query the contemporary fiction corpus DeLiKo@DNB, |
| 13 | for example, set \code{KorAPUrl} to \url{https://korap.dnb.de/}.} |
Marc Kupietz | f9914bb | 2025-06-25 09:57:55 +0200 | [diff] [blame] | 14 | |
| 15 | \item{apiVersion}{which version of KorAP's API you want to connect to. Defaults to "v1.0".} |
| 16 | |
| 17 | \item{apiUrl}{URL of the KorAP web service. If not provided, it will be constructed from KorAPUrl and apiVersion.} |
| 18 | |
| 19 | \item{accessToken}{OAuth2 access token. For queries on corpus parts with restricted |
| 20 | access (e.g. textual queries on IPR protected data), you need to authorize |
| 21 | your application with an access token. |
| 22 | You can obtain an access token in the OAuth settings of your KorAP web interface. |
| 23 | |
| 24 | More details are explained in the |
| 25 | \href{https://github.com/KorAP/RKorAPClient#authorization}{authorization section} |
| 26 | of the RKorAPClient Readme on GitHub. |
| 27 | |
| 28 | To use authorization based on an access token |
| 29 | in subsequent queries, initialize your KorAP connection with: |
| 30 | |
| 31 | \if{html}{\out{<div class="sourceCode">}}\preformatted{kco <- KorAPConnection(accessToken="<access token>") |
| 32 | }\if{html}{\out{</div>}} |
| 33 | |
| 34 | In order to make the API |
| 35 | token persistent for the currently used \code{KorAPUrl} (you can have one |
| 36 | token per KorAPUrl / KorAP server instance), use: |
| 37 | |
| 38 | \if{html}{\out{<div class="sourceCode">}}\preformatted{persistAccessToken(kco) |
| 39 | }\if{html}{\out{</div>}} |
| 40 | |
| 41 | This will store it in your keyring using the |
| 42 | \link[keyring:keyring-package]{keyring::keyring-package}. Subsequent KorAPConnection() calls will |
| 43 | then automatically retrieve the token from your keying. To stop using a |
| 44 | persisted token, call \code{clearAccessToken(kco)}. Please note that for |
| 45 | DeReKo, authorized queries will behave differently inside and outside the |
| 46 | IDS, because of the special license situation. This concerns also cached |
| 47 | results which do not take into account from where a request was issued. If |
| 48 | you experience problems or unexpected results, please try \code{kco <- KorAPConnection(cache=FALSE)} or use |
| 49 | \code{\link[=clearCache]{clearCache()}} to clear the cache completely. |
| 50 | |
| 51 | An alternative to using an access token is to use a browser-based oauth2 workflow |
| 52 | to obtain an access token. This can be done with the \code{\link[=auth]{auth()}} method.} |
| 53 | |
Marc Kupietz | 36117de | 2025-06-25 12:46:10 +0200 | [diff] [blame] | 54 | \item{oauthClient}{OAuth2 client object.} |
Marc Kupietz | f9914bb | 2025-06-25 09:57:55 +0200 | [diff] [blame] | 55 | |
| 56 | \item{oauthScope}{OAuth2 scope. Defaults to "search match_info".} |
| 57 | |
| 58 | \item{authorizationSupported}{logical that indicates if authorization is supported/necessary for the current KorAP instance. Automatically set during initialization.} |
| 59 | |
| 60 | \item{userAgent}{user agent string. Defaults to "R-KorAP-Client".} |
| 61 | |
| 62 | \item{timeout}{timeout in seconds for API requests (this does not influence server internal timeouts). Defaults to 240 seconds.} |
| 63 | |
| 64 | \item{verbose}{logical that decides whether following operations will default to |
| 65 | be verbose. Defaults to FALSE.} |
| 66 | |
| 67 | \item{cache}{logical that decides if API calls are cached locally. You can clear |
| 68 | the cache with \code{\link[=clearCache]{clearCache()}}. Defaults to TRUE.} |
| 69 | } |
| 70 | \value{ |
| 71 | \code{\link[=KorAPConnection]{KorAPConnection()}} object that can be used e.g. with \code{\link[=corpusQuery]{corpusQuery()}} |
| 72 | } |
Marc Kupietz | e95108e | 2019-09-18 13:23:58 +0200 | [diff] [blame] | 73 | \description{ |
Marc Kupietz | a8c40f4 | 2025-06-24 15:49:52 +0200 | [diff] [blame] | 74 | \code{KorAPConnection()} creates a connection to a KorAP server for corpus queries. |
| 75 | This is your starting point for all corpus analysis tasks. |
Marc Kupietz | e95108e | 2019-09-18 13:23:58 +0200 | [diff] [blame] | 76 | } |
Marc Kupietz | a8c40f4 | 2025-06-24 15:49:52 +0200 | [diff] [blame] | 77 | \details{ |
| 78 | Use \code{KorAPConnection()} to connect, then \code{corpusQuery()} to search, and |
| 79 | \code{fetchAll()} to retrieve results. For authorized access to restricted corpora, |
| 80 | use \code{auth()} or provide an \code{accessToken}. |
Marc Kupietz | a81343d | 2022-09-06 12:32:10 +0200 | [diff] [blame] | 81 | |
Marc Kupietz | a8c40f4 | 2025-06-24 15:49:52 +0200 | [diff] [blame] | 82 | The KorAPConnection object contains various configuration slots for advanced users: |
| 83 | KorAPUrl (server URL), apiVersion, accessToken (OAuth2 token), |
| 84 | timeout (request timeout), verbose (logging), cache (local caching), |
| 85 | and other technical parameters. Most users can ignore these implementation details. |
| 86 | } |
| 87 | \section{Basic Workflow}{ |
Marc Kupietz | a81343d | 2022-09-06 12:32:10 +0200 | [diff] [blame] | 88 | |
Marc Kupietz | a81343d | 2022-09-06 12:32:10 +0200 | [diff] [blame] | 89 | |
Marc Kupietz | a8c40f4 | 2025-06-24 15:49:52 +0200 | [diff] [blame] | 90 | \if{html}{\out{<div class="sourceCode r">}}\preformatted{# Connect to KorAP |
| 91 | kcon <- KorAPConnection() |
Marc Kupietz | a81343d | 2022-09-06 12:32:10 +0200 | [diff] [blame] | 92 | |
Marc Kupietz | a8c40f4 | 2025-06-24 15:49:52 +0200 | [diff] [blame] | 93 | # Search for a term |
| 94 | query <- corpusQuery(kcon, "Ameisenplage") |
Marc Kupietz | a81343d | 2022-09-06 12:32:10 +0200 | [diff] [blame] | 95 | |
Marc Kupietz | a8c40f4 | 2025-06-24 15:49:52 +0200 | [diff] [blame] | 96 | # Get all results |
| 97 | results <- fetchAll(query) |
| 98 | }\if{html}{\out{</div>}} |
Marc Kupietz | 05b2277 | 2020-02-18 21:58:42 +0100 | [diff] [blame] | 99 | } |
Marc Kupietz | e95108e | 2019-09-18 13:23:58 +0200 | [diff] [blame] | 100 | |
Marc Kupietz | a8c40f4 | 2025-06-24 15:49:52 +0200 | [diff] [blame] | 101 | \section{Authorization}{ |
Marc Kupietz | 6ae7605 | 2021-09-21 10:34:00 +0200 | [diff] [blame] | 102 | |
Marc Kupietz | a8c40f4 | 2025-06-24 15:49:52 +0200 | [diff] [blame] | 103 | For access to restricted corpora, authorize your connection: |
| 104 | |
| 105 | \if{html}{\out{<div class="sourceCode r">}}\preformatted{kcon <- KorAPConnection() |> auth() |
| 106 | }\if{html}{\out{</div>}} |
Marc Kupietz | 4862b86 | 2019-11-07 10:13:53 +0100 | [diff] [blame] | 107 | } |
| 108 | |
Marc Kupietz | a8c40f4 | 2025-06-24 15:49:52 +0200 | [diff] [blame] | 109 | \seealso{ |
| 110 | Other initialization functions: |
| 111 | \code{\link{auth,KorAPConnection-method}}, |
| 112 | \code{\link{clearAccessToken,KorAPConnection-method}}, |
| 113 | \code{\link{persistAccessToken,KorAPConnection-method}} |
Marc Kupietz | e95108e | 2019-09-18 13:23:58 +0200 | [diff] [blame] | 114 | } |
Marc Kupietz | a8c40f4 | 2025-06-24 15:49:52 +0200 | [diff] [blame] | 115 | \concept{initialization functions} |