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);
}
}
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);
}
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);
}
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);
}
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;
}
Aggregations