3

I am trying to run a basic sentence annotation function and I keep running into the same error.

The code I tried to use is:

 s <- as.String(cleandata) #cleandata is my data.It is a character class.
 sent_ann <- Maxent_Sent_Token_Annotator()
 a2 <- annotate(s,sent_ann) 

The above code keeps generating the error:

Error in as.data.frame.default(x[[i]], optional = TRUE) : 
cannot coerce class "c("Simple_Sent_Token_Annotator", "Annotator")" to a data.frame

What do I do ?

2 Answers2

5

I was getting your same error, doing exactly the same. Then I restarted R-studio, I loaded the libraries

library(NLP);
library(tm);
library(openNLP);
library(openNLPmodels.en);

and I could execute the statement successfully.

Rafa
  • 51
  • 3
1

I had the same error. In my case the tidyverse library was overwriting the annotate function from NLP. This should work:

library(NLP);
library(openNLP);
Jurian-K
  • 11
  • 2