/* LanguageTool, a natural language style checker 
 * Copyright (C) 2005 Daniel Naber (http://www.danielnaber.de)
 * 
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * This library 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
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301
 * USA
 */
package de.danielnaber.languagetool.tagging.en;

import java.io.IOException;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

import junit.framework.TestCase;
import de.danielnaber.languagetool.AnalyzedTokenReadings;
import de.danielnaber.languagetool.tokenizers.WordTokenizer;

/**
 * @author Daniel Naber
 */
public class EnglishTaggerTest extends TestCase {

  private EnglishTagger tagger;
  private WordTokenizer tokenizer;
  
  public void setUp() {
    tagger = new EnglishTagger();
    tokenizer = new WordTokenizer();
  }

  public void testTagger() throws IOException {
    myAssert("This is a big house.", "This/[this]DT|This/[this]PDT is/[be]VBZ a/[a]DT big/[big]JJ|big/[big]VB house/[house]NN|house/[house]VB");
    myAssert("Marketing do a lot of trouble.", "Marketing/[marketing]NN:U|Marketing/[market]VBG do/[do]VB a/[a]DT lot/[lot]JJ|lot/[lot]NN|lot/[lot]VB of/[of]IN trouble/[trouble]NN:UN|trouble/[trouble]VB");
    myAssert("Manager use his laptop every day.", "Manager/[manager]NN use/[use]NN|use/[use]VB his/[his]PRP$|his/[hi]NNS laptop/[laptop]NN every/[every]DT day/[day]NN");
    myAssert("This is a bigger house.", "This/[this]DT|This/[this]PDT is/[be]VBZ a/[a]DT bigger/[big]JJR house/[house]NN|house/[house]VB");
    myAssert("He doesn't believe me.", "He/[he]PRP doesn/[do]VBZ t/[t]JJ|t/[t]NN|t/[t]RB believe/[believe]VB me/[I]PRP");
    myAssert("It has become difficult.", "It/[it]PRP has/[have]VBZ become/[become]VB difficult/[difficult]JJ"); 
  }

  private void myAssert(String input, String expected) throws IOException {
    List tokens = tokenizer.tokenize(input);
    List<String> noWhitespaceTokens = new ArrayList<String>();
    // whitespace confuses tagger, so give it the tokens but no whitespace tokens:
    for (Iterator iterator = tokens.iterator(); iterator.hasNext();) {
      String token = (String) iterator.next();
      if (isWord(token)) {
        noWhitespaceTokens.add(token);
      }
    }
    List output = tagger.tag(noWhitespaceTokens);
    StringBuffer outputStr = new StringBuffer();
    for (Iterator iter = output.iterator(); iter.hasNext();) {
      AnalyzedTokenReadings token = (AnalyzedTokenReadings) iter.next();
      int readingsNumber = token.getReadingsLength();
      for (int j = 0; j < readingsNumber; j++) {
      outputStr.append(token.getAnalyzedToken(j).getToken());
      outputStr.append("/[");
      outputStr.append(token.getAnalyzedToken(j).getLemma());
      outputStr.append("]");
      outputStr.append(token.getAnalyzedToken(j).getPOSTag());
      if (readingsNumber > 1 && j < readingsNumber - 1) {
      outputStr.append("|");
      }
      }
      if (iter.hasNext())
        outputStr.append(" ");
    }
    assertEquals(expected, outputStr.toString());
  }

  private boolean isWord(String token) {
    for (int i = 0; i < token.length(); i++) {
      char c = token.charAt(i);
      if (Character.isLetter(c) || Character.isDigit(c))
        return true;
    }
    return false;
  }

}

@@ -1573,16 +1573,29 @@
 /%5Bbig%5DVB
+%7Cbig/%5Bbig%5DVBP
  house/%5B
@@ -1610,32 +1610,49 @@
 %7Chouse/%5Bhouse%5DVB
+%7Chouse/%5Bhouse%5DVBP
 %22);%0A    myAssert
@@ -1744,16 +1744,27 @@
 o/%5Bdo%5DVB
+%7Cdo/%5Bdo%5DVBP
  a/%5Ba%5DDT
@@ -1799,16 +1799,29 @@
 /%5Blot%5DVB
+%7Clot/%5Blot%5DVBP
  of/%5Bof%5D
@@ -1861,24 +1861,45 @@
 /%5Btrouble%5DVB
+%7Ctrouble/%5Btrouble%5DVBP
 %22);%0A    myAs
@@ -1984,16 +1984,29 @@
 /%5Buse%5DVB
+%7Cuse/%5Buse%5DVBP
  his/%5Bhi
@@ -2209,16 +2209,33 @@
 house%5DVB
+%7Chouse/%5Bhouse%5DVBP
 %22);%0A    
@@ -2338,16 +2338,37 @@
 lieve%5DVB
+%7Cbelieve/%5Bbelieve%5DVBP
  me/%5BI%5DP
@@ -2457,16 +2457,54 @@
 ecome%5DVB
+%7Cbecome/%5Bbecome%5DVBN%7Cbecome/%5Bbecome%5DVBP
  difficu

update for stempelator 1.05