首页 > 解决方案 > quanteda 的 fcm 函数:选择窗口一侧的任何可能性

问题描述

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

现在上面的代码是在目标特征之前和之后选择 3 个单词。是否有可能设置窗口以选择目标特征的左侧?

谢谢您的帮助。

标签: firebase-cloud-messagingquanteda

解决方案


您可以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 包于 2021-04-12 创建(v1.0.0)


推荐阅读