@@ -68,7 +68,13 @@ setGeneric("corpusQuery", function(kco, ...) standardGeneric("corpusQuery"))
6868setGeneric ("fetchAll ", function(kqo, ...) standardGeneric("fetchAll"))
6969setGeneric ("fetchNext ", function(kqo, ...) standardGeneric("fetchNext"))
7070setGeneric ("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+ )
7278setGeneric ("frequencyQuery ", function(kco, ...) standardGeneric("frequencyQuery"))
7379
7480maxResultsPerPage <- 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 (
0 commit comments