01: package org.incava.text;
02:
03: import java.io.*;
04: import java.util.*;
05: import junit.framework.TestCase;
06:
07: public class TestNoCaseSpellChecker extends TestCase {
08: public TestNoCaseSpellChecker(String name) {
09: super (name);
10: }
11:
12: public void testSame() {
13: NoCaseSpellChecker sc = new NoCaseSpellChecker();
14: assertEquals(0, sc.editDistance("this", "this"));
15: assertEquals(0, sc.editDistance("THIS", "THIS"));
16: assertEquals(0, sc.editDistance("repository", "repository"));
17: }
18:
19: public void testDifferent() {
20: NoCaseSpellChecker sc = new NoCaseSpellChecker();
21:
22: // additions
23: assertEquals(1, sc.editDistance("the", "THEY"));
24: assertEquals(2, sc.editDistance("The", "their"));
25: assertEquals(3, sc.editDistance("thEy", "THEY're"));
26: assertEquals(4, sc.editDistance("THE", "theaTre", 5));
27: assertEquals(4, sc.editDistance("the", "THEAter", 5));
28:
29: // deletions
30: assertEquals(1, sc.editDistance("thEy", "tHe"));
31: assertEquals(2, sc.editDistance("thEIR", "The"));
32: assertEquals(3, sc.editDistance("ThEy'Re", "ThEy"));
33: assertEquals(4, sc.editDistance("tHeaTre", "tHe", 5));
34: assertEquals(4, sc.editDistance("thEatEr", "ThE", 5));
35:
36: // changes
37: assertEquals(2, sc.editDistance("tHeaTER", "theAtre"));
38: assertEquals(2, sc.editDistance("cenTER", "cEntre"));
39: assertEquals(2, sc.editDistance("reAlize", "reALISE"));
40: assertEquals(4, sc.editDistance("rEaLiZE", "Reality", 5));
41:
42: // miscellaneous
43: assertEquals(1, sc.editDistance("Here", "There"));
44: assertEquals(5, sc.editDistance("hIt", "miSS", 5));
45: assertEquals(6, sc.editDistance("up", "dOWn", 6));
46: assertEquals(7, sc.editDistance("fEast", "fAMINE", 7));
47: }
48:
49: public void testDictionary() {
50: NoCaseSpellChecker sc = new NoCaseSpellChecker();
51: sc.addDictionary("/home/jpace/proj/doctorj/etc/words.en_US");
52:
53: assertTrue(sc.hasWord("Locate"));
54: assertTrue(sc.hasWord("LogAritHM"));
55: assertFalse(sc.hasWord("EuJiffEroUs")); // alas.
56:
57: Map nearMatches = new TreeMap();
58: boolean isOK = sc.isCorrect("badd", nearMatches);
59: tr.Ace.log("isOK: " + isOK);
60: tr.Ace.log("nearMatches", nearMatches);
61: }
62:
63: }
|