简体   繁体   English

R:如何计算语料库中的令牌总数?

[英]R: How to count the total number of tokens in a corpus?

I have created a Quanteda corpus called readtext_corpus with 190 types of text.我创建了一个名为 readtext_corpus 的 Quanteda 语料库,其中包含 190 种文本。 I would like to count the total number of tokens or words in the corpus.我想计算语料库中标记或单词的总数。 I tried the function ntoken which gives a number of words per text not the total number of words for all 190 texts.我尝试了 function ntoken,它给出了每个文本的单词数,而不是所有 190 个文本的总单词数。

you can just use the sum() function which is really simple.你可以只使用 sum() function 这真的很简单。 I left an example:我留下了一个例子:

test <- c("testing string number 1","testing string number 2")

sum(quanteda::ntoken(test))

Result:结果:

> quanteda::ntoken(test)
text1 text2 
    4     4 
> sum(quanteda::ntoken(test))
[1] 8
> 

In case you are using pipes, which is pretty common with quanteda如果您使用的是管道,这在 quanteda 中很常见

> quanteda::ntoken(test) %>% sum()
[1] 8

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM