blob: 3ccaae2ee739d96a81c25b0abb1624b2a9855e24 [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
Marc Kupietz39da9dc2025-09-10 13:54:40 +020065be verbose. Defaults to FALSE. If not explicitly provided, this can be overridden
66via environment variable \code{KORAP_VERBOSE} (accepted true-ish values: 1, true, yes, on)
67or R option \code{rkorap.verbose} (logical).}
Marc Kupietzf9914bb2025-06-25 09:57:55 +020068
69\item{cache}{logical that decides if API calls are cached locally. You can clear
70the cache with \code{\link[=clearCache]{clearCache()}}. Defaults to TRUE.}
71}
72\value{
73\code{\link[=KorAPConnection]{KorAPConnection()}} object that can be used e.g. with \code{\link[=corpusQuery]{corpusQuery()}}
74}
Marc Kupietze95108e2019-09-18 13:23:58 +020075\description{
Marc Kupietza8c40f42025-06-24 15:49:52 +020076\code{KorAPConnection()} creates a connection to a KorAP server for corpus queries.
77This is your starting point for all corpus analysis tasks.
Marc Kupietze95108e2019-09-18 13:23:58 +020078}
Marc Kupietza8c40f42025-06-24 15:49:52 +020079\details{
80Use \code{KorAPConnection()} to connect, then \code{corpusQuery()} to search, and
81\code{fetchAll()} to retrieve results. For authorized access to restricted corpora,
82use \code{auth()} or provide an \code{accessToken}.
Marc Kupietza81343d2022-09-06 12:32:10 +020083
Marc Kupietza8c40f42025-06-24 15:49:52 +020084The KorAPConnection object contains various configuration slots for advanced users:
85KorAPUrl (server URL), apiVersion, accessToken (OAuth2 token),
86timeout (request timeout), verbose (logging), cache (local caching),
87and other technical parameters. Most users can ignore these implementation details.
88}
89\section{Basic Workflow}{
Marc Kupietza81343d2022-09-06 12:32:10 +020090
Marc Kupietza81343d2022-09-06 12:32:10 +020091
Marc Kupietza8c40f42025-06-24 15:49:52 +020092\if{html}{\out{<div class="sourceCode r">}}\preformatted{# Connect to KorAP
93kcon <- KorAPConnection()
Marc Kupietza81343d2022-09-06 12:32:10 +020094
Marc Kupietza8c40f42025-06-24 15:49:52 +020095# Search for a term
96query <- corpusQuery(kcon, "Ameisenplage")
Marc Kupietza81343d2022-09-06 12:32:10 +020097
Marc Kupietza8c40f42025-06-24 15:49:52 +020098# Get all results
99results <- fetchAll(query)
100}\if{html}{\out{</div>}}
Marc Kupietz05b22772020-02-18 21:58:42 +0100101}
Marc Kupietze95108e2019-09-18 13:23:58 +0200102
Marc Kupietza8c40f42025-06-24 15:49:52 +0200103\section{Authorization}{
Marc Kupietz6ae76052021-09-21 10:34:00 +0200104
Marc Kupietza8c40f42025-06-24 15:49:52 +0200105For access to restricted corpora, authorize your connection:
106
107\if{html}{\out{<div class="sourceCode r">}}\preformatted{kcon <- KorAPConnection() |> auth()
108}\if{html}{\out{</div>}}
Marc Kupietz4862b862019-11-07 10:13:53 +0100109}
110
Marc Kupietza8c40f42025-06-24 15:49:52 +0200111\seealso{
112Other initialization functions:
113\code{\link{auth,KorAPConnection-method}},
114\code{\link{clearAccessToken,KorAPConnection-method}},
115\code{\link{persistAccessToken,KorAPConnection-method}}
Marc Kupietze95108e2019-09-18 13:23:58 +0200116}
Marc Kupietza8c40f42025-06-24 15:49:52 +0200117\concept{initialization functions}