blob: 03b39e29122f51a35a3a4ba43bdfa26ec18ed0e2 [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
11to query DeReKo, otherwise.}
12
13\item{apiVersion}{which version of KorAP's API you want to connect to. Defaults to "v1.0".}
14
15\item{apiUrl}{URL of the KorAP web service. If not provided, it will be constructed from KorAPUrl and apiVersion.}
16
17\item{accessToken}{OAuth2 access token. For queries on corpus parts with restricted
18access (e.g. textual queries on IPR protected data), you need to authorize
19your application with an access token.
20You can obtain an access token in the OAuth settings of your KorAP web interface.
21
22More details are explained in the
23\href{https://github.com/KorAP/RKorAPClient#authorization}{authorization section}
24of the RKorAPClient Readme on GitHub.
25
26To use authorization based on an access token
27in subsequent queries, initialize your KorAP connection with:
28
29\if{html}{\out{<div class="sourceCode">}}\preformatted{kco <- KorAPConnection(accessToken="<access token>")
30}\if{html}{\out{</div>}}
31
32In order to make the API
33token persistent for the currently used \code{KorAPUrl} (you can have one
34token per KorAPUrl / KorAP server instance), use:
35
36\if{html}{\out{<div class="sourceCode">}}\preformatted{persistAccessToken(kco)
37}\if{html}{\out{</div>}}
38
39This will store it in your keyring using the
40\link[keyring:keyring-package]{keyring::keyring-package}. Subsequent KorAPConnection() calls will
41then automatically retrieve the token from your keying. To stop using a
42persisted token, call \code{clearAccessToken(kco)}. Please note that for
43DeReKo, authorized queries will behave differently inside and outside the
44IDS, because of the special license situation. This concerns also cached
45results which do not take into account from where a request was issued. If
46you experience problems or unexpected results, please try \code{kco <- KorAPConnection(cache=FALSE)} or use
47\code{\link[=clearCache]{clearCache()}} to clear the cache completely.
48
49An alternative to using an access token is to use a browser-based oauth2 workflow
50to obtain an access token. This can be done with the \code{\link[=auth]{auth()}} method.}
51
52\item{oauthClient}{OAuth2 client object (advanced users only).}
53
54\item{oauthScope}{OAuth2 scope. Defaults to "search match_info".}
55
56\item{authorizationSupported}{logical that indicates if authorization is supported/necessary for the current KorAP instance. Automatically set during initialization.}
57
58\item{userAgent}{user agent string. Defaults to "R-KorAP-Client".}
59
60\item{timeout}{timeout in seconds for API requests (this does not influence server internal timeouts). Defaults to 240 seconds.}
61
62\item{verbose}{logical that decides whether following operations will default to
63be verbose. Defaults to FALSE.}
64
65\item{cache}{logical that decides if API calls are cached locally. You can clear
66the cache with \code{\link[=clearCache]{clearCache()}}. Defaults to TRUE.}
67}
68\value{
69\code{\link[=KorAPConnection]{KorAPConnection()}} object that can be used e.g. with \code{\link[=corpusQuery]{corpusQuery()}}
70}
Marc Kupietze95108e2019-09-18 13:23:58 +020071\description{
Marc Kupietza8c40f42025-06-24 15:49:52 +020072\code{KorAPConnection()} creates a connection to a KorAP server for corpus queries.
73This is your starting point for all corpus analysis tasks.
Marc Kupietze95108e2019-09-18 13:23:58 +020074}
Marc Kupietza8c40f42025-06-24 15:49:52 +020075\details{
76Use \code{KorAPConnection()} to connect, then \code{corpusQuery()} to search, and
77\code{fetchAll()} to retrieve results. For authorized access to restricted corpora,
78use \code{auth()} or provide an \code{accessToken}.
Marc Kupietza81343d2022-09-06 12:32:10 +020079
Marc Kupietza8c40f42025-06-24 15:49:52 +020080The KorAPConnection object contains various configuration slots for advanced users:
81KorAPUrl (server URL), apiVersion, accessToken (OAuth2 token),
82timeout (request timeout), verbose (logging), cache (local caching),
83and other technical parameters. Most users can ignore these implementation details.
84}
85\section{Basic Workflow}{
Marc Kupietza81343d2022-09-06 12:32:10 +020086
Marc Kupietza81343d2022-09-06 12:32:10 +020087
Marc Kupietza8c40f42025-06-24 15:49:52 +020088\if{html}{\out{<div class="sourceCode r">}}\preformatted{# Connect to KorAP
89kcon <- KorAPConnection()
Marc Kupietza81343d2022-09-06 12:32:10 +020090
Marc Kupietza8c40f42025-06-24 15:49:52 +020091# Search for a term
92query <- corpusQuery(kcon, "Ameisenplage")
Marc Kupietza81343d2022-09-06 12:32:10 +020093
Marc Kupietza8c40f42025-06-24 15:49:52 +020094# Get all results
95results <- fetchAll(query)
96}\if{html}{\out{</div>}}
Marc Kupietz05b22772020-02-18 21:58:42 +010097}
Marc Kupietze95108e2019-09-18 13:23:58 +020098
Marc Kupietza8c40f42025-06-24 15:49:52 +020099\section{Authorization}{
Marc Kupietz6ae76052021-09-21 10:34:00 +0200100
Marc Kupietza8c40f42025-06-24 15:49:52 +0200101For access to restricted corpora, authorize your connection:
102
103\if{html}{\out{<div class="sourceCode r">}}\preformatted{kcon <- KorAPConnection() |> auth()
104}\if{html}{\out{</div>}}
Marc Kupietz4862b862019-11-07 10:13:53 +0100105}
106
Marc Kupietza8c40f42025-06-24 15:49:52 +0200107\seealso{
108Other initialization functions:
109\code{\link{auth,KorAPConnection-method}},
110\code{\link{clearAccessToken,KorAPConnection-method}},
111\code{\link{persistAccessToken,KorAPConnection-method}}
Marc Kupietze95108e2019-09-18 13:23:58 +0200112}
Marc Kupietza8c40f42025-06-24 15:49:52 +0200113\concept{initialization functions}