Learn R Programming

RKorAPClient (version 1.4.0)

collocationScoreQuery,KorAPConnection-method: Query frequencies of a node and a collocate and calculate collocation association scores

Description

Computes various collocation association scores based on frequencyQuery()s for a target word and a collocate.

Usage

# S4 method for KorAPConnection
collocationScoreQuery(
  kco,
  node,
  collocate,
  vc = "",
  lemmatizeNodeQuery = FALSE,
  lemmatizeCollocateQuery = FALSE,
  leftContextSize = 5,
  rightContextSize = 5,
  scoreFunctions = defaultAssociationScoreFunctions(),
  smoothingConstant = 0.5,
  observed = NA,
  ignoreCollocateCase = FALSE,
  withinSpan = "base/s=s",
  cacheAs = NULL
)

Value

tibble with query KorAP web request URL, all observed values and association scores

Arguments

kco

KorAPConnection() object (obtained e.g. from KorAPConnection()

node

target word or query as a single character string

collocate

character vector of one or more collocates of the target word

vc

character vector describing the virtual corpus or corpora in which the query should be performed. An empty string (default) means the whole corpus, as far as it is license-wise accessible.

lemmatizeNodeQuery

logical, set to TRUE if node query should be lemmatized, i.e. x -> [tt/l=x]

lemmatizeCollocateQuery

logical, set to TRUE if collocate query should be lemmatized, i.e. x -> [tt/l=x]

leftContextSize

size of the left context window

rightContextSize

size of the right context window

scoreFunctions

named list of score functions of the form function(O1, O2, O, N, E, window_size), see e.g. pmi

smoothingConstant

smoothing constant will be added to all observed values

observed

if collocation frequencies are already known (or estimated from a sample) they can be passed as a vector here, otherwise: NA

ignoreCollocateCase

logical, set to TRUE if collocate case should be ignored

withinSpan

KorAP span specification (see https://korap.ids-mannheim.de/doc/ql/poliqarp-plus?embedded=true#spans) for collocations to be searched within. Defaults to base/s=s.

cacheAs

path to an RDS file to keep the result in. If the file exists and records the same call, it is read back instead of contacting the server; otherwise the query is run and its result stored there. Unlike the connection's cache, this file belongs to the caller, which is what keeps an analysis reproducible once the corpus has grown or the scores have changed. Defaults to NULL (no file).

See Also

Other collocation analysis functions: association-score-functions, collocationAnalysis,KorAPConnection-method, synsemanticStopwords()

Examples

Run this code
if (FALSE) {

KorAPConnection(verbose = TRUE) |>
  collocationScoreQuery("Grund", "triftiger")
}

if (FALSE) {

KorAPConnection(verbose = TRUE) |>
collocationScoreQuery("Grund", c("guter", "triftiger"),
   scoreFunctions = list(localMI = function(O1, O2, O, N, E, window_size) { O * log2(O/E) }) )
}

if (FALSE) {

library(highcharter)
library(tidyr)
KorAPConnection(verbose = TRUE) |>
  collocationScoreQuery("Team", "agil", vc = paste("pubDate in", c(2014:2018)),
                        lemmatizeNodeQuery = TRUE, lemmatizeCollocateQuery = TRUE) |>
                         pivot_longer(14:last_col(), names_to = "measure", values_to = "score") |>
  hchart(type="spline", hcaes(label, score, group=measure)) |>
  hc_add_onclick_korap_search()
}

Run the code above in your browser using DataLab