Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

textstat_readability() returns nothing for an empty document #1976

Closed
kbenoit opened this issue Jun 30, 2020 · 0 comments
Closed

textstat_readability() returns nothing for an empty document #1976

kbenoit opened this issue Jun 30, 2020 · 0 comments
Assignees
Labels

Comments

@kbenoit
Copy link
Collaborator

kbenoit commented Jun 30, 2020

The question has arisen in #1969 of how to handle NA documents. What about empty string documents? Right now, textstat_readability() returns nothing if the document was "". This is not true for other textstat returns. We should make them consistent.

library("quanteda")
## Package version: 2.1.0

txt <- c(d1 = "The cat in the hat", d2 = "", d3 = "Once upon a time.")
corp <- corpus(txt)
toks <- tokens(corp)
dfmat <- dfm(toks)

textstat_readability(txt)
##   document  Flesch
## 1       d1 117.160
## 2       d3  97.025
textstat_readability(corp)
##   document  Flesch
## 1       d1 117.160
## 2       d3  97.025

textstat_dist(dfmat) %>%
  as.data.frame()
##   document1 document2 euclidean
## 1        d3        d1  3.464102
## 2        d1        d3  3.464102

textstat_entropy(dfmat)
##   document  entropy
## 1       d1 1.921928
## 2       d2 0.000000
## 3       d3 2.321928

textstat_lexdiv(toks)
##   document TTR
## 1       d1 0.8
## 2       d2 NaN
## 3       d3 1.0
textstat_lexdiv(dfmat)
##   document TTR
## 1       d1 0.8
## 2       d2 NaN
## 3       d3 1.0

Suggestion

Return NA for textstat_readability() if the document is zero.

@kbenoit kbenoit added this to the v2.1 essentials milestone Jun 30, 2020
@kbenoit kbenoit self-assigned this Jun 30, 2020
@kbenoit kbenoit mentioned this issue Jun 30, 2020
@kbenoit kbenoit closed this as completed in f06948e Jul 2, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant