Examples of SentenceDetectorME


Examples of opennlp.tools.sentdetect.SentenceDetectorME

  public static void main(String[] args) throws IOException {
    if (args.length == 0) {
      System.err.print("Usage java opennlp.tools.lang.spanish.SentenceDetector model < text");
      System.exit(1);
    }
    SentenceDetectorME sdetector = new SentenceDetector(args[0]);
    StringBuffer para = new StringBuffer();
    BufferedReader inReader = new BufferedReader(new InputStreamReader(System.in,"ISO-8859-1"));
    PrintStream out = new PrintStream(System.out,true,"ISO-8859-1");
    for (String line = inReader.readLine(); line != null; line = inReader.readLine()) {
      if (line.equals("")) {
        if (para.length() != 0) {
          //System.err.println(para.toString());
          String[] sents = sdetector.sentDetect(para.toString());
          for (int si = 0, sn = sents.length; si < sn; si++) {
            out.println(sents[si]);
          }
        }
        out.println();
        para.setLength(0);
      }
      else {
        para.append(line).append(" ");
      }
    }
    if (para.length() != 0) {
      String[] sents = sdetector.sentDetect(para.toString());
      for (int si = 0, sn = sents.length; si < sn; si++) {
        out.println(sents[si]);
      }
    }
  }
View Full Code Here

Examples of opennlp.tools.sentdetect.SentenceDetectorME

  public static void main(String[] args) throws IOException {
    if (args.length == 0) {
      System.err.print("Usage java opennlp.tools.sentdetect.EnglishSentenceDetectorME model < text");
      System.exit(1);
    }
    SentenceDetectorME sdetector = new SentenceDetector(args[0]);
    StringBuffer para = new StringBuffer();
    BufferedReader inReader = new BufferedReader(new InputStreamReader(System.in));
    for (String line = inReader.readLine(); line != null; line = inReader.readLine()) {
      if (line.equals("")) {
        if (para.length() != 0) {
          //System.err.println(para.toString());
          String[] sents = sdetector.sentDetect(para.toString());
          for (int si = 0, sn = sents.length; si < sn; si++) {
            System.out.println(sents[si]);
          }
        }
        System.out.println();
        para.setLength(0);
      }
      else {
        para.append(line).append(" ");
      }
    }
    if (para.length() != 0) {
      String[] sents = sdetector.sentDetect(para.toString());
      for (int si = 0, sn = sents.length; si < sn; si++) {
        System.out.println(sents[si]);
      }
    }
  }
View Full Code Here

Examples of opennlp.tools.sentdetect.SentenceDetectorME

  /**
  * this method updates the array of spans
   */
  private void getSentences(SentenceModel model){
    /* Configure the sentence detector with preloaded model */
    SentenceDetectorME sentenceDetector = new SentenceDetectorME(model)
   
    /* sentence spans is an array of Span objects where each span is a token
     * an span object has two integers with the start and end offset of a sentence*/
    sentenceSpans = sentenceDetector.sentPosDetect(text.getText());
  }
View Full Code Here

Examples of opennlp.tools.sentdetect.SentenceDetectorME

    SentenceDetectorME sentenceDetector;

    public ParseText() throws IOException {
        InputStream modelIO = new FileInputStream("en-sent.bin");
        SentenceModel sentenceModel = new SentenceModel(modelIO);
        sentenceDetector = new SentenceDetectorME(sentenceModel);
    }
View Full Code Here

Examples of opennlp.tools.sentdetect.SentenceDetectorME

    if (params.getMisclassified()) {
      errorListener = new SentenceEvaluationErrorListener();
    }
   
    SentenceDetectorEvaluator evaluator = new SentenceDetectorEvaluator(
        new SentenceDetectorME(model), errorListener);

    System.out.print("Evaluating ... ");
    try {
    evaluator.evaluate(sampleStream);
    }
View Full Code Here

Examples of opennlp.tools.sentdetect.SentenceDetectorME

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

      PerformanceMonitor perfMon = new PerformanceMonitor(System.err, "sent");
      perfMon.start();

      try {
        String para;
        while ((para = paraStream.read()) != null) {

          String[] sents = sdetector.sentDetect(para);
          for (String sentence : sents) {
            System.out.println(sentence);
          }

          perfMon.incrementCounter(sents.length);
View Full Code Here

Examples of opennlp.tools.sentdetect.SentenceDetectorME

  @Override
  public Resource init() throws ResourceInstantiationException {
    // logger.info("Sentence split url is: " + model.getFile());
    try {
      splitter = new SentenceDetectorME(getModel(model));
    } catch (Exception e) {
      logger.error("Sentence Splitter can not be initialized!");
      throw new RuntimeException(
          "Sentence Splitter cannot be initialized!", e);
    }
View Full Code Here

Examples of opennlp.tools.sentdetect.SentenceDetectorME

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

Examples of opennlp.tools.sentdetect.SentenceDetectorME

     * @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

Examples of opennlp.tools.sentdetect.SentenceDetectorME

        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
TOP
Copyright © 2018 www.massapi.com. 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.