Zaid Khan
Zaid Khan

Reputation: 826

Has the method annotations in R(NLP package) been deprecated or replaced?

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:

  1. openNLP: v0.2-6

  2. openNLPmodels.en: v1.5-1

  3. rJava - v0.9-9

  4. magrittr - v1.5

  5. NLP - v0.2-0

Upvotes: 2

Views: 776

Answers (3)

Anibal Feijoo
Anibal Feijoo

Reputation: 11

try this:

# Extract entities from an AnnotatedPlainTextDocument
         entities <- function(doc, kind) {
         s <- doc$content
         a <- annotation(doc)
         if(hasArg(kind)) {
             k <- sapply(a$features, `[[`, "kind")
             s[a[k == kind]]
         } else {
             s[a[a$type == "entity"]]
         }
     }

Upvotes: 1

MS Berends
MS Berends

Reputation: 5219

The function annotations is in a lot of packages, please see here: https://www.rdocumentation.org/search?q=annotations

Albeit probably not the best way, if you are looking for a specific function without knowing which package the function belongs to, this site may help you find such a package.

Upvotes: 1

neilfws
neilfws

Reputation: 33782

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.

Upvotes: 3

Related Questions