Adds a column with n words before and after the selected pattern to see keywords in context
Source:R/cas_kwic.R
cas_kwic_single_pattern.RdAdds a column with n words before and after the selected pattern to see keywords in context
Usage
cas_kwic_single_pattern(
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
beforecolumn.- words_after
Integer, defaults to 5. Number of columns to include in the
aftercolumn.- 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. IfTRUE, a period (".") is always included at the end of a sentence. Relevant only ifsame_sentenceis set toTRUE.- ignore_case
Defaults to
TRUE.- regex
Defaults to
TRUE. Treat pattern as regex.- full_words_only
Defaults to
FALSE. IfFALSE, pattern is counted even when it is found in the middle of a word (e.g. ifFALSE, "ratio" would be counted as match in the word "irrational").- full_word_with_partial_match
Defaults to
TRUE. IfTRUE, if there is a partial match of the pattern, thepatterncolumn still includes the full word where the match has been found. Relevant only whenfull_words_onlyis set toFALSE.- 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_single_pattern(
corpus = castarter::cas_demo_corpus,
pattern = "West"
)
#> # A tibble: 8 × 10
#> doc_id text date title location link id before pattern after
#> <chr> <chr> <date> <chr> <chr> <chr> <dbl> <chr> <chr> <chr>
#> 1 president_ru… He u… 2000-01-28 Acti… The Kre… http… 38049 He un… Western poin…
#> 2 president_ru… Acti… 2000-02-08 Acti… The Kre… http… 37887 for b… Western Euro…
#> 3 president_ru… Pres… 2000-05-22 Pres… The Kre… http… 38214 Presi… West Fede…
#> 4 president_ru… Pres… 2000-05-22 Pres… The Kre… http… 38214 legis… West Fede…
#> 5 president_ru… Mr P… 2000-05-22 Pres… The Kre… http… 38214 the g… West Fede…
#> 6 president_ru… Gove… 2000-05-25 Pres… The Kre… http… 38231 at a … Western Fede…
#> 7 president_ru… In t… 2000-11-24 Pres… The Kre… http… 39674 of “l… West Bank…
#> 8 president_ru… The … 2001-11-30 CIS … The Kre… http… 26838 faced… Western coun…