计算整个语料库类型的正确方法

问题描述 投票:0回答:1

我努力寻找正确的方法来计算 Quanteda 语料库中的类型(单词的独特形式)。

ntype()
给出每个文档的类型数量,但不是整个语料库的类型数量。

我找到了两种获得此计数的方法,这给出了两个不同的结果,我不明白为什么。

可复制代码:

library(quanteda)

corp_uk <- corpus(data_char_ukimmig2010)
corp_uk_tokens <- tokens(corp_uk, remove_punct = TRUE)

nfeat(dfm(corp_uk_tokens))
length(types(corp_uk_tokens))

nfeat(dfm(corp_uk_tokens))
输出1648

length(types(corp_uk_tokens))
输出1804

哪一个是正确的?为什么这两种计算结果不同?

非常感谢您的帮助!

types quanteda
1个回答
0
投票

因为

dfm()
默认有
tolower = TRUE
,所以
nfeat()
由于小写而合并了一些类型。如果您关闭此功能,您将得到与
types()
的长度相同的结果。

library(quanteda)
#> Package version: 4.0.0
#> Unicode version: 14.0
#> ICU version: 71.1
#> Parallel computing: disabled
#> See https://quanteda.io for tutorials and examples.

corp_uk <- corpus(data_char_ukimmig2010)
corp_uk_tokens <- tokens(corp_uk, remove_punct = TRUE)

# length of types vector
length(types(corp_uk_tokens))
#> [1] 1800

# gives the types after lowercasing, default for dfm()
nfeat(dfm(corp_uk_tokens))
#> [1] 1644

# without lowercasing, it's the same
nfeat(dfm(corp_uk_tokens, tolower = FALSE))
#> [1] 1800

创建于 2024-03-28,使用 reprex v2.1.0

© www.soinside.com 2019 - 2024. All rights reserved.