blob: 018573fe87775a7b4834f195f156f1553eb046df [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 Kupietz6a16d7d2026-08-31 21:36:01 +02008\usage{
9KorAPConnection(
10 KorAPUrl = defaultKorAPUrl(),
11 apiVersion = "v1.0",
12 apiUrl,
13 accessToken = getAccessToken(KorAPUrl),
14 oauthClient = NULL,
15 oauthScope = "search match_info",
16 authorizationSupported = TRUE,
17 userAgent = "R-KorAP-Client",
18 timeout = 240,
19 verbose = FALSE,
20 cache = TRUE
21)
22}
Marc Kupietzf9914bb2025-06-25 09:57:55 +020023\arguments{
24\item{KorAPUrl}{URL of the web user interface of the KorAP server instance you want to access.
25Defaults to the environment variable \code{KORAP_URL} if set and to the IDS Mannheim KorAP main instance
Marc Kupietz36117de2025-06-25 12:46:10 +020026to query DeReKo, otherwise. In order to access the KorAP instance at the German
27National Library (DNB) to query the contemporary fiction corpus DeLiKo@DNB,
28for example, set \code{KorAPUrl} to \url{https://korap.dnb.de/}.}
Marc Kupietzf9914bb2025-06-25 09:57:55 +020029
30\item{apiVersion}{which version of KorAP's API you want to connect to. Defaults to "v1.0".}
31
32\item{apiUrl}{URL of the KorAP web service. If not provided, it will be constructed from KorAPUrl and apiVersion.}
33
34\item{accessToken}{OAuth2 access token. For queries on corpus parts with restricted
35access (e.g. textual queries on IPR protected data), you need to authorize
36your application with an access token.
37You can obtain an access token in the OAuth settings of your KorAP web interface.
38
39More details are explained in the
40\href{https://github.com/KorAP/RKorAPClient#authorization}{authorization section}
41of the RKorAPClient Readme on GitHub.
42
43To use authorization based on an access token
44in subsequent queries, initialize your KorAP connection with:
45
46\if{html}{\out{<div class="sourceCode">}}\preformatted{kco <- KorAPConnection(accessToken="<access token>")
47}\if{html}{\out{</div>}}
48
49In order to make the API
50token persistent for the currently used \code{KorAPUrl} (you can have one
51token per KorAPUrl / KorAP server instance), use:
52
53\if{html}{\out{<div class="sourceCode">}}\preformatted{persistAccessToken(kco)
54}\if{html}{\out{</div>}}
55
56This will store it in your keyring using the
57\link[keyring:keyring-package]{keyring::keyring-package}. Subsequent KorAPConnection() calls will
58then automatically retrieve the token from your keying. To stop using a
59persisted token, call \code{clearAccessToken(kco)}. Please note that for
60DeReKo, authorized queries will behave differently inside and outside the
61IDS, because of the special license situation. This concerns also cached
62results which do not take into account from where a request was issued. If
63you experience problems or unexpected results, please try \code{kco <- KorAPConnection(cache=FALSE)} or use
64\code{\link[=clearCache]{clearCache()}} to clear the cache completely.
65
66An alternative to using an access token is to use a browser-based oauth2 workflow
67to obtain an access token. This can be done with the \code{\link[=auth]{auth()}} method.}
68
Marc Kupietz36117de2025-06-25 12:46:10 +020069\item{oauthClient}{OAuth2 client object.}
Marc Kupietzf9914bb2025-06-25 09:57:55 +020070
71\item{oauthScope}{OAuth2 scope. Defaults to "search match_info".}
72
73\item{authorizationSupported}{logical that indicates if authorization is supported/necessary for the current KorAP instance. Automatically set during initialization.}
74
75\item{userAgent}{user agent string. Defaults to "R-KorAP-Client".}
76
77\item{timeout}{timeout in seconds for API requests (this does not influence server internal timeouts). Defaults to 240 seconds.}
78
79\item{verbose}{logical that decides whether following operations will default to
Marc Kupietz39da9dc2025-09-10 13:54:40 +020080be verbose. Defaults to FALSE. If not explicitly provided, this can be overridden
81via environment variable \code{KORAP_VERBOSE} (accepted true-ish values: 1, true, yes, on)
82or R option \code{rkorap.verbose} (logical).}
Marc Kupietzf9914bb2025-06-25 09:57:55 +020083
84\item{cache}{logical that decides if API calls are cached locally. You can clear
85the cache with \code{\link[=clearCache]{clearCache()}}. Defaults to TRUE.}
86}
87\value{
88\code{\link[=KorAPConnection]{KorAPConnection()}} object that can be used e.g. with \code{\link[=corpusQuery]{corpusQuery()}}
89}
Marc Kupietze95108e2019-09-18 13:23:58 +020090\description{
Marc Kupietza8c40f42025-06-24 15:49:52 +020091\code{KorAPConnection()} creates a connection to a KorAP server for corpus queries.
92This is your starting point for all corpus analysis tasks.
Marc Kupietze95108e2019-09-18 13:23:58 +020093}
Marc Kupietza8c40f42025-06-24 15:49:52 +020094\details{
95Use \code{KorAPConnection()} to connect, then \code{corpusQuery()} to search, and
96\code{fetchAll()} to retrieve results. For authorized access to restricted corpora,
97use \code{auth()} or provide an \code{accessToken}.
Marc Kupietza81343d2022-09-06 12:32:10 +020098
Marc Kupietza8c40f42025-06-24 15:49:52 +020099The KorAPConnection object contains various configuration slots for advanced users:
100KorAPUrl (server URL), apiVersion, accessToken (OAuth2 token),
101timeout (request timeout), verbose (logging), cache (local caching),
102and other technical parameters. Most users can ignore these implementation details.
103}
104\section{Basic Workflow}{
Marc Kupietza81343d2022-09-06 12:32:10 +0200105
Marc Kupietza81343d2022-09-06 12:32:10 +0200106
Marc Kupietza8c40f42025-06-24 15:49:52 +0200107\if{html}{\out{<div class="sourceCode r">}}\preformatted{# Connect to KorAP
108kcon <- KorAPConnection()
Marc Kupietza81343d2022-09-06 12:32:10 +0200109
Marc Kupietza8c40f42025-06-24 15:49:52 +0200110# Search for a term
111query <- corpusQuery(kcon, "Ameisenplage")
Marc Kupietza81343d2022-09-06 12:32:10 +0200112
Marc Kupietza8c40f42025-06-24 15:49:52 +0200113# Get all results
114results <- fetchAll(query)
115}\if{html}{\out{</div>}}
Marc Kupietz05b22772020-02-18 21:58:42 +0100116}
Marc Kupietze95108e2019-09-18 13:23:58 +0200117
Marc Kupietza8c40f42025-06-24 15:49:52 +0200118\section{Authorization}{
Marc Kupietz6ae76052021-09-21 10:34:00 +0200119
Marc Kupietza8c40f42025-06-24 15:49:52 +0200120For access to restricted corpora, authorize your connection:
121
122\if{html}{\out{<div class="sourceCode r">}}\preformatted{kcon <- KorAPConnection() |> auth()
123}\if{html}{\out{</div>}}
Marc Kupietz4862b862019-11-07 10:13:53 +0100124}
125
Marc Kupietza8c40f42025-06-24 15:49:52 +0200126\seealso{
Marc Kupietz209b52c2026-06-21 12:14:36 +0200127Other initialization functions:
Marc Kupietza8c40f42025-06-24 15:49:52 +0200128\code{\link{auth,KorAPConnection-method}},
129\code{\link{clearAccessToken,KorAPConnection-method}},
130\code{\link{persistAccessToken,KorAPConnection-method}}
Marc Kupietze95108e2019-09-18 13:23:58 +0200131}
Marc Kupietza8c40f42025-06-24 15:49:52 +0200132\concept{initialization functions}