use of opennlp.tools.sentdetect.SentenceModel in project stanbol by apache.
the class OpenNlpSentenceDetectionEngine method getSentenceDetector.
/**
* Obtains the {@link SentenceDetectorME} model for the given
* language form the {@link #openNLP} service. If a custom
* model is configured for the parsed language than it is
* loaded by using {@link OpenNLP#getModel(Class, String, Map)}
* otherwise the default model {@link OpenNLP#getSentenceDetector(String)}
* is retrieved
* @param language the language
* @return the model of <code>null</code> if non is available or
* an exception was encountered while loading
*/
private SentenceDetector getSentenceDetector(String language) {
SentenceModel model;
String modelName = languageConfig.getParameter(language, MODEL_NAME_PARAM);
if (modelName == null) {
try {
model = openNLP.getSentenceModel(language);
} catch (Exception e) {
log.warn("Unable to load default Sentence Detection model for language '" + language + "'!", e);
return null;
}
} else {
try {
model = openNLP.getModel(SentenceModel.class, modelName, null);
} catch (Exception e) {
log.warn("Unable to load Sentence Detection model for language '" + language + "' from the configured model '" + modelName + "'!", e);
return null;
}
}
if (model != null) {
log.debug("Sentence Detection Model {} for lanugage '{}' version: {}", new Object[] { model.getClass().getSimpleName(), model.getLanguage(), model.getVersion() != null ? model.getVersion() : "undefined" });
return new SentenceDetectorME(model);
}
log.debug("Sentence Detection Model for Language '{}' not available.", language);
return null;
}
use of opennlp.tools.sentdetect.SentenceModel 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.sentdetect.SentenceModel in project stanbol by apache.
the class OpenNLPTest method testLoadIncompatibleModelByName.
@Test(expected = IllegalStateException.class)
public void testLoadIncompatibleModelByName() throws IOException {
SentenceModel sentModel = openNLP.getModel(SentenceModel.class, "en-token.bin", null);
Assert.assertNotNull(sentModel);
}
use of opennlp.tools.sentdetect.SentenceModel in project stanbol by apache.
the class TextAnalyzer method getSentenceDetector.
protected final SentenceDetector getSentenceDetector() {
if (!config.enableSentenceDetector) {
return null;
}
if (sentenceDetector == null && !sentenceDetectorNotAvailable) {
try {
SentenceModel sentModel = openNLP.getSentenceModel(language);
if (sentModel != null) {
sentenceDetector = new SentenceDetectorME(sentModel);
} else {
log.debug("No Sentence Detection Model for language '{}'", language);
sentenceDetectorNotAvailable = true;
}
} catch (IOException e) {
log.info("Unable to load Sentence Detection Model for language '" + language + "'", e);
sentenceDetectorNotAvailable = true;
}
}
return sentenceDetector;
}
use of opennlp.tools.sentdetect.SentenceModel in project useful-java-links by Vedenin.
the class OpenNLPSentenceDetectors method testOpenNLPPosition.
private Span[] testOpenNLPPosition(String text) throws Exception {
try (InputStream modelIn = this.getClass().getResourceAsStream(RESOURCES_EN_SENT_BIN)) {
SentenceModel model = new SentenceModel(modelIn);
SentenceDetectorME sentenceDetector = new SentenceDetectorME(model);
return sentenceDetector.sentPosDetect(text);
}
}
Aggregations