Package opennlp.tools.sentdetect

Examples of opennlp.tools.sentdetect.SentenceModel


   
    if (args.length != 1) {
      System.out.println(getHelp());
    } else {

      SentenceModel model = new SentenceModelLoader().load(new File(args[0]));

      SentenceDetectorME sdetector = new SentenceDetectorME(model);

      ObjectStream<String> paraStream =
        new ParagraphStream(new PlainTextByLineStream(new InputStreamReader(System.in)));
View Full Code Here


        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;
View Full Code Here

        Assert.assertEquals(SimpleTokenizer.INSTANCE, tokenizer);
    }
   
    @Test
    public void testLoadEnSentence() throws IOException{
        SentenceModel model = openNLP.getSentenceModel("en");
        Assert.assertNotNull(model);
        SentenceDetector sentDetector = openNLP.getSentenceDetector("en");
        Assert.assertNotNull(sentDetector);
    }
View Full Code Here

        SentenceDetector sentDetector = openNLP.getSentenceDetector("en");
        Assert.assertNotNull(sentDetector);
    }
    @Test
    public void testLoadMissingSentence() throws IOException{
        SentenceModel model = openNLP.getSentenceModel("ru");
        Assert.assertNull(model);
        SentenceDetector sentDetector = openNLP.getSentenceDetector("ru");
        Assert.assertNull(sentDetector);
    }
View Full Code Here

    }
    @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);
View Full Code Here

        tokenModel = openNLP.getModel(TokenizerModel.class, "ru-token.bin", null);
        Assert.assertNull(tokenModel);
    }
    @Test(expected=IllegalStateException.class)
    public void testLoadIncompatibleModelByName() throws IOException{
        SentenceModel sentModel = openNLP.getModel(SentenceModel.class, "en-token.bin", null);
        Assert.assertNotNull(sentModel);
    }
View Full Code Here

     * @return the model or <code>null</code> if no model data are found
     * @throws InvalidFormatException in case the found model data are in the wrong format
     * @throws IOException on any error while reading the model data
     */
    public SentenceDetector getSentenceDetector(String language) throws IOException {
        SentenceModel sentModel = getSentenceModel(language);
        if(sentModel != null){
            return new SentenceDetectorME(sentModel);
        } else {
            log.debug("No Sentence Detection Model for language '{}'",language);
            return null;
View Full Code Here

     * @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;
    }
View Full Code Here

    String sdModelPath = (String) context
        .getConfigParameterValue(SD_MODEL_FILE_PARAM);
      InputStream is = FileLocator.getAsStream(sdModelPath);
      logger.info("Sentence detector model file: " + sdModelPath);
      sdmodel = new SentenceModel(is);
      is.close();
      EndOfSentenceScannerImpl eoss = new EndOfSentenceScannerImpl();
      char[] eosc = eoss.getEndOfSentenceCharacters();
      // SentenceDContextGenerator cg = new SentenceDContextGenerator();
      DefaultSDContextGenerator cg = new DefaultSDContextGenerator(eosc);
View Full Code Here

  public void initialize(UimaContext aContext)
      throws ResourceInitializationException {
    super.initialize(aContext);
    try (InputStream is = FileLocator.getAsStream(sdModelPath)){
      logger.info("Sentence detector model file: " + sdModelPath);
      sdmodel = new SentenceModel(is);
      EndOfSentenceScannerImpl eoss = new EndOfSentenceScannerImpl();
      DefaultSDContextGenerator cg = new DefaultSDContextGenerator(eoss.getEndOfSentenceCharacters());
      sentenceDetector = new SentenceDetectorCtakes(
          sdmodel.getMaxentModel(), cg, eoss);
View Full Code Here

TOP

Related Classes of opennlp.tools.sentdetect.SentenceModel

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.