Search in sources :

Example 6 with SentenceModel

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);
    }
}
Also used : InputStream(java.io.InputStream) SentenceModel(opennlp.tools.sentdetect.SentenceModel) SentenceDetectorME(opennlp.tools.sentdetect.SentenceDetectorME)

Example 7 with SentenceModel

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);
    }
}
Also used : SentenceModel(opennlp.tools.sentdetect.SentenceModel) IOException(java.io.IOException) InvalidFormatException(opennlp.tools.util.InvalidFormatException)

Example 8 with SentenceModel

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);
}
Also used : SentenceModel(opennlp.tools.sentdetect.SentenceModel) SentenceDetector(opennlp.tools.sentdetect.SentenceDetector) Test(org.junit.Test)

Example 9 with SentenceModel

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);
}
Also used : SentenceModel(opennlp.tools.sentdetect.SentenceModel) SentenceDetector(opennlp.tools.sentdetect.SentenceDetector) Test(org.junit.Test)

Aggregations

SentenceModel (opennlp.tools.sentdetect.SentenceModel)9 SentenceDetectorME (opennlp.tools.sentdetect.SentenceDetectorME)4 Test (org.junit.Test)4 IOException (java.io.IOException)2 InputStream (java.io.InputStream)2 SentenceDetector (opennlp.tools.sentdetect.SentenceDetector)2 ChunkerModel (opennlp.tools.chunker.ChunkerModel)1 TokenNameFinderModel (opennlp.tools.namefind.TokenNameFinderModel)1 POSModel (opennlp.tools.postag.POSModel)1 TokenizerModel (opennlp.tools.tokenize.TokenizerModel)1 InvalidFormatException (opennlp.tools.util.InvalidFormatException)1 EngineException (org.apache.stanbol.enhancer.servicesapi.EngineException)1 ConfigurationException (org.osgi.service.cm.ConfigurationException)1