Package functionality

Source Code of functionality.SentenceOnText

/*
*    Copyright (C) 2012  Marta Rodr�guez, Teresa de Salas, Ana Vargas
*
*    This program is free software: you can redistribute it and/or
*    modify it under the terms of the GNU General Public License as
*    published by the Free Software Foundation, either version 3 of
*    the License, or any later version.
*
*    This program is distributed in the hope that it will be useful,
*    but WITHOUT ANY WARRANTY; without even the implied warranty of
*    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
*    GNU General Public License for more details.
*
*   You should have received a copy of the GNU General Public License
*   along with this program. If not, see
*   http://www.gnu.org/licenses/.
*/

package functionality;

import opennlp.tools.sentdetect.SentenceDetectorME;
import opennlp.tools.sentdetect.SentenceModel;
import opennlp.tools.util.Span;

import org.gjt.sp.jedit.textarea.JEditTextArea;

/**
*
* @author Marta Rodr�guez
* @author Teresa de Salas
* @author Ana Vargas
*
*/
public class SentenceOnText {
 
  /**
   * caret position on text
   */
  private int caretPos;
 
  /**
   * start position of sentence on text
   */
  private int startPos;
 
  /**
   * end position of sentence on text
   */
  private int endPos;
 
  /**
   * text that starts on startPos and ends on endPos
   */
  private JEditTextArea text;
 
  /**
   * array of spans objects
   */
  private Span sentenceSpans[];
 
  public SentenceOnText(JEditTextArea text,int offset){
    this.text = text;
    this.caretPos = offset;
  }
 
  /**
  * 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());
  }
 
  /**
   * this method gets the sentence that contains the caret position
   */
  public void getSentenceForWord(SentenceModel model){
    getSentences(model);
    boolean finded = false;
    int i = 0;
    while (i < sentenceSpans.length && !finded){
      Span s = sentenceSpans[i];
      if (caretPos >= s.getStart() && caretPos <=s.getEnd()){
        startPos = s.getStart();
        endPos = s.getEnd();
        finded = true;
      }
      i++;
    }
  }

  public int getStart(){ return this.startPos;}
  public int getEnd(){return this.endPos;}
 
}
TOP

Related Classes of functionality.SentenceOnText

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.