I am following this article https://mylearnmachinelearning.com/category/linear-regression/ to create a Named Entity Extractor. Like required, I have installed all the openNLP
, NLP
, rJava
, magrittr
and openNLPmodels.en
packages. All has gone to plan except when using this function annotations
.:
# Extract entities from an AnnotatedPlainTextDocument
entities <- function(doc, kind) {
s <- doc$content
a <- annotations(doc)[[1]] #Point of error
if(hasArg(kind)) {
k <- sapply(a$features, `[[`, "kind")
s[a[k == kind]]
} else {
s[a[a$type == "entity"]]
}
}
by using this:
entities(text_doc, kind = "person")
.
The thing is even the intellisense in RStudio does not seem to know any function annotations
. It show annotation
,annotate
and annotations_in_spans
and what not but there is no annotations
.
There is even a YouTube video which demonstrates the same. Strangely he is able to use annotations
there.
Package versions:
openNLP: v0.2-6
openNLPmodels.en: v1.5-1
rJava - v0.9-9
magrittr - v1.5
NLP - v0.2-0
The annotations
method was associated with objects of type AnnotatedPlainTextDocument
in earlier versions of the NLP
package.
Here is the documentation for version 0.1-11.
The latest NLP version is 0.2-0.
The method for AnnotatedPlainTextDocument is now called annotation
(no 's' at the end). From the documentation it seems the main difference is that it returns an Annotation
object, not a list of Annotation
objects.