use of opennlp.tools.sentdetect.SentenceModel in project useful-java-links by Vedenin.
the class OpenNLPSentenceDetectors method testOpenNLP.
private String[] testOpenNLP(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.sentDetect(text);
}
}
use of opennlp.tools.sentdetect.SentenceModel in project stanbol by apache.
the class NEREngineCore method getSentenceModel.
/**
* Loads the {@link SentenceModel} for the parsed language or
* English as fallback if one for the language is not available
* @param language
* @return
*/
private SentenceModel getSentenceModel(String language) {
try {
SentenceModel model = openNLP.getSentenceModel(language);
if (model != null) {
return model;
} else {
//fallback to english
log.info("No sentence detection modle for {}. fallback to English");
model = openNLP.getSentenceModel("en");
if (model == null) {
throw new IllegalStateException(String.format("Unable to built Model for extracting sentences neither for '%s' " + "nor the fallback language 'en'.", language));
} else {
return model;
}
}
} catch (InvalidFormatException e) {
throw new IllegalStateException(String.format("Unable to built Model for extracting sentences from '%s' language texts.", language), e);
} catch (IOException e) {
throw new IllegalStateException(String.format("Unable to built Model for extracting sentences from '%s' language texts.", language), e);
}
}
use of opennlp.tools.sentdetect.SentenceModel in project stanbol by apache.
the class OpenNLPTest method testLoadEnSentence.
@Test
public void testLoadEnSentence() throws IOException {
SentenceModel model = openNLP.getSentenceModel("en");
Assert.assertNotNull(model);
SentenceDetector sentDetector = openNLP.getSentenceDetector("en");
Assert.assertNotNull(sentDetector);
}
use of opennlp.tools.sentdetect.SentenceModel in project stanbol by apache.
the class OpenNLPTest method testLoadMissingSentence.
@Test
public void testLoadMissingSentence() throws IOException {
SentenceModel model = openNLP.getSentenceModel("ru");
Assert.assertNull(model);
SentenceDetector sentDetector = openNLP.getSentenceDetector("ru");
Assert.assertNull(sentDetector);
}
Aggregations