cas_kwic: Adds a column with n words before and after the selected...

View source: R/cas_kwic.R

cas_kwicR Documentation

Adds a column with n words before and after the selected pattern to see keywords in context

Description

Adds a column with n words before and after the selected pattern to see keywords in context

Usage

cas_kwic(
  corpus,
  pattern,
  text = text,
  words_before = 5,
  words_after = 5,
  same_sentence = TRUE,
  period_at_end_of_sentence = TRUE,
  ignore_case = TRUE,
  regex = TRUE,
  full_words_only = FALSE,
  full_word_with_partial_match = TRUE,
  pattern_column_name = pattern
)

Arguments

corpus

A textual corpus as a data frame.

pattern

A pattern, typically of one or more words, to be used to break text. Should be of length 1 or length equal to the number of rows.

text

Defaults to text. The unquoted name of the column of the corpus data frame to be used for matching.

words_before

Integer, defaults to 5. Number of columns to include in the before column.

words_after

Integer, defaults to 5. Number of columns to include in the after column.

same_sentence

Logical, defaults to TRUE. If TRUE, before and after include only words found in the sentence including the matched pattern.

period_at_end_of_sentence

Logical, defaults to TRUE. If TRUE, a period (".") is always included at the end of a sentence. Relevant only if same_sentence is set to TRUE.

ignore_case

Defaults to TRUE.

regex

Defaults to TRUE. Treat pattern as regex.

full_words_only

Defaults to FALSE. If FALSE, pattern is counted even when it is found in the middle of a word (e.g. if FALSE, "ratio" would be counted as match in the word "irrational").

full_word_with_partial_match

Defaults to TRUE. If TRUE, if there is a partial match of the pattern, the pattern column still includes the full word where the match has been found. Relevant only when full_words_only is set to FALSE.

pattern_column_name

Defaults to 'pattern'. The unquoted name of the column to be used for the word in the output.

Value

A data frame (a tibble), with the same columns as input, plus three columns: before, pattern, and after. Only rows where the pattern is found are included.

Examples


cas_kwic(
  corpus = tifkremlinen::kremlin_en,
  pattern = c("china", "india")
)

giocomai/castarter documentation built on April 23, 2024, 11:14 p.m.