我使用 Quanteda 对 ngram 和 token 进行上下文分析中的关键字,效果很好。
我现在想对skipgrams 执行此操作,捕获“进入障碍”的上下文以及“[...] [和] 进入障碍。
下面的代码是一个空的 kwic 对象,但我不知道我做错了什么。 dcc.corpus 指的是文本文档。我也使用了标记化版本,但没有任何变化。
结果是:
“具有 0 行的 kwic 对象”
x <- tokens("barriers entry")
ntoken_test <- tokens_ngrams(x, n = 2, skip = 0:4, concatenator = " ")
twic_skipgram <- kwic(doc.corpus, pattern = list(ntoken_test), window=20, valuetype= "glob")
twic_skipgram
也许最简单的方法是用通配符来表示“跳过”。
library("quanteda")
## Package version: 2.1.1
txt <- c(
"There are barriers to entry.",
"Also barriers against entry.",
"Just barriers entry."
)
# for skip of 1
kwic(txt, phrase("barriers * entry"))
##
## [text1, 3:5] There are | barriers to entry | .
## [text2, 2:4] Also | barriers against entry | .
# for skip of 0 and 1
kwic(txt, phrase(c("barriers * entry", "barriers entry")))
##
## [text1, 3:5] There are | barriers to entry | .
## [text2, 2:4] Also | barriers against entry | .
## [text3, 2:3] Just | barriers entry | .
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)