kwic: List key words in context from a text or a corpus of texts.
Description
For a text or a collection of texts (in a quanteda corpus object), return a
list of a keyword supplied by the user in its immediate context, identifying
the source text and the word index number within the source text. (Not the
line number, since the text may or may not be segmented using end-of-line
delimiters.)
Usage
kwic(x, word, window = 5, wholeword = FALSE)
## S3 method for class 'character':
kwic(x, word, window = 5, wholeword = FALSE)
## S3 method for class 'corpus':
kwic(x, word, window = 5, wholeword = FALSE)
Arguments
x
A text character scalar or a quanteda corpus. (Currently does not
support character vectors.)
word
A keyword chosen by the user.
window
The number of context words to be displayed around the
keyword.
wholeword
If TRUE, then only search for the entire "word".
Otherwise word is interpreted as a regular expression, which
matches any occurrence of word in the text, so that the the
concordance will include all words in which th
Value
A data frame with the context before (preword), the keyword
in its original format (word, preserving case and attached
punctuation), and the context after (postword). The rows of the
dataframe will be named with the word index position, or the text name and
the index position for a corpus object.