Skip to content

dfm_lookup() and tokens_lookup() disagree #2159

Description

@koheiw

Looks like a bug. "GB" in "text2" is 2 and 3.

require(quanteda)
#> Loading required package: quanteda
#> Warning: package 'quanteda' was built under R version 4.0.5
#> Warning in stringi::stri_info(): Your native charset is not a superset of US-
#> ASCII. This may cause serious problems. Consider switching to UTF-8.

#> Warning in stringi::stri_info(): Your native charset is not a superset of US-
#> ASCII. This may cause serious problems. Consider switching to UTF-8.
#> Package version: 3.2.0
#> Unicode version: 13.0
#> ICU version: 69.1
#> Parallel computing: 8 of 8 threads used.
#> See https://quanteda.io for tutorials and examples.
require(newsmap)
#> Loading required package: newsmap
#> Warning: package 'newsmap' was built under R version 4.0.5
txt <- c("American and Japanese leaders met in Tokyo.",
         "Paris Hilton visited British museum in London.",
         "India and Pakistan are neighbours.",
         "A man went to the Moon.")
toks <- tokens(txt)
toks_label <- tokens_lookup(toks, data_dictionary_newsmap_en, levels = 3)
dfmt <- dfm(toks)
dfmt_label <- dfm(toks_label, tolower = FALSE)
dfmt_label[,c("GB", "JP", "FR")]
#> Document-feature matrix of: 4 documents, 3 features (75.00% sparse) and 0 docvars.
#>        features
#> docs    GB JP FR
#>   text1  0  2  0
#>   text2  2  0  1
#>   text3  0  0  0
#>   text4  0  0  0

dfmt_label2 <- dfm_lookup(dfmt, data_dictionary_newsmap_en, levels = 3)
dfmt_label2[,c("GB", "JP", "FR")]
#> Document-feature matrix of: 4 documents, 3 features (75.00% sparse) and 0 docvars.
#>        features
#> docs    GB JP FR
#>   text1  0  2  0
#>   text2  3  0  1
#>   text3  0  0  0
#>   text4  0  0  0

Created on 2022-01-24 by the reprex package (v2.0.1)

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions