gt:             			  tmp + " ");
context: /*
   JavaRAP: a freely-available JAVA anaphora resolution implementation
   of the classic Lappin and Leass (1994) paper:
  
   An Algorithm for Pronominal Anaphora Resolution.
   Computational Linguistics, 20(4), pp. 535-561.
  
   Copyright (C) 2005  Long Qiu
  
   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 2
   of the License, or (at your option) 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, write to the Free Software
   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
   */
  
  package edu.nus.comp.nlp.tool.anaphoraresolution;
  
  import java.io.*;
  import java.util.*;
  import java.util.regex.*;
  
  /**
   * <p>Title: NLP Tools</p>
   * <p>Description: A copy of external class to make JavaRAP standalone.
   * </p>
   * <p>Copyright: Copyright (c) 2003</p>
   * <p>Company: NUS</p>
   * @author Qiu Long qiul@comp.nus.edu.sg
   * @version 2.04
   *
   * History:
   * 2010.01.03 Bug fixing: In splitSentences() the size of <i>sents</i> wasn't checked before trying to remove something
   *            from it, at one point. Corrected. ( Thanks to Chisom. ) 
   * 2006.11.01 V2.04.1 Unpaired double-quotation mark in the input text: If there is one at the then of the input text and
   * for some reason (ill-formated input, for instance) it is not recognized as a closing one, It'll form a pseudo sentence
   * with only a "\"", which won't be parsed, syntactically or semantically. Such sentences without parses cause problem in
   * downstream analysiers. Solution: Attach it to the last sentence.
   * 2006.11.01 V2.04 Bug fixing: Ending sentence like "A is U.S." will no longer be added twice, either.
   * 2005.11.30 V2.03 Bug fixing: Ending sentence like "A is U.S. " will no longer be missed.
   * 2005.07.24 V2.02 Bug fixing: A., B., were splitted into A. <s> , B., ... Fixed by strictly requiring an upper case letter as the head of a sentence.
   * 2004.09.27 V2.01 Bug fixing: Single upper case letter could be the head of sentences. (As well as X.X.X.)
   *            So "... was found. U.S. ... " are separated now.
   * 2004.04.28 V2.00 Bug fixing: Sentences contain more than one <i>Title CapitalLetters</i> combinations no longer wrongly separated.
   * 2003.12.09 Original puncuations retained. Switch from split to StringTokenizer to keep the delimiters.
   * 2003.11.04 New lines within sentences removed.
   *
   *
   */
  
  
  public class PlainText implements java.io.Serializable{
    final static public String sentDelim =
        "``|''|\\?\"|\\!\"|\\.\"|\\. |\\.\n|\n\n|\\!|\\?";
    static String extraStr = ""; //string goes between <s> and the sentence
  
  
    static boolean singleLine = false;
    StringBuffer text = null;
    String[] sents = null;
  
  
    public PlainText() {
    }
  
    public PlainText(String fileName) {
      text = Util.readFile(fileName);
      mergeQuots();
    }
  
    public PlainText(String fileName, String commentFlag) {
      text = Util.readFile(fileName,commentFlag);
      mergeQuots();
    }
  
    public PlainText(StringBuffer str) {
      text = str;
      mergeQuots();
    }
  
    public void setSents(String[] ss){
      sents = ss;
    }
  
    public int getSentCount(){
      if(sents==null){
        sents = PlainText.splitSentences(text.toString(),
                                                PlainText.sentDelim);
      }
      return sents.length;
    }
  
    public String addQuote(boolean debugMode, String exStr) {
      this.extraStr = exStr;
      return addQuote(debugMode);
    }
  
    /**
     * @param debugMode: If true, a index for each sentence is displayed.
     * @return
     */
    public String addQuote(boolean debugMode) {
      if(sents ==null){
        sents = PlainText.splitSentences(text.toString(),
                                         PlainText.sentDelim);
      }
      String outStr = new String();
  
      String openFlag = "<s> ";
      String closingFlag = "</s>";
  
      for (int i = 0; i < sents.length; i++) {
        if (debugMode) {
          outStr += String.valueOf(i+1) + "\t" + openFlag + extraStr + sents[i] +
              " " + extraStr + closingFlag + "\n";
        }
        else {
          outStr += openFlag + extraStr + sents[i] + " " + extraStr + closingFlag +
              "\n";
        }
      }
      return outStr;
    }
  
    public void mergeQuots() {
      String pureTextA = Util.mergeDoubleSingleQuots(text.toString());
      text = new StringBuffer(pureTextA);
    }
  
    public String[] splitSentences() {
      return splitSentences(text.toString(), PlainText.sentDelim);
    }
  
    static public String[] splitSentences(String text, String delim) {
      ArrayList sents = new ArrayList();
      String delimForTokenizer = "!|\"|\\.|\\?"; //| is not necessary here, added for the sake of checking "tmp.matches(delimForTokenizer"
      String sentence = null;
      String title_acronym = "";
  
      if (text != null) {
        //List sentenceList = Arrays.asList(text.toString().split(delim));
        //ListIterator iterator = sentenceList.listIterator();
        StringTokenizer tokenizer = new StringTokenizer(text, delimForTokenizer, true);
  
        //Pattern pSentenceHead = Pattern.compile("(<[.[^<>]]+>\\W?)*\\W*[A-Z\"].*");//sep27 2004, make it match single upper case letter as well.
        Pattern pSentenceHead = Pattern.compile("(<[.[^<>]]+>\\s?)*\\s*[A-Z\"].*");//jul24 2005
  
        boolean acronym = false; //
        boolean openQuotation = true;
  
        while (tokenizer.hasMoreTokens()) {
  
  
          String tmp = new String( ( (String) tokenizer.nextToken()).trim());
          if (false) {
            System.err.println(tmp);
            System.err.println("=" + title_acronym + "=");
            System.err.println(acronym);
          }
          Matcher mSentenceHead = pSentenceHead.matcher(tmp);
  
          if (tmp.length() == 0) {
            //skip spaces
            continue;
          }
          else if (tmp.matches(delimForTokenizer)) {
  
              if (acronym || (title_acronym.length()>0) ) {
                title_acronym += tmp + " ";
                if (!tokenizer.hasMoreTokens()) {
                  //Ending "B."
                  //hacked on Jan.30 2004, to couple with sentence like A is a B.
                  //Sometime a tailing token might fail this condition check and leave a title_acronym out of the sents. This will be addressed by a checking on title_acronym after this while loop
                  sents.add(title_acronym);
                  title_acronym = ""; //Reset: The content till the very end of the input has been fit into a sentence. Nov.1 2006
                }
              }else if (tmp.equals("\"") && openQuotation
                      && tokenizer.hasMoreTokens()) { //Nov.1, 2006. See @History 2006.11.01 V2.04.1
                openQuotation = !openQuotation;
  
                //concatenate with previous part which doesn't end with a valid sentence deliminator
                String previousSent = " ";
                if (sents.size() > 0) {
                  previousSent = ( (String) sents.get(sents.size() - 1)).trim();
                }
  
                String ending = previousSent.substring(previousSent.length() - 1);
                if (!ending.matches(delimForTokenizer)) {
                  //The previous segment does not end with a legal sentence deliminator, concatenate
                  if (sents.size() > 0) {
                    sents.add( ( (String) sents.remove(sents.size() - 1)) +
                              tmp + " ");
                  }
                  else {
                    //Happens when the article starts with an openning quot
                    sents.add(tmp + " ");
                  }
                }
                else {
                  title_acronym += tmp + " ";
                }
              }else {
  
                if (tmp.equals("\"")) {
                  openQuotation = !openQuotation;
                }
                //it is possibly a closing punctuation
                if (sents.size() > 0) { //This wasn't checked until 2010.01.03, as suggested by Chisom.
              	  sents.add( ( (String) sents.remove(sents.size() - 1)) +
  