Marc Kupietz | a29f3d4 | 2025-07-18 10:14:43 +0200 | [diff] [blame] | 1 | % 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 Kupietz | 89f796e | 2025-07-19 09:05:06 +0200 | [diff] [blame] | 18 | The updated \code{kqo} object with annotation columns |
| 19 | like \code{pos}, \code{lemma}, \code{morph} (and \code{atokens} and \code{annotation_snippet}) |
| 20 | in the \verb{@collectedMatches} slot. Each column is a data frame |
| 21 | with \code{left}, \code{match}, and \code{right} columns containing list vectors of annotations |
| 22 | for the left context, matched tokens, and right context, respectively. |
| 23 | The original XML snippet for each match is also stored in \code{annotation_snippet}. |
Marc Kupietz | a29f3d4 | 2025-07-18 10:14:43 +0200 | [diff] [blame] | 24 | } |
| 25 | \description{ |
Marc Kupietz | 89f796e | 2025-07-19 09:05:06 +0200 | [diff] [blame] | 26 | \ifelse{html}{\href{https://lifecycle.r-lib.org/articles/stages.html#experimental}{\figure{lifecycle-experimental.svg}{options: alt='[Experimental]'}}}{\strong{[Experimental]}} |
Marc Kupietz | a29f3d4 | 2025-07-18 10:14:43 +0200 | [diff] [blame] | 27 | } |
| 28 | \details{ |
Marc Kupietz | 89f796e | 2025-07-19 09:05:06 +0200 | [diff] [blame] | 29 | \strong{\code{fetchAnnotations}} fetches annotations (only token annotations, for now) |
| 30 | for all matches in the \verb{@collectedMatches} slot |
| 31 | of a KorAPQuery object and adds annotation columns directly to the \verb{@collectedMatches} |
| 32 | data frame. The method uses the \code{matchID} from collected matches. |
| 33 | |
Marc Kupietz | a29f3d4 | 2025-07-18 10:14:43 +0200 | [diff] [blame] | 34 | \strong{Important}: For copyright-restricted corpora, users must be authorized via \code{\link[=auth]{auth()}} |
| 35 | and the initial corpus query must have \code{metadataOnly = FALSE} to ensure snippets are |
| 36 | available for annotation parsing. |
| 37 | |
| 38 | The 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 |
| 52 | q <- KorAPConnection() |> |
| 53 | auth() |> |
| 54 | corpusQuery("Ameisenplage", metadataOnly = FALSE) |> |
| 55 | fetchNext(maxFetch = 10) |> |
| 56 | fetchAnnotations() |
| 57 | |
| 58 | # Access linguistic annotations for match i: |
| 59 | pos_tags <- q@collectedMatches$pos # Data frame with left/match/right columns for POS tags |
Marc Kupietz | 89f796e | 2025-07-19 09:05:06 +0200 | [diff] [blame] | 60 | lemmas <- q@collectedMatches$lemma # Data frame with left/match/right columns for lemmas |
Marc Kupietz | a29f3d4 | 2025-07-18 10:14:43 +0200 | [diff] [blame] | 61 | morphology <- q@collectedMatches$morph # Data frame with left/match/right columns for morphological tags |
| 62 | atokens <- q@collectedMatches$atokens # Data frame with left/match/right columns for annotation token text |
| 63 | raw_snippet <- q@collectedMatches$annotation_snippet[[i]] # Original XML snippet for match i |
| 64 | |
| 65 | # Access specific components: |
| 66 | match_pos <- q@collectedMatches$pos$match[[i]] # POS tags for the matched tokens in match i |
| 67 | left_lemmas <- q@collectedMatches$lemma$left[[i]] # Lemmas for the left context in match i |
| 68 | right_tokens <- q@collectedMatches$atokens$right[[i]] # Token text for the right context in match i |
| 69 | |
Marc Kupietz | 89f796e | 2025-07-19 09:05:06 +0200 | [diff] [blame] | 70 | # Use a different foundry (e.g., MarMoT) |
Marc Kupietz | a29f3d4 | 2025-07-18 10:14:43 +0200 | [diff] [blame] | 71 | q <- KorAPConnection() |> |
| 72 | auth() |> |
| 73 | corpusQuery("Ameisenplage", metadataOnly = FALSE) |> |
| 74 | fetchNext(maxFetch = 10) |> |
Marc Kupietz | 89f796e | 2025-07-19 09:05:06 +0200 | [diff] [blame] | 75 | fetchAnnotations(foundry = "marmot") |
| 76 | q@collectedMatches$pos$left[1] # POS tags for the left context of the first match |
Marc Kupietz | a29f3d4 | 2025-07-18 10:14:43 +0200 | [diff] [blame] | 77 | } |
| 78 | } |
| 79 | \seealso{ |
| 80 | Other corpus search functions: |
| 81 | \code{\link{corpusQuery,KorAPConnection-method}}, |
| 82 | \code{\link{fetchAll,KorAPQuery-method}}, |
| 83 | \code{\link{fetchNext,KorAPQuery-method}} |
| 84 | } |
Marc Kupietz | 89f796e | 2025-07-19 09:05:06 +0200 | [diff] [blame] | 85 | \concept{Annotations} |
Marc Kupietz | a29f3d4 | 2025-07-18 10:14:43 +0200 | [diff] [blame] | 86 | \concept{corpus search functions} |