quanteda 的 fcm 函数:选择 window 的一侧的任何可能性

fcm function of quanteda: any possibility of selecting one side of the window

quanteda::fcm(wiki_toks, context = "window", count = "weighted", window = 3)

现在上面的代码是 selecting 目标特征前后的 3 个词。是否有可能将 window 设置为 select 目标特征的左侧?

感谢您的帮助。

您可以在反转令牌后使用 ordered = TRUE。所以:

library("quanteda")
## Package version: 3.0.0
## Unicode version: 10.0
## ICU version: 61.1
## Parallel computing: 12 of 12 threads used.
## See https://quanteda.io for tutorials and examples.

toks <- tokens(c("A D A C", "A B D E"))

fcm(toks, context = "window", window = 2, ordered = TRUE)
## Feature co-occurrence matrix of: 5 by 5 features.
##         features
## features A D C B E
##        A 1 2 1 1 0
##        D 1 0 1 0 1
##        C 0 0 0 0 0
##        B 0 1 0 0 1
##        E 0 0 0 0 0

fcm(as.tokens(lapply(toks, rev)),
  context = "window", window = 2, ordered = TRUE
)
## Feature co-occurrence matrix of: 5 by 5 features.
##         features
## features C A D E B
##        C 0 1 1 0 0
##        A 0 1 1 0 0
##        D 0 2 0 0 1
##        E 0 0 1 0 1
##        B 0 1 0 0 0

reprex package (v1.0.0)

于 2021 年 4 月 12 日创建