01: package org.incava.text;
02:
03: import java.io.*;
04: import java.util.*;
05: import junit.framework.TestCase;
06:
07: public class TestSpellChecker extends TestCase {
08: public TestSpellChecker(String name) {
09: super (name);
10: }
11:
12: public void testSame() {
13: SpellChecker sc = new SpellChecker();
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: SpellChecker sc = new SpellChecker();
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: SpellChecker sc = new SpellChecker();
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: }
|