Retrieve the word context of a token, optionally checking for boundaries of a XML region.

context(.Object, ...)

# S4 method for slice
context(
  .Object,
  query,
  cqp = is.cqp,
  check = TRUE,
  left = getOption("polmineR.left"),
  right = getOption("polmineR.right"),
  p_attribute = getOption("polmineR.p_attribute"),
  boundary = NULL,
  stoplist = NULL,
  positivelist = NULL,
  regex = FALSE,
  count = TRUE,
  mc = getOption("polmineR.mc"),
  verbose = TRUE,
  progress = TRUE,
  ...
)

# S4 method for partition
context(
  .Object,
  query,
  cqp = is.cqp,
  check = TRUE,
  left = getOption("polmineR.left"),
  right = getOption("polmineR.right"),
  p_attribute = getOption("polmineR.p_attribute"),
  boundary = NULL,
  stoplist = NULL,
  positivelist = NULL,
  regex = FALSE,
  count = TRUE,
  mc = getOption("polmineR.mc"),
  verbose = TRUE,
  progress = TRUE,
  ...
)

# S4 method for subcorpus
context(
  .Object,
  query,
  cqp = is.cqp,
  check = TRUE,
  left = getOption("polmineR.left"),
  right = getOption("polmineR.right"),
  p_attribute = getOption("polmineR.p_attribute"),
  boundary = NULL,
  stoplist = NULL,
  positivelist = NULL,
  regex = FALSE,
  count = TRUE,
  mc = getOption("polmineR.mc"),
  verbose = TRUE,
  progress = TRUE,
  ...
)

# S4 method for matrix
context(.Object, corpus, left, right)

# S4 method for corpus
context(
  .Object,
  query,
  cqp = is.cqp,
  p_attribute = getOption("polmineR.p_attribute"),
  boundary = NULL,
  left = getOption("polmineR.left"),
  right = getOption("polmineR.right"),
  stoplist = NULL,
  positivelist = NULL,
  regex = FALSE,
  count = TRUE,
  mc = getOption("polmineR.mc"),
  verbose = TRUE,
  progress = TRUE,
  ...
)

# S4 method for character
context(
  .Object,
  query,
  cqp = is.cqp,
  p_attribute = getOption("polmineR.p_attribute"),
  boundary = NULL,
  left = getOption("polmineR.left"),
  right = getOption("polmineR.right"),
  stoplist = NULL,
  positivelist = NULL,
  regex = FALSE,
  count = TRUE,
  mc = getOption("polmineR.mc"),
  verbose = TRUE,
  progress = TRUE,
  ...
)

# S4 method for partition_bundle
context(.Object, query, p_attribute, verbose = TRUE, ...)

# S4 method for cooccurrences
context(.Object, query, check = TRUE, complete = FALSE)

Arguments

.Object

a partition or a partition_bundle object

...

further parameters

query

A query, which may by a character vector or a CQP query.

cqp

defaults to is.cqp-function, or provide TRUE/FALSE

check

A logical value, whether to check validity of CQP query using check_cqp_query.

left

Number of tokens to the left of the query match.

right

Number of tokens to the right of the query match.

p_attribute

The p-attribute of the query.

boundary

If provided, a length-one character vector specifying a s-attribute. It will be checked that corpus positions do not extend beyond the region defined by the s-attribute.

stoplist

Exclude match for query if stopword(s) is/are are present in context. See positivelist for further explanation.

positivelist

character vector or numeric/integer vector: include a query hit only if token in positivelist is present. If positivelist is a character vector, it may include regular expressions (see parameter regex)

regex

logical, defaults to FALSE - whether stoplist and/or positivelist are regular expressions

count

logical

mc

whether to use multicore; if NULL (default), the function will get the value from the options

verbose

report progress, defaults to TRUE

progress

logical, whether to show progress bar

corpus

A length-one character vector stating the corpus ID of a CWB corpus.

complete

enhance completely

Value

depending on whether a partition or a partition_bundle serves as input, the return will be a context object, or a context_bundle object

Details

For formulating the query, CPQ syntax may be used (see examples). Statistical tests available are log-likelihood, t-test, pmi.

If .Object is a matrix, the context-method will unfold the matrix (interpreted as regions defining left and right corpus positions) and return an elementary ... object.

Author

Andreas Blaette

Examples

use("polmineR")
#> ... activating corpus: GERMAPARLMINI (version: 0.0.1 | build date: 2019-02-23)
#> ... activating corpus: REUTERS
p <- partition("GERMAPARLMINI", interjection = "speech")
#> ... get encoding: latin1
#> ... get cpos and strucs
y <- context(p, query = "Integration", p_attribute = "word")
#> ... getting corpus positions
#> ... number of hits: 23
#> ... checking that all p-attributes are available
#> ... getting token id for p-attribute: word
#> ... generating contexts
#> ... counting tokens
y <- context(p, query = "Integration", p_attribute = "word", positivelist = "Bildung")
#> ... getting corpus positions
#> ... number of hits: 23
#> ... checking that all p-attributes are available
#> ... getting token id for p-attribute: word
#> ... filtering by positivelist
#> ... number of hits droped due to positivelist: 18
#> ... generating contexts
#> ... counting tokens
y <- context( p, query = "Integration", p_attribute = "word", positivelist = c("[aA]rbeit.*", "Ausbildung"), regex = TRUE )
#> ... getting corpus positions
#> ... number of hits: 23
#> ... checking that all p-attributes are available
#> ... getting token id for p-attribute: word
#> ... filtering by positivelist
#> ... number of hits droped due to positivelist: 21
#> ... generating contexts
#> ... counting tokens