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.)

kwic_old(x, keywords, window = 5, valuetype = c("glob", "regex", "fixed"),
  case_insensitive = TRUE, ..., new = FALSE)

Arguments

x
a character, corpus, or tokens object
keywords
a keyword pattern or phrase consisting of multiple keyword patterns, possibly including punctuation. If a phrase, keywords will be tokenized using the ... options.
window
the number of context words to be displayed around the keyword.
valuetype
how to interpret keyword expressions: "glob" for "glob"-style wildcard expressions; "regex" for regular expressions; or "fixed" for exact matching. See valuetype for details.
case_insensitive
match without respect to case if TRUE
...
additional arguments passed to tokens, for applicable object types
new
always FALSE for this function

Value

A kwic object classed data.frame, with the document name (docname), the token index position (position), the context before (contextPre), the keyword in its original format (keyword, preserving case and attached punctuation), and the context after (contextPost).

Examples

head(kwic_old(data_char_inaugural, "secure*", window = 3, valuetype = "glob"))
#> contextPre keyword #> [1797-Adams, 479] welfare, and [ secure #> [1797-Adams, 1517] nations, and [ secured #> [1805-Jefferson, 2368] , and shall [ secure #> [1817-Monroe, 1765] cherished. To [ secure #> [1817-Monroe, 1825] defense as to [ secure #> [1817-Monroe, 3026] I can to [ secure #> contextPost #> [1797-Adams, 479] ] the blessings of #> [1797-Adams, 1517] ] immortal glory with #> [1805-Jefferson, 2368] ] to you the #> [1817-Monroe, 1765] ] us against these #> [1817-Monroe, 1825] ] our cities and #> [1817-Monroe, 3026] ] economy and fidelity
head(kwic_old(data_char_inaugural, "secur", window = 3, valuetype = "regex"))
#> contextPre keyword #> [1789-Washington, 1499] government for the [ security #> [1797-Adams, 479] welfare, and [ secure #> [1797-Adams, 1517] nations, and [ secured #> [1805-Jefferson, 2368] , and shall [ secure #> [1813-Madison, 321] seas and the [ security #> [1817-Monroe, 1620] may form some [ security #> contextPost #> [1789-Washington, 1499] ] of their union #> [1797-Adams, 479] ] the blessings of #> [1797-Adams, 1517] ] immortal glory with #> [1805-Jefferson, 2368] ] to you the #> [1813-Madison, 321] ] of an important #> [1817-Monroe, 1620] ] against these dangers
head(kwic_old(data_char_inaugural, "security", window = 3, valuetype = "fixed"))
#> contextPre keyword #> [1789-Washington, 1499] government for the [ security #> [1813-Madison, 321] seas and the [ security #> [1817-Monroe, 1620] may form some [ security #> [1817-Monroe, 3444] and as a [ security #> [1825-Adams, 1373] that the best [ security #> [1825-Adams, 1445] that the firmest [ security #> contextPost #> [1789-Washington, 1499] ] of their union #> [1813-Madison, 321] ] of an important #> [1817-Monroe, 1620] ] against these dangers #> [1817-Monroe, 3444] ] against foreign dangers #> [1825-Adams, 1373] ] for the beneficence #> [1825-Adams, 1445] ] of peace is
kwic_old(data_corpus_inaugural, "war against")
#> contextPre keyword #> [1857-Buchanan, 2933:2934] advantage of the fortune of [ war against #> [1901-McKinley, 2284:2285] . We are not waging [ war against #> [1901-McKinley, 2299:2300] portion of them are making [ war against #> [1901-McKinley, 2413:2414] used when those who make [ war against #> [1933-Roosevelt, 1851:1852] Executive power to wage a [ war against #> contextPost #> [1857-Buchanan, 2933:2934] ] a sister republic, we #> [1901-McKinley, 2284:2285] ] the inhabitants of the Philippine #> [1901-McKinley, 2299:2300] ] the United States. By #> [1901-McKinley, 2413:2414] ] us shall make it no #> [1933-Roosevelt, 1851:1852] ] the emergency, as great
kwic_old(data_corpus_inaugural, "war against", valuetype = "regex")
#> contextPre keyword #> [1801-Jefferson, 1277:1278] domestic concerns and the surest [ bulwarks against #> [1845-Polk, 692:693] domestic concerns and the surest [ bulwark against #> [1857-Buchanan, 2933:2934] advantage of the fortune of [ war against #> [1901-McKinley, 2284:2285] . We are not waging [ war against #> [1901-McKinley, 2299:2300] portion of them are making [ war against #> [1901-McKinley, 2413:2414] used when those who make [ war against #> [1933-Roosevelt, 1851:1852] Executive power to wage a [ war against #> [1977-Carter, 927:928] and we will fight our [ wars against #> contextPost #> [1801-Jefferson, 1277:1278] ] antirepublican tendencies; the preservation #> [1845-Polk, 692:693] ] antirepublican tendencies," and #> [1857-Buchanan, 2933:2934] ] a sister republic, we #> [1901-McKinley, 2284:2285] ] the inhabitants of the Philippine #> [1901-McKinley, 2299:2300] ] the United States. By #> [1901-McKinley, 2413:2414] ] us shall make it no #> [1933-Roosevelt, 1851:1852] ] the emergency, as great #> [1977-Carter, 927:928] ] poverty, ignorance, and