blob: 5ae4a2422fa098e698e0055103e0c6599b3a3114 [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{
8\S4method{fetchAnnotations}{KorAPQuery}(kqo, foundry = "tt", verbose = kqo@korapConnection@verbose)
9}
10\arguments{
11\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.}
12
13\item{foundry}{string specifying the foundry to use for annotations (default: "tt" for Tree-Tagger)}
14
15\item{verbose}{print progress information if true}
16}
17\value{
Marc Kupietz89f796e2025-07-19 09:05:06 +020018The updated \code{kqo} object with annotation columns
19like \code{pos}, \code{lemma}, \code{morph} (and \code{atokens} and \code{annotation_snippet})
20in the \verb{@collectedMatches} slot. Each column is a data frame
21with \code{left}, \code{match}, and \code{right} columns containing list vectors of annotations
22for the left context, matched tokens, and right context, respectively.
23The original XML snippet for each match is also stored in \code{annotation_snippet}.
Marc Kupietza29f3d42025-07-18 10:14:43 +020024}
25\description{
Marc Kupietz89f796e2025-07-19 09:05:06 +020026\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 +020027}
28\details{
Marc Kupietz89f796e2025-07-19 09:05:06 +020029\strong{\code{fetchAnnotations}} fetches annotations (only token annotations, for now)
30for all matches in the \verb{@collectedMatches} slot
31of a KorAPQuery object and adds annotation columns directly to the \verb{@collectedMatches}
32data frame. The method uses the \code{matchID} from collected matches.
33
Marc Kupietza29f3d42025-07-18 10:14:43 +020034\strong{Important}: For copyright-restricted corpora, users must be authorized via \code{\link[=auth]{auth()}}
35and the initial corpus query must have \code{metadataOnly = FALSE} to ensure snippets are
36available for annotation parsing.
37
38The method parses XML snippet annotations and adds linguistic columns to the data frame:
39\itemize{
40\item \code{pos}: data frame with \code{left}, \code{match}, \code{right} columns, each containing list vectors of part-of-speech tags
41\item \code{lemma}: data frame with \code{left}, \code{match}, \code{right} columns, each containing list vectors of lemmas
42\item \code{morph}: data frame with \code{left}, \code{match}, \code{right} columns, each containing list vectors of morphological tags
43\item \code{atokens}: data frame with \code{left}, \code{match}, \code{right} columns, each containing list vectors of token text (from annotations)
44\item \code{annotation_snippet}: original XML snippet from the annotation API
45}
46}
47\examples{
48\dontrun{
49
50# Fetch annotations for matches using Tree-Tagger foundry
51# Note: Authorization required for copyright-restricted corpora
52q <- KorAPConnection() |>
53 auth() |>
54 corpusQuery("Ameisenplage", metadataOnly = FALSE) |>
55 fetchNext(maxFetch = 10) |>
56 fetchAnnotations()
57
58# Access linguistic annotations for match i:
59pos_tags <- q@collectedMatches$pos # Data frame with left/match/right columns for POS tags
Marc Kupietz89f796e2025-07-19 09:05:06 +020060lemmas <- q@collectedMatches$lemma # Data frame with left/match/right columns for lemmas
Marc Kupietza29f3d42025-07-18 10:14:43 +020061morphology <- q@collectedMatches$morph # Data frame with left/match/right columns for morphological tags
62atokens <- q@collectedMatches$atokens # Data frame with left/match/right columns for annotation token text
63raw_snippet <- q@collectedMatches$annotation_snippet[[i]] # Original XML snippet for match i
64
65# Access specific components:
66match_pos <- q@collectedMatches$pos$match[[i]] # POS tags for the matched tokens in match i
67left_lemmas <- q@collectedMatches$lemma$left[[i]] # Lemmas for the left context in match i
68right_tokens <- q@collectedMatches$atokens$right[[i]] # Token text for the right context in match i
69
Marc Kupietz89f796e2025-07-19 09:05:06 +020070# Use a different foundry (e.g., MarMoT)
Marc Kupietza29f3d42025-07-18 10:14:43 +020071q <- KorAPConnection() |>
72 auth() |>
73 corpusQuery("Ameisenplage", metadataOnly = FALSE) |>
74 fetchNext(maxFetch = 10) |>
Marc Kupietz89f796e2025-07-19 09:05:06 +020075 fetchAnnotations(foundry = "marmot")
76q@collectedMatches$pos$left[1] # POS tags for the left context of the first match
Marc Kupietza29f3d42025-07-18 10:14:43 +020077}
78}
79\seealso{
80Other corpus search functions:
81\code{\link{corpusQuery,KorAPConnection-method}},
82\code{\link{fetchAll,KorAPQuery-method}},
83\code{\link{fetchNext,KorAPQuery-method}}
84}
Marc Kupietz89f796e2025-07-19 09:05:06 +020085\concept{Annotations}
Marc Kupietza29f3d42025-07-18 10:14:43 +020086\concept{corpus search functions}