Skip to content

dfm_lookup() produces different result when dictionary keys are in different order #2424

Description

@koheiw
library(quanteda)
#> Package version: 4.1.0
#> Unicode version: 15.1
#> ICU version: 74.1
#> Parallel computing: 16 of 16 threads used.
#> See https://quanteda.io for tutorials and examples.

toks <- tokens(c("I like apples, but I don't like apple pie. Bananas are OK",
                 "I like bananas, but I don't like banana fritter."))
dfmat <- dfm(toks)

dict <- dictionary(list(apple = c("apple*"),
                        banana = c("banana*")))
dfmat1 <-  dfm_lookup(dfmat,
                     dictionary = dict, exclusive = FALSE, capkeys = FALSE)

dfmat2 <-  dfm_lookup(dfmat,
                      dictionary = rev(dict), exclusive = FALSE, capkeys = FALSE)

identical(as.matrix(dfmat1), as.matrix(dfmat2))
#> [1] FALSE

dfmat3 <-  dfm(tokens_lookup(toks, dictionary = rev(dict), 
                             exclusive = FALSE, capkeys = FALSE))

identical(as.matrix(dfmat1), as.matrix(dfmat3))
#> [1] TRUE

Metadata

Metadata

Assignees

Labels

Type

No type

Fields

No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions