1616from packaging import version
1717from rpy2 .robjects .methods import RS4
1818
19- CURRENT_R_PACKAGE_VERSION = "1.1.0 "
19+ CURRENT_R_PACKAGE_VERSION = "1.2.1 "
2020
2121KorAPClient = packages .importr ('RKorAPClient' )
2222if version .parse (KorAPClient .__version__ ) < version .parse (CURRENT_R_PACKAGE_VERSION ):
@@ -395,3 +395,48 @@ def fetchAll(self, *args, **kwargs):
395395 super ().__init__ (res )
396396 return self
397397
398+ def fetchAnnotations (self , * args , ** kwargs ):
399+ """Fetches and parses linguistic annotations for the collected matches.
400+
401+ This method enriches the `collectedMatches` DataFrame with additional columns
402+ containing linguistic annotations like lemma, part-of-speech (POS), and
403+ morphology for each token in the match and its context.
404+
405+ Args:
406+ foundry (str, optional): The foundry (annotation layer) to fetch.
407+ Defaults to "tt" (TreeTagger).
408+ overwrite (bool, optional): If True, existing annotation columns will be
409+ overwritten. Defaults to False.
410+ verbose (bool, optional): If True, prints progress information. Defaults
411+ to the verbosity setting of the
412+ KorAPConnection object.
413+ *args: Positional arguments passed to the underlying R function.
414+ **kwargs: Keyword arguments passed to the underlying R function.
415+
416+ Returns:
417+ KorAPQuery: A new KorAPQuery object with the `collectedMatches` DataFrame
418+ updated to include the fetched annotations.
419+
420+ Example:
421+ ```
422+ from KorAPClient import KorAPConnection
423+
424+ # Authentication might be required for snippets and annotations
425+ kcon = KorAPConnection(verbose=True).auth()
426+
427+ # Perform a query and fetch all matches
428+ q = kcon.corpusQuery("Ameisenplage", metadataOnly=False).fetchAll()
429+
430+ # Fetch annotations for the matches
431+ q_annotated = q.fetchAnnotations()
432+
433+ # Display the collected matches with new annotation columns
434+ print(q_annotated.slots['collectedMatches'][['snippet', 'lemma.left', 'lemma.match', 'lemma.right']].head())
435+ ```
436+ """
437+ res = KorAPClient .fetchAnnotations (self , * args , ** kwargs )
438+ with localconverter (fix_lists_in_dataframes ):
439+ df = res .slots ['collectedMatches' ]
440+ res .slots ['collectedMatches' ] = df
441+ super ().__init__ (res )
442+ return self
0 commit comments