更改quanteda KWIC中关键字的前置和后置单词数

时间:2018-04-19 23:00:59

标签: r quanteda

有没有办法在quanteda KWIC功能中更改单词的前后数? 窗口函数在关键字前后给出了相同数量的单词,但我需要在关键字前面加一个单词,在关键字后面加五个单词。

1 个答案:

答案 0 :(得分:2)

最简单的方法是进行两次kwic()次呼叫,一次窗口大小为1,第二次窗口大小为5.然后,使用大小为1的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