Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

OpenNLP lemmatization example

Tags:

nlp

opennlp

Does anyone know where I can find an example of how to use the SimpleLemmatizer() class in the OpenNLP library, and where I can find a sample english dictionary? It appears to be missing from the documentation.

like image 411
pYr0 Avatar asked Aug 16 '16 18:08

pYr0


2 Answers

You can download Dictionary from here - en-lemmatizer.dict

Example :

import opennlp.tools.lemmatizer.SimpleLemmatizer;

private static SimpleLemmatizer lemmatizer;

private String lemmatize(String word, String postag) throws IOException {
    if (lemmatizer == null) {
        InputStream is = getClass().getResourceAsStream("/models/en-lemmatizer.dict");
        lemmatizer = new SimpleLemmatizer(is);
        is.close();
    }
    String lemma = lemmatizer.lemmatize(word, postag);
    return lemma;
}

Sample code taken from here - DocumentTaggerService

like image 110
RAVI Avatar answered Sep 27 '22 17:09

RAVI


RAVI did not fully answer the question:

The reason you aren't seeing the SimpleLemmatizer in the autodoc is because it actually doesn't exist.

Use DictionaryLemmatizer instead.

opennlp.tools.lemmatizer.DictionaryLemmatizer

like image 38
Collin Bell Avatar answered Sep 27 '22 18:09

Collin Bell