statsmaths / cleanNLP

R package providing annotators and a normalized data model for natural language processing
GNU Lesser General Public License v2.1
209 stars 36 forks source link

possible failure to append meta data file to text file #51

Closed gsalfourn closed 4 years ago

gsalfourn commented 4 years ago

I am using the following: R version 3.6.1 (2019-07-05) RStudio Version 1.2.1335 cleanNLP version 2.3.0

the code for what I am running is below: it's from the 2017 publication of Taylor Arnold. i haven't made any modifications to it. when i ran the code to get estimate of speech length, it throws an error: "Error in FUN(X[[i]], ...) : object 'year' not found"

my thought is that for some reason the meta data file sotu_meta is not being appended to the sotu_text file

see sequence of codes below

intiliaze the spacy backend

cnlp_init_spacy()

run the annotator

sotu <- cleanNLP::cnlp_annotate(sotu_text, as_strings = TRUE, meta = sotu_meta)

estimate length of sotu speeches

cleanNLP::cnlp_get_token(sotu) %>% count(id) %>% left_join(cleanNLP::cnlp_get_document(sotu)) %>% ggplot(aes(year, n)) + geom_line(color = grey(0.8)) + geom_point(aes(color = sotu_type)) + geom_smooth()

Joining, by = "id"

the error message

Error in FUN(X[[i]], ...) : object 'year' not found

statsmaths commented 4 years ago

The code in the paper is using an older API. I recently released version 3.0.0 of cleanNLP on CRAN. I also posted a revised set of code replicating the analyses in the R Journal paper on the State of the Union Addresses here:

 https://statsmaths.github.io/cleanNLP/state-of-union.html

It uses the new versions' functions and should work if you reinstall a new version of cleanNLP.