更改 quanteda KWIC 中关键字的前置词和 post 词的数量

Change the number of pre and post words of a keyword in quanteda KWIC

有没有办法改变 quanteda KWIC 函数中的前置字数和 post 字数? window 函数在关键字前后给我相同数量的单词,但我需要关键字前后一个单词和五个单词。

最简单的方法是进行两次 kwic() 调用,一次 window 大小为 1,第二次 window 大小为 5。然后,您使用1 号的 pre 作为另一个的 pre。

library("quanteda")

# get a kwic with window size of 1
kwpre  <- kwic(data_char_sampletext, "econom*", window = 1)

# store main kwic result in one with window size of 5
kw <- kwic(data_char_sampletext, "econom*", window = 5)

# replace kw pre with the one-word window pre
kw[["pre"]] <- kwpre[["pre"]]

kw
# [text1, 162]    Irish | economy | in pursuit of a policy             
# [text1, 202] domestic | economy | ? As we are tired                  
# [text1, 268] domestic | economy | show the abject failure of         
# [text1, 486]      the | economy | . Otherwise those funds would      
# [text1, 504] domestic | economy | , stimulating demand and sustaining