的quanteda
封裝具有的功能,專爲背景返回關鍵詞:kwic
。它在引擎蓋下使用stringi
。
library(quanteda)
kwic(txt, keywords = "twisters", window = 5, case_insensitive = TRUE)
# contextPre keyword contextPost
#[text1, 8] the full effect of tongue [ twisters ] you should repeat them several
#[text2, 2] The [ twisters ] are always twisting
#[text3, 9] for those guys, they are [ twisters ] of words and will tell
#[text4, 1] [ Twisters ] will ruin your life.
示例文本:
# sample text
txt <- c("To get the full effect of tongue twisters you should repeat them several times, as quickly as possible, without stumbling or mispronouncing.",
"The twisters are always twisting",
"watch out for those guys, they are twisters of words and will tell a yarn a mile long",
"Twisters will ruin your life.")
多謝,正是我需要的。 – Atwp67