blob: bf7559901669f024f2bfad14ac72cd626243c4dd [file] [log] [blame]
Marc Kupietza29f3d42025-07-18 10:14:43 +02001% Generated by roxygen2: do not edit by hand
2% Please edit documentation in R/KorAPQuery.R
3\name{fetchAnnotations,KorAPQuery-method}
4\alias{fetchAnnotations,KorAPQuery-method}
5\alias{fetchAnnotations}
6\title{Fetch annotations for all collected matches}
7\usage{
Marc Kupietz93787d52025-09-03 13:33:25 +02008\S4method{fetchAnnotations}{KorAPQuery}(
9 kqo,
10 foundry = "tt",
11 overwrite = FALSE,
12 verbose = kqo@korapConnection@verbose
13)
Marc Kupietza29f3d42025-07-18 10:14:43 +020014}
15\arguments{
16\item{kqo}{object obtained from \code{\link[=corpusQuery]{corpusQuery()}} with collected matches. Note: the original corpus query should have \code{metadataOnly = FALSE} for annotation parsing to work.}
17
18\item{foundry}{string specifying the foundry to use for annotations (default: "tt" for Tree-Tagger)}
19
Marc Kupietz93787d52025-09-03 13:33:25 +020020\item{overwrite}{logical; if TRUE, re-fetch and replace any existing
21annotation columns. If FALSE (default), only add missing annotation layers
22and preserve already fetched ones (e.g., keep POS/lemma from a previous
23foundry while adding morph from another).}
24
Marc Kupietza29f3d42025-07-18 10:14:43 +020025\item{verbose}{print progress information if true}
26}
27\value{
Marc Kupietz89f796e2025-07-19 09:05:06 +020028The updated \code{kqo} object with annotation columns
29like \code{pos}, \code{lemma}, \code{morph} (and \code{atokens} and \code{annotation_snippet})
30in the \verb{@collectedMatches} slot. Each column is a data frame
31with \code{left}, \code{match}, and \code{right} columns containing list vectors of annotations
32for the left context, matched tokens, and right context, respectively.
33The original XML snippet for each match is also stored in \code{annotation_snippet}.
Marc Kupietza29f3d42025-07-18 10:14:43 +020034}
35\description{
Marc Kupietz89f796e2025-07-19 09:05:06 +020036\ifelse{html}{\href{https://lifecycle.r-lib.org/articles/stages.html#experimental}{\figure{lifecycle-experimental.svg}{options: alt='[Experimental]'}}}{\strong{[Experimental]}}
Marc Kupietza29f3d42025-07-18 10:14:43 +020037}
38\details{
Marc Kupietz89f796e2025-07-19 09:05:06 +020039\strong{\code{fetchAnnotations}} fetches annotations (only token annotations, for now)
40for all matches in the \verb{@collectedMatches} slot
41of a KorAPQuery object and adds annotation columns directly to the \verb{@collectedMatches}
42data frame. The method uses the \code{matchID} from collected matches.
43
Marc Kupietza29f3d42025-07-18 10:14:43 +020044\strong{Important}: For copyright-restricted corpora, users must be authorized via \code{\link[=auth]{auth()}}
45and the initial corpus query must have \code{metadataOnly = FALSE} to ensure snippets are
46available for annotation parsing.
47
48The method parses XML snippet annotations and adds linguistic columns to the data frame:
49\itemize{
50\item \code{pos}: data frame with \code{left}, \code{match}, \code{right} columns, each containing list vectors of part-of-speech tags
51\item \code{lemma}: data frame with \code{left}, \code{match}, \code{right} columns, each containing list vectors of lemmas
52\item \code{morph}: data frame with \code{left}, \code{match}, \code{right} columns, each containing list vectors of morphological tags
53\item \code{atokens}: data frame with \code{left}, \code{match}, \code{right} columns, each containing list vectors of token text (from annotations)
54\item \code{annotation_snippet}: original XML snippet from the annotation API
55}
56}
57\examples{
58\dontrun{
59
60# Fetch annotations for matches using Tree-Tagger foundry
61# Note: Authorization required for copyright-restricted corpora
62q <- KorAPConnection() |>
63 auth() |>
64 corpusQuery("Ameisenplage", metadataOnly = FALSE) |>
65 fetchNext(maxFetch = 10) |>
66 fetchAnnotations()
67
68# Access linguistic annotations for match i:
69pos_tags <- q@collectedMatches$pos # Data frame with left/match/right columns for POS tags
Marc Kupietz89f796e2025-07-19 09:05:06 +020070lemmas <- q@collectedMatches$lemma # Data frame with left/match/right columns for lemmas
Marc Kupietza29f3d42025-07-18 10:14:43 +020071morphology <- q@collectedMatches$morph # Data frame with left/match/right columns for morphological tags
72atokens <- q@collectedMatches$atokens # Data frame with left/match/right columns for annotation token text
73raw_snippet <- q@collectedMatches$annotation_snippet[[i]] # Original XML snippet for match i
74
75# Access specific components:
76match_pos <- q@collectedMatches$pos$match[[i]] # POS tags for the matched tokens in match i
77left_lemmas <- q@collectedMatches$lemma$left[[i]] # Lemmas for the left context in match i
78right_tokens <- q@collectedMatches$atokens$right[[i]] # Token text for the right context in match i
79
Marc Kupietz89f796e2025-07-19 09:05:06 +020080# Use a different foundry (e.g., MarMoT)
Marc Kupietza29f3d42025-07-18 10:14:43 +020081q <- KorAPConnection() |>
82 auth() |>
83 corpusQuery("Ameisenplage", metadataOnly = FALSE) |>
84 fetchNext(maxFetch = 10) |>
Marc Kupietz89f796e2025-07-19 09:05:06 +020085 fetchAnnotations(foundry = "marmot")
86q@collectedMatches$pos$left[1] # POS tags for the left context of the first match
Marc Kupietza29f3d42025-07-18 10:14:43 +020087}
88}
89\seealso{
90Other corpus search functions:
91\code{\link{corpusQuery,KorAPConnection-method}},
92\code{\link{fetchAll,KorAPQuery-method}},
93\code{\link{fetchNext,KorAPQuery-method}}
94}
Marc Kupietz89f796e2025-07-19 09:05:06 +020095\concept{Annotations}
Marc Kupietza29f3d42025-07-18 10:14:43 +020096\concept{corpus search functions}