Skip to content

Commit 0af7593

Browse files
committed
Fix fetchAnnotations documentation mismatches
Change-Id: I2dc7bc69ce64492780ee1f67fea03e00bbc034ba
1 parent 6aa5a0d commit 0af7593

File tree

3 files changed

+56
-22
lines changed

3 files changed

+56
-22
lines changed

R/KorAPQuery.R

Lines changed: 26 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,13 @@ setGeneric("corpusQuery", function(kco, ...) standardGeneric("corpusQuery"))
6868
setGeneric("fetchAll", function(kqo, ...) standardGeneric("fetchAll"))
6969
setGeneric("fetchNext", function(kqo, ...) standardGeneric("fetchNext"))
7070
setGeneric("fetchRest", function(kqo, ...) standardGeneric("fetchRest"))
71-
setGeneric("fetchAnnotations", function(kqo, ...) standardGeneric("fetchAnnotations"))
71+
setGeneric(
72+
"fetchAnnotations",
73+
function(kqo,
74+
foundry = "tt",
75+
overwrite = FALSE,
76+
verbose = kqo@korapConnection@verbose) standardGeneric("fetchAnnotations")
77+
)
7278
setGeneric("frequencyQuery", function(kco, ...) standardGeneric("frequencyQuery"))
7379

7480
maxResultsPerPage <- 50
@@ -1119,7 +1125,6 @@ parse_xml_annotations_structured <- function(xml_snippet) {
11191125
#'
11201126
#' @family corpus search functions
11211127
#' @concept Annotations
1122-
#' @aliases fetchAnnotations
11231128
#'
11241129
#' @param kqo object obtained from [corpusQuery()] with collected matches. Note: the original corpus query should have `metadataOnly = FALSE` for annotation parsing to work.
11251130
#' @param foundry string specifying the foundry to use for annotations (default: "tt" for Tree-Tagger)
@@ -1128,7 +1133,7 @@ parse_xml_annotations_structured <- function(xml_snippet) {
11281133
#' and preserve already fetched ones (e.g., keep POS/lemma from a previous
11291134
#' foundry while adding morph from another).
11301135
#' @param verbose print progress information if true
1131-
#' @return The updated `kqo` object with annotation columns
1136+
#' @return The updated `kqo` object with annotation columns
11321137
#' like `pos`, `lemma`, `morph` (and `atokens` and `annotation_snippet`)
11331138
#' in the `@collectedMatches` slot. Each column is a data frame
11341139
#' with `left`, `match`, and `right` columns containing list vectors of annotations
@@ -1155,12 +1160,16 @@ parse_xml_annotations_structured <- function(xml_snippet) {
11551160
#' # Data frame with left/match/right columns for morphological tags
11561161
#' atokens <- q@collectedMatches$atokens
11571162
#' # Data frame with left/match/right columns for annotation token text
1158-
#' raw_snippet <- q@collectedMatches$annotation_snippet[[i]] # Original XML snippet for match i
1163+
#' # Original XML snippet for match i
1164+
#' raw_snippet <- q@collectedMatches$annotation_snippet[[i]]
11591165
#'
11601166
#' # Access specific components:
1161-
#' match_pos <- q@collectedMatches$pos$match[[i]] # POS tags for the matched tokens in match i
1162-
#' left_lemmas <- q@collectedMatches$lemma$left[[i]] # Lemmas for the left context in match i
1163-
#' right_tokens <- q@collectedMatches$atokens$right[[i]] # Token text for the right context in match i
1167+
#' # POS tags for the matched tokens in match i
1168+
#' match_pos <- q@collectedMatches$pos$match[[i]]
1169+
#' # Lemmas for the left context in match i
1170+
#' left_lemmas <- q@collectedMatches$lemma$left[[i]]
1171+
#' # Token text for the right context in match i
1172+
#' right_tokens <- q@collectedMatches$atokens$right[[i]]
11641173
#'
11651174
#' # Use a different foundry (e.g., MarMoT)
11661175
#' q <- KorAPConnection() |>
@@ -1170,14 +1179,16 @@ parse_xml_annotations_structured <- function(xml_snippet) {
11701179
#' fetchAnnotations(foundry = "marmot")
11711180
#' q@collectedMatches$pos$left[1] # POS tags for the left context of the first match
11721181
#' }
1173-
#' @usage fetchAnnotations(kqo, foundry = "tt", overwrite = FALSE,
1174-
#' verbose = kqo@korapConnection@verbose)
11751182
#' @export
1176-
setMethod("fetchAnnotations", "KorAPQuery", function(kqo, foundry = "tt", overwrite = FALSE, verbose = kqo@korapConnection@verbose) {
1177-
if (is.null(kqo@collectedMatches) || nrow(kqo@collectedMatches) == 0) {
1178-
warning("No collected matches found. Please run fetchNext() or fetchAll() first.")
1179-
return(kqo)
1180-
}
1183+
setMethod("fetchAnnotations", "KorAPQuery", function(kqo,
1184+
foundry = "tt",
1185+
overwrite = FALSE,
1186+
verbose = kqo@korapConnection@verbose) {
1187+
if (is.null(kqo@collectedMatches) ||
1188+
nrow(kqo@collectedMatches) == 0) {
1189+
warning("No collected matches found. Please run fetchNext() or fetchAll() first.")
1190+
return(kqo)
1191+
}
11811192

11821193
df <- kqo@collectedMatches
11831194
kco <- kqo@korapConnection
@@ -1188,7 +1199,7 @@ setMethod("fetchAnnotations", "KorAPQuery", function(kqo, foundry = "tt", overwr
11881199

11891200
# Pre-compute the empty character vector list to avoid repeated computation
11901201
empty_char_list <- I(replicate(nrows, character(0), simplify = FALSE))
1191-
1202+
11921203
# Helper function to create annotation data frame structure
11931204
create_annotation_df <- function(empty_list) {
11941205
data.frame(

man/fetchAnnotations-KorAPQuery-method.Rd

Lines changed: 10 additions & 7 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

man/fetchAnnotations.Rd

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
% Please edit documentation in R/KorAPQuery.R if changing API
2+
\name{fetchAnnotations}
3+
\alias{fetchAnnotations}
4+
\title{Fetch annotations (generic)}
5+
\description{
6+
S4 generic for fetching token annotations for collected matches. See specific methods, e.g. \code{\link{fetchAnnotations,KorAPQuery-method}}.
7+
}
8+
\usage{
9+
fetchAnnotations(kqo, foundry = "tt", overwrite = FALSE,
10+
verbose = kqo@korapConnection@verbose)
11+
}
12+
\arguments{
13+
\item{kqo}{An object on which an annotation fetching method is defined.}
14+
\item{foundry}{Annotation foundry identifier.}
15+
\item{overwrite}{Logical flag controlling whether to overwrite existing annotations.}
16+
\item{verbose}{Logical flag for progress output.}
17+
}
18+
\seealso{
19+
\code{\link{fetchAnnotations,KorAPQuery-method}}
20+
}

0 commit comments

Comments
 (0)