blob: ab0b7a108512b258a3ce38dd33733e89e1ab30d3 [file] [log] [blame]
Marc Kupietze95108e2019-09-18 13:23:58 +02001% 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 Kupietza8c40f42025-06-24 15:49:52 +02007\title{Connect to KorAP Server}
Marc Kupietzf9914bb2025-06-25 09:57:55 +02008\arguments{
9\item{KorAPUrl}{URL of the web user interface of the KorAP server instance you want to access.
10Defaults to the environment variable \code{KORAP_URL} if set and to the IDS Mannheim KorAP main instance
Marc Kupietz36117de2025-06-25 12:46:10 +020011to query DeReKo, otherwise. In order to access the KorAP instance at the German
12National Library (DNB) to query the contemporary fiction corpus DeLiKo@DNB,
13for example, set \code{KorAPUrl} to \url{https://korap.dnb.de/}.}
Marc Kupietzf9914bb2025-06-25 09:57:55 +020014
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
20access (e.g. textual queries on IPR protected data), you need to authorize
21your application with an access token.
22You can obtain an access token in the OAuth settings of your KorAP web interface.
23
24More details are explained in the
25\href{https://github.com/KorAP/RKorAPClient#authorization}{authorization section}
26of the RKorAPClient Readme on GitHub.
27
28To use authorization based on an access token
29in 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
34In order to make the API
35token persistent for the currently used \code{KorAPUrl} (you can have one
36token per KorAPUrl / KorAP server instance), use:
37
38\if{html}{\out{<div class="sourceCode">}}\preformatted{persistAccessToken(kco)
39}\if{html}{\out{</div>}}
40
41This will store it in your keyring using the
42\link[keyring:keyring-package]{keyring::keyring-package}. Subsequent KorAPConnection() calls will
43then automatically retrieve the token from your keying. To stop using a
44persisted token, call \code{clearAccessToken(kco)}. Please note that for
45DeReKo, authorized queries will behave differently inside and outside the
46IDS, because of the special license situation. This concerns also cached
47results which do not take into account from where a request was issued. If
48you 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
51An alternative to using an access token is to use a browser-based oauth2 workflow
52to obtain an access token. This can be done with the \code{\link[=auth]{auth()}} method.}
53
Marc Kupietz36117de2025-06-25 12:46:10 +020054\item{oauthClient}{OAuth2 client object.}
Marc Kupietzf9914bb2025-06-25 09:57:55 +020055
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
65be verbose. Defaults to FALSE.}
66
67\item{cache}{logical that decides if API calls are cached locally. You can clear
68the 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 Kupietze95108e2019-09-18 13:23:58 +020073\description{
Marc Kupietza8c40f42025-06-24 15:49:52 +020074\code{KorAPConnection()} creates a connection to a KorAP server for corpus queries.
75This is your starting point for all corpus analysis tasks.
Marc Kupietze95108e2019-09-18 13:23:58 +020076}
Marc Kupietza8c40f42025-06-24 15:49:52 +020077\details{
78Use \code{KorAPConnection()} to connect, then \code{corpusQuery()} to search, and
79\code{fetchAll()} to retrieve results. For authorized access to restricted corpora,
80use \code{auth()} or provide an \code{accessToken}.
Marc Kupietza81343d2022-09-06 12:32:10 +020081
Marc Kupietza8c40f42025-06-24 15:49:52 +020082The KorAPConnection object contains various configuration slots for advanced users:
83KorAPUrl (server URL), apiVersion, accessToken (OAuth2 token),
84timeout (request timeout), verbose (logging), cache (local caching),
85and other technical parameters. Most users can ignore these implementation details.
86}
87\section{Basic Workflow}{
Marc Kupietza81343d2022-09-06 12:32:10 +020088
Marc Kupietza81343d2022-09-06 12:32:10 +020089
Marc Kupietza8c40f42025-06-24 15:49:52 +020090\if{html}{\out{<div class="sourceCode r">}}\preformatted{# Connect to KorAP
91kcon <- KorAPConnection()
Marc Kupietza81343d2022-09-06 12:32:10 +020092
Marc Kupietza8c40f42025-06-24 15:49:52 +020093# Search for a term
94query <- corpusQuery(kcon, "Ameisenplage")
Marc Kupietza81343d2022-09-06 12:32:10 +020095
Marc Kupietza8c40f42025-06-24 15:49:52 +020096# Get all results
97results <- fetchAll(query)
98}\if{html}{\out{</div>}}
Marc Kupietz05b22772020-02-18 21:58:42 +010099}
Marc Kupietze95108e2019-09-18 13:23:58 +0200100
Marc Kupietza8c40f42025-06-24 15:49:52 +0200101\section{Authorization}{
Marc Kupietz6ae76052021-09-21 10:34:00 +0200102
Marc Kupietza8c40f42025-06-24 15:49:52 +0200103For 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 Kupietz4862b862019-11-07 10:13:53 +0100107}
108
Marc Kupietza8c40f42025-06-24 15:49:52 +0200109\seealso{
110Other initialization functions:
111\code{\link{auth,KorAPConnection-method}},
112\code{\link{clearAccessToken,KorAPConnection-method}},
113\code{\link{persistAccessToken,KorAPConnection-method}}
Marc Kupietze95108e2019-09-18 13:23:58 +0200114}
Marc Kupietza8c40f42025-06-24 15:49:52 +0200115\concept{initialization functions}