package edu.brandeis.cs.steele.wn;

import junit.framework.TestCase;
import java.util.*;

public class MorphyTest extends TestCase {
  public void test1() {
    final DictionaryDatabase dictionary = FileBackedDictionary.getInstance();
    String[][] unstemmedStemmedCases = new String[][] {
      { POS.NOUN.name(), "dogs", "dog" },
      { POS.NOUN.name(), "geese", "goose" },
      { POS.NOUN.name(), "handfuls", "handful" },
      //"true case" bug { POS.NOUN.name(), "villas", "villa" },
      { POS.NOUN.name(), "heiresses", "heiress" }, 
        //WN missing derivationally relation to neuter form "heir" - intentional?
      { POS.NOUN.name(), "heiress", "heiress" },
      { POS.NOUN.name(), "George W. \t\tBush", "George W. Bush" }, //WN doesn't get this (extra internal space) (WN online does - probably string preprocessing)
      { POS.NOUN.name(), "george w. bush", "George W. Bush" },
      //WN doesn't get this either (missing ".") { POS.NOUN.name(), "george w bush", "George W. Bush" },
      { POS.NOUN.name(), "mice", "mouse" },
      { POS.NOUN.name(), "internal-combustion engine", "internal-combustion engine" },
      //WN 3 doesn't get this? { POS.NOUN.name(), "internal combustion engine", "internal-combustion engine" },
      { POS.NOUN.name(), "hangers-on", "hanger-on" },
      // needs " " -> "-" { POS.NOUN.name(), "hangers on", "hanger-on" },
      { POS.NOUN.name(), "letter bombs", "letter bomb" },
      // needs "-" -> "" { POS.NOUN.name(), "fire-bomb", "firebomb" },
      // needs "-" -> " " { POS.NOUN.name(), "letter-bomb", "letter bomb" },
      { POS.NOUN.name(), "I ran", null }, // WN gets this as "Iran" - " " -> "" seems bad unless a variant has "-" in same position (WN online doesn't do this)
      { POS.NOUN.name(), "be an", null }, // WN gets this as "bean" (WN online doesn't do this)
      { POS.NOUN.name(), "are a", null }, // WN gets this as "area" (WN online doesn't do this)
      { POS.VERB.name(), "dogs", "dog" },
      { POS.ADJ.name(), "onliner" /* no idea */, "online" },
      // should both variants be returned ? { POS.ADJ.name(), "onliner" /* no idea */, "on-line" },
      { POS.ADJ.name(), "redder" /* no idea */, "red" },
    };
    for(final String[] unstemmedStemmed : unstemmedStemmedCases) {
      final POS pos = POS.valueOf(unstemmedStemmed[0]);
      final String unstemmed = unstemmedStemmed[1];
      final String stemmed = unstemmedStemmed[2];
      final List<String> baseForms = Arrays.asList(dictionary.lookupBaseForms(pos, unstemmed));
      assertTrue("unstemmed: \""+unstemmed+"\" "+pos+" gold: \""+stemmed+"\" output: "+baseForms,
          baseForms.contains(stemmed) || (stemmed == null && baseForms.isEmpty()));
    }
  }
  // TODO
  // - upgrade to junit4 (@Test, @Ignore, paramterized tests) - don't forget adapter
  // - test plan
  //   - Morphy
  //     - make sure caching strategies are not harming correctness (uses DatabaseKey(pos, someString))
  //   - specific synsets
  //     - using offets will require changes as WN is improved
  //     - could use lemmma, pos, and (sense number OR gloss)
  //   - other relations including derivationally related
  //   * DictionaryDatabase iteration (require Xmx)
  //     - check if iteration returns first AND last item (boundary cases) - look at data files manually
  //   * multi-threaded correctness and no exceptions 
  //   - sense numbers
  //   - gloss
  //   - compare to parsed output of 'wn' binary (optional - @Ignore and/or boolean flag)
}

@@ -56,81 +56,180 @@
 ork.
-TestCase;%0Aimport java.util.*;%0A%0Apublic class MorphyTest extends TestCase %7B
+JUnit4TestAdapter;%0Aimport org.junit.*;%0Aimport static org.junit.Assert.*;%0Aimport java.util.*;%0A%0Apublic class MorphyTest %7B%0A  //TODO consider proper Parameterized tests%0A  @Test
 %0A  p
@@ -2819,93 +2819,8 @@
 ODO%0A
-  // - upgrade to junit4 (@Test, @Ignore, paramterized tests) - don't forget adapter%0A
   //
@@ -3172,212 +3172,249 @@
 /   
-* DictionaryDatabase iteration (require Xmx)%0A  //     - check if iteration returns first AND last item (boundary cases) - look at data files manually%0A  //   * multi-threaded correctness and no exceptions 
+- add speed tests%0A  //     - task-based: count unique Word's in all DBs%0A  //     - get stems of every lemma in all DBs (%22wounds%22 -%3E %22wound%22 -%3E %22wind%22) %0A  //     - compare speed with various CharStream impls (add some package private methods)
 %0A  /
@@ -3537,11 +3537,115 @@
 an flag)
+%0A%0A  public static junit.framework.Test suite() %7B%0A    return new JUnit4TestAdapter(MorphyTest.class);%0A  %7D
 %0A%7D%0A

converted to JUnit 4