Search in sources :

Example 1 with ChunkerModel

use of opennlp.tools.chunker.ChunkerModel in project stanbol by apache.

the class OpenNlpChunkingEngine method initChunker.

private ChunkerME initChunker(String language) {
    //check if the parsed language is ok
    isLangaugeConfigured(this, languageConfiguration, language, true);
    String modelName = languageConfiguration.getParameter(language, MODEL_PARAM_NAME);
    ChunkerModel model;
    try {
        if (modelName == null) {
            // the default model
            model = openNLP.getChunkerModel(language);
        } else {
            model = openNLP.getModel(ChunkerModel.class, modelName, null);
        }
    } catch (IOException e) {
        log.warn("Unable to load Chunker model for language '" + language + "' (model: " + (modelName == null ? "default" : modelName) + ")", e);
        return null;
    } catch (RuntimeException e) {
        log.warn("Error while creating ChunkerModel for language '" + language + "' (model: " + (modelName == null ? "default" : modelName) + ")", e);
        return null;
    }
    if (model == null) {
        log.trace("no Chunker Model for language {}", language);
        return null;
    } else {
        return new ChunkerME(model);
    }
}
Also used : ChunkerModel(opennlp.tools.chunker.ChunkerModel) ChunkerME(opennlp.tools.chunker.ChunkerME) IOException(java.io.IOException)

Example 2 with ChunkerModel

use of opennlp.tools.chunker.ChunkerModel in project stanbol by apache.

the class OpenNLPTest method testLoadMissingChunker.

@Test
public void testLoadMissingChunker() throws IOException {
    ChunkerModel model = openNLP.getChunkerModel("ru");
    Assert.assertNull(model);
    Chunker chunker = openNLP.getChunker("ru");
    Assert.assertNull(chunker);
}
Also used : ChunkerModel(opennlp.tools.chunker.ChunkerModel) Chunker(opennlp.tools.chunker.Chunker) Test(org.junit.Test)

Example 3 with ChunkerModel

use of opennlp.tools.chunker.ChunkerModel in project stanbol by apache.

the class OpenNLPTest method testLoadModelByName.

@Test
public void testLoadModelByName() throws IOException {
    TokenizerModel tokenModel = openNLP.getModel(TokenizerModel.class, "en-token.bin", null);
    Assert.assertNotNull(tokenModel);
    SentenceModel sentModel = openNLP.getModel(SentenceModel.class, "en-sent.bin", null);
    Assert.assertNotNull(sentModel);
    POSModel posModel = openNLP.getModel(POSModel.class, "en-pos-maxent.bin", null);
    Assert.assertNotNull(posModel);
    ChunkerModel chunkModel = openNLP.getModel(ChunkerModel.class, "en-chunker.bin", null);
    Assert.assertNotNull(chunkModel);
    TokenNameFinderModel nerModel = openNLP.getModel(TokenNameFinderModel.class, "en-ner-person.bin", null);
    Assert.assertNotNull(nerModel);
    //unavailable model
    tokenModel = openNLP.getModel(TokenizerModel.class, "ru-token.bin", null);
    Assert.assertNull(tokenModel);
}
Also used : TokenNameFinderModel(opennlp.tools.namefind.TokenNameFinderModel) ChunkerModel(opennlp.tools.chunker.ChunkerModel) SentenceModel(opennlp.tools.sentdetect.SentenceModel) POSModel(opennlp.tools.postag.POSModel) TokenizerModel(opennlp.tools.tokenize.TokenizerModel) Test(org.junit.Test)

Example 4 with ChunkerModel

use of opennlp.tools.chunker.ChunkerModel in project stanbol by apache.

the class OpenNLPTest method testLoadEnChunker.

@Test
public void testLoadEnChunker() throws IOException {
    ChunkerModel model = openNLP.getChunkerModel("en");
    Assert.assertNotNull(model);
    Chunker chunker = openNLP.getChunker("en");
    Assert.assertNotNull(chunker);
}
Also used : ChunkerModel(opennlp.tools.chunker.ChunkerModel) Chunker(opennlp.tools.chunker.Chunker) Test(org.junit.Test)

Example 5 with ChunkerModel

use of opennlp.tools.chunker.ChunkerModel in project stanbol by apache.

the class TextAnalyzer method getChunker.

protected final ChunkerME getChunker() {
    if (!config.enableChunker || config.forcePosTypeChunker) {
        return null;
    }
    if (chunker == null && !chunkerNotAvailable) {
        try {
            ChunkerModel chunkerModel = openNLP.getChunkerModel(language);
            if (chunkerModel != null) {
                chunker = new ChunkerME(chunkerModel);
            } else {
                log.debug("No Chunker Model for language {}", language);
                chunkerNotAvailable = true;
            }
        } catch (IOException e) {
            log.info("Unable to load Chunker Model for language " + language, e);
            chunkerNotAvailable = true;
        }
    }
    return chunker;
}
Also used : ChunkerModel(opennlp.tools.chunker.ChunkerModel) ChunkerME(opennlp.tools.chunker.ChunkerME) IOException(java.io.IOException)

Aggregations

ChunkerModel (opennlp.tools.chunker.ChunkerModel)5 Test (org.junit.Test)3 IOException (java.io.IOException)2 Chunker (opennlp.tools.chunker.Chunker)2 ChunkerME (opennlp.tools.chunker.ChunkerME)2 TokenNameFinderModel (opennlp.tools.namefind.TokenNameFinderModel)1 POSModel (opennlp.tools.postag.POSModel)1 SentenceModel (opennlp.tools.sentdetect.SentenceModel)1 TokenizerModel (opennlp.tools.tokenize.TokenizerModel)1