quanteda::fcm(wiki_toks, context = "window", count = "weighted", window = 3)
Right now the above code is selecting 3 words before and after the target feature. Any possibility of setting the window to select the left side of the target feature?
Thanks for the help.
You could use ordered = TRUE
after reversing the tokens. So:
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
Created on 2021-04-12 by the reprex package (v1.0.0)