blob: ea00bcb239888215f7ce4d9a3c82d4eeff715fb9 [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 Kupietz6aa5a0d2025-09-08 17:51:47 +02008\S4method{fetchAnnotations}{KorAPQuery}(kqo, foundry = "tt", overwrite = FALSE,
9 verbose = kqo@korapConnection@verbose)
Marc Kupietza29f3d42025-07-18 10:14:43 +020010}
11\arguments{
12\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.}
13
14\item{foundry}{string specifying the foundry to use for annotations (default: "tt" for Tree-Tagger)}
15
Marc Kupietz93787d52025-09-03 13:33:25 +020016\item{overwrite}{logical; if TRUE, re-fetch and replace any existing
17annotation columns. If FALSE (default), only add missing annotation layers
18and preserve already fetched ones (e.g., keep POS/lemma from a previous
19foundry while adding morph from another).}
20
Marc Kupietza29f3d42025-07-18 10:14:43 +020021\item{verbose}{print progress information if true}
22}
23\value{
Marc Kupietz89f796e2025-07-19 09:05:06 +020024The updated \code{kqo} object with annotation columns
25like \code{pos}, \code{lemma}, \code{morph} (and \code{atokens} and \code{annotation_snippet})
26in the \verb{@collectedMatches} slot. Each column is a data frame
27with \code{left}, \code{match}, and \code{right} columns containing list vectors of annotations
28for the left context, matched tokens, and right context, respectively.
29The original XML snippet for each match is also stored in \code{annotation_snippet}.
Marc Kupietza29f3d42025-07-18 10:14:43 +020030}
31\description{
Marc Kupietz89f796e2025-07-19 09:05:06 +020032\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 +020033}
34\details{
Marc Kupietz89f796e2025-07-19 09:05:06 +020035\strong{\code{fetchAnnotations}} fetches annotations (only token annotations, for now)
36for all matches in the \verb{@collectedMatches} slot
37of a KorAPQuery object and adds annotation columns directly to the \verb{@collectedMatches}
38data frame. The method uses the \code{matchID} from collected matches.
39
Marc Kupietza29f3d42025-07-18 10:14:43 +020040\strong{Important}: For copyright-restricted corpora, users must be authorized via \code{\link[=auth]{auth()}}
41and the initial corpus query must have \code{metadataOnly = FALSE} to ensure snippets are
42available for annotation parsing.
43
44The method parses XML snippet annotations and adds linguistic columns to the data frame:
45\itemize{
46\item \code{pos}: data frame with \code{left}, \code{match}, \code{right} columns, each containing list vectors of part-of-speech tags
47\item \code{lemma}: data frame with \code{left}, \code{match}, \code{right} columns, each containing list vectors of lemmas
48\item \code{morph}: data frame with \code{left}, \code{match}, \code{right} columns, each containing list vectors of morphological tags
49\item \code{atokens}: data frame with \code{left}, \code{match}, \code{right} columns, each containing list vectors of token text (from annotations)
50\item \code{annotation_snippet}: original XML snippet from the annotation API
51}
52}
53\examples{
54\dontrun{
55
56# Fetch annotations for matches using Tree-Tagger foundry
57# Note: Authorization required for copyright-restricted corpora
58q <- KorAPConnection() |>
59 auth() |>
60 corpusQuery("Ameisenplage", metadataOnly = FALSE) |>
61 fetchNext(maxFetch = 10) |>
62 fetchAnnotations()
63
64# Access linguistic annotations for match i:
Marc Kupietz6aa5a0d2025-09-08 17:51:47 +020065pos_tags <- q@collectedMatches$pos
66# Data frame with left/match/right columns for POS tags
67lemmas <- q@collectedMatches$lemma
68# Data frame with left/match/right columns for lemmas
69morphology <- q@collectedMatches$morph
70# Data frame with left/match/right columns for morphological tags
71atokens <- q@collectedMatches$atokens
72# Data frame with left/match/right columns for annotation token text
73raw_snippet <- q@collectedMatches$annotation_snippet[[i]]
74# Original XML snippet for match i
Marc Kupietza29f3d42025-07-18 10:14:43 +020075
76# Access specific components:
Marc Kupietz6aa5a0d2025-09-08 17:51:47 +020077match_pos <- q@collectedMatches$pos$match[[i]]
78# POS tags for the matched tokens in match i
79left_lemmas <- q@collectedMatches$lemma$left[[i]]
80# Lemmas for the left context in match i
81right_tokens <- q@collectedMatches$atokens$right[[i]]
82# Token text for the right context in match i
Marc Kupietza29f3d42025-07-18 10:14:43 +020083
Marc Kupietz89f796e2025-07-19 09:05:06 +020084# Use a different foundry (e.g., MarMoT)
Marc Kupietza29f3d42025-07-18 10:14:43 +020085q <- KorAPConnection() |>
86 auth() |>
87 corpusQuery("Ameisenplage", metadataOnly = FALSE) |>
88 fetchNext(maxFetch = 10) |>
Marc Kupietz89f796e2025-07-19 09:05:06 +020089 fetchAnnotations(foundry = "marmot")
90q@collectedMatches$pos$left[1] # POS tags for the left context of the first match
Marc Kupietza29f3d42025-07-18 10:14:43 +020091}
92}
93\seealso{
94Other corpus search functions:
95\code{\link{corpusQuery,KorAPConnection-method}},
96\code{\link{fetchAll,KorAPQuery-method}},
97\code{\link{fetchNext,KorAPQuery-method}}
98}
Marc Kupietz89f796e2025-07-19 09:05:06 +020099\concept{Annotations}
Marc Kupietza29f3d42025-07-18 10:14:43 +0200100\concept{corpus search functions}