blob: a912430c1b57163a15495ee7e24617cd3104a5bd [file] [log] [blame]
Marc Kupietzdbd431a2021-08-29 12:17:45 +02001% Generated by roxygen2: do not edit by hand
2% Please edit documentation in R/collocationAnalysis.R
3\name{collocationAnalysis,KorAPConnection-method}
4\alias{collocationAnalysis,KorAPConnection-method}
5\alias{collocationAnalysis}
6\title{Collocation analysis}
7\usage{
8\S4method{collocationAnalysis}{KorAPConnection}(
9 kco,
10 node,
11 vc = "",
12 lemmatizeNodeQuery = FALSE,
13 minOccur = 5,
14 leftContextSize = 5,
15 rightContextSize = 5,
16 topCollocatesLimit = 200,
17 searchHitsSampleLimit = 20000,
18 ignoreCollocateCase = FALSE,
19 withinSpan = ifelse(exactFrequencies, "base/s=s", ""),
20 exactFrequencies = TRUE,
Marc Kupietz6505ccf2021-11-27 17:46:25 +010021 stopwords = append(RKorAPClient::synsemanticStopwords(), node),
Marc Kupietzdbd431a2021-08-29 12:17:45 +020022 seed = 7,
23 expand = length(vc) != length(node),
Marc Kupietz5a336b62021-11-27 17:51:35 +010024 maxRecurse = 0,
Marc Kupietzdadfd912021-12-22 12:48:20 +010025 addExamples = FALSE,
Marc Kupietz419f21f2021-12-07 10:27:30 +010026 thresholdScore = "logDice",
27 threshold = 2,
Marc Kupietz5a336b62021-11-27 17:51:35 +010028 localStopwords = c(),
Marc Kupietz47d0d2b2021-12-19 16:38:52 +010029 collocateFilterRegex = "^[:alnum:]+-?[:alnum:]*$",
Marc Kupietz130a2a22025-10-18 16:09:23 +020030 missingScoreQuantile = 0.05,
31 vcLabel = NA_character_,
Marc Kupietzdbd431a2021-08-29 12:17:45 +020032 ...
33)
34}
35\arguments{
Marc Kupietz617266d2025-02-27 10:43:07 +010036\item{kco}{\code{\link[=KorAPConnection]{KorAPConnection()}} object (obtained e.g. from \code{KorAPConnection()}}
Marc Kupietzdbd431a2021-08-29 12:17:45 +020037
38\item{node}{target word}
39
40\item{vc}{string describing the virtual corpus in which the query should be performed. An empty string (default) means the whole corpus, as far as it is license-wise accessible.}
41
Marc Kupietz67edcb52021-09-20 21:54:24 +020042\item{lemmatizeNodeQuery}{if TRUE, node query will be lemmatized, i.e. \verb{x -> [tt/l=x]}}
Marc Kupietzdbd431a2021-08-29 12:17:45 +020043
44\item{minOccur}{minimum absolute number of observed co-occurrences to consider a collocate candidate}
45
46\item{leftContextSize}{size of the left context window}
47
48\item{rightContextSize}{size of the right context window}
49
50\item{topCollocatesLimit}{limit analysis to the n most frequent collocates in the search hits sample}
51
52\item{searchHitsSampleLimit}{limit the size of the search hits sample}
53
54\item{ignoreCollocateCase}{logical, set to TRUE if collocate case should be ignored}
55
Marc Kupietz6bd9cad2024-12-18 15:57:26 +010056\item{withinSpan}{KorAP span specification (see \url{https://korap.ids-mannheim.de/doc/ql/poliqarp-plus?embedded=true#spans}) for collocations to be searched within. Defaults to \code{base/s=s}.}
Marc Kupietzdbd431a2021-08-29 12:17:45 +020057
58\item{exactFrequencies}{if FALSE, extrapolate observed co-occurrence frequencies from frequencies in search hits sample, otherwise retrieve exact co-occurrence frequencies}
59
60\item{stopwords}{vector of stopwords not to be considered as collocates}
61
62\item{seed}{seed for random page collecting order}
63
64\item{expand}{if TRUE, \code{node} and \code{vc} parameters are expanded to all of their combinations}
65
Marc Kupietz7d400e02021-12-19 16:39:36 +010066\item{maxRecurse}{apply collocation analysis recursively \code{maxRecurse} times}
67
68\item{addExamples}{If TRUE, examples for instances of collocations will be added in a column \code{example}. This makes a difference in particular if \code{node} is given as a lemma query.}
69
70\item{thresholdScore}{association score function (see \code{\link{association-score-functions}}) to use for computing the threshold that is applied for recursive collocation analysis calls}
71
72\item{threshold}{minimum value of \code{thresholdScore} function call to apply collocation analysis recursively}
73
74\item{localStopwords}{vector of stopwords that will not be considered as collocates in the current function call, but that will not be passed to recursive calls}
75
Marc Kupietz47d0d2b2021-12-19 16:38:52 +010076\item{collocateFilterRegex}{allow only collocates matching the regular expression}
77
Marc Kupietz4cbb5472025-10-19 12:15:25 +020078\item{missingScoreQuantile}{lower quantile (evaluated per association measure) that anchors the adaptive floor used for imputing missing scores between virtual corpora; a robust spread is subtracted from this anchor so the imputed values stay below the weakest observed scores}
Marc Kupietz130a2a22025-10-18 16:09:23 +020079
80\item{vcLabel}{optional label override for the current virtual corpus (used internally when named VC collections are expanded)}
81
Marc Kupietz67edcb52021-09-20 21:54:24 +020082\item{...}{more arguments will be passed to \code{\link[=collocationScoreQuery]{collocationScoreQuery()}}}
Marc Kupietzdbd431a2021-08-29 12:17:45 +020083}
84\value{
Marc Kupietz130a2a22025-10-18 16:09:23 +020085A tibble where each row represents a candidate collocate for the requested node.
86Columns include (depending on the selected association measures):
87
88\itemize{
89\item \code{node}, \code{collocate}, \code{vc}, \code{label}: identifiers for the query node, collocate, virtual corpus, and optional label.
90\item Frequency and contingency information such as \code{frequency}, \code{O}, \code{O1}, \code{O2}, \code{E}, \code{leftContextSize}, \code{rightContextSize}, and \code{w}.
91\item Association measures (e.g. \code{logDice}, \code{ll}, \code{mi}, ...), one column per requested scorer.
92\item Per-labelled association scores produced by multi-VC comparisons using the pattern \code{<measure>_<label>}.
93\item Ranks per label/measure with the pattern \code{rank_<label>_<measure>} (1 is best) and the corresponding percentile ranks \code{percentile_rank_<label>_<measure>}.
94\item Pairwise contrasts for two-label comparisons, e.g. \code{delta_<measure>}, \code{delta_rank_<measure>}, and \code{delta_percentile_rank_<measure>}.
95\item Summary columns describing the strongest labels per measure (\code{winner_*}, \code{runner_up_*}, \code{loser_*}, and \code{max_delta_*}).
96\item Optional helper columns such as \code{query}, \code{example}, or \code{url} when example retrieval is requested.
97}
Marc Kupietzdbd431a2021-08-29 12:17:45 +020098}
99\description{
Marc Kupietzdbd431a2021-08-29 12:17:45 +0200100Performs a collocation analysis for the given node (or query)
101in the given virtual corpus.
102}
103\details{
104The collocation analysis is currently implemented on the client side, as some of the
105functionality is not yet provided by the KorAP backend. Mainly for this reason
106it is very slow (several minutes, up to hours), but on the other hand very flexible.
107You can, for example, perform the analysis in arbitrary virtual corpora, use complex node queries,
108and look for expression-internal collocates using the focus function (see examples and demo).
109
110To increase speed at the cost of accuracy and possible false negatives,
111you can decrease searchHitsSampleLimit and/or topCollocatesLimit and/or set exactFrequencies to FALSE.
112
Marc Kupietze7f0d682025-02-19 10:50:59 +0100113Note that some outdated non-DeReKo back-ends might not yet support returning tokenized matches (warning issued).
114In this case, the client library will fall back to client-side tokenization which might be slightly less accurate.
115This might lead to false negatives and to frequencies that differ from corresponding ones acquired via the web
Marc Kupietzdbd431a2021-08-29 12:17:45 +0200116user interface.
117}
118\examples{
Marc Kupietz6ae76052021-09-21 10:34:00 +0200119\dontrun{
120
Marc Kupietzb1dec012025-06-04 17:16:57 +0200121# Find top collocates of "Packung" inside and outside the sports domain.
122KorAPConnection(verbose = TRUE) |>
123 collocationAnalysis("Packung",
124 vc = c("textClass=sport", "textClass!=sport"),
125 leftContextSize = 1, rightContextSize = 1, topCollocatesLimit = 20
126 ) |>
Marc Kupietzdbd431a2021-08-29 12:17:45 +0200127 dplyr::filter(logDice >= 5)
128}
129
Marc Kupietz6ae76052021-09-21 10:34:00 +0200130\dontrun{
131
Marc Kupietzdbd431a2021-08-29 12:17:45 +0200132# Identify the most prominent light verb construction with "in ... setzen".
133# Note that, currently, the use of focus function disallows exactFrequencies.
Marc Kupietz463bb162025-03-26 10:23:33 +0100134KorAPConnection(verbose = TRUE) |>
Marc Kupietzdbd431a2021-08-29 12:17:45 +0200135 collocationAnalysis("focus(in [tt/p=NN] {[tt/l=setzen]})",
Marc Kupietzb1dec012025-06-04 17:16:57 +0200136 leftContextSize = 1, rightContextSize = 0, exactFrequencies = FALSE, topCollocatesLimit = 20
137 )
Marc Kupietzdbd431a2021-08-29 12:17:45 +0200138}
139
140}
141\seealso{
142Other collocation analysis functions:
143\code{\link{association-score-functions}},
144\code{\link{collocationScoreQuery,KorAPConnection-method}},
145\code{\link{synsemanticStopwords}()}
146}
147\concept{collocation analysis functions}