1 package org.egothor.stemmer;
4 Egothor Software License version 1.00
5 Copyright (C) 1997-2004 Leo Galambos.
6 Copyright (C) 2002-2004 "Egothor developers"
7 on behalf of the Egothor Project.
10 This software is copyrighted by the "Egothor developers". If this
11 license applies to a single file or document, the "Egothor developers"
12 are the people or entities mentioned as copyright holders in that file
13 or document. If this license applies to the Egothor project as a
14 whole, the copyright holders are the people or entities mentioned in
15 the file CREDITS. This file can be found in the same location as this
16 license in the distribution.
18 Redistribution and use in source and binary forms, with or without
19 modification, are permitted provided that the following conditions are
21 1. Redistributions of source code must retain the above copyright
22 notice, the list of contributors, this list of conditions, and the
24 2. Redistributions in binary form must reproduce the above copyright
25 notice, the list of contributors, this list of conditions, and the
26 disclaimer that follows these conditions in the documentation
27 and/or other materials provided with the distribution.
28 3. The name "Egothor" must not be used to endorse or promote products
29 derived from this software without prior written permission. For
30 written permission, please contact Leo.G@seznam.cz
31 4. Products derived from this software may not be called "Egothor",
32 nor may "Egothor" appear in their name, without prior written
33 permission from Leo.G@seznam.cz.
35 In addition, we request that you include in the end-user documentation
36 provided with the redistribution and/or in the software itself an
37 acknowledgement equivalent to the following:
38 "This product includes software developed by the Egothor Project.
39 http://egothor.sf.net/"
41 THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
42 WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
43 MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
44 IN NO EVENT SHALL THE EGOTHOR PROJECT OR ITS CONTRIBUTORS BE LIABLE
45 FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
46 CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
47 SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
48 BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
49 WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
50 OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
51 IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
53 This software consists of voluntary contributions made by many
54 individuals on behalf of the Egothor Project and was originally
55 created by Leo Galambos (Leo.G@seznam.cz).
58 import org.apache.lucene.util.LuceneTestCase;
60 public class TestStemmer extends LuceneTestCase {
62 public void testTrie() {
63 Trie t = new Trie(true);
65 String keys[] = {"a", "ba", "bb", "c"};
66 String vals[] = {"1", "2", "2", "4"};
68 for (int i = 0; i < keys.length; i++) {
69 t.add(keys[i], vals[i]);
72 assertEquals(0, t.root);
73 assertEquals(2, t.rows.size());
74 assertEquals(3, t.cmds.size());
75 assertTrieContents(t, keys, vals);
78 public void testTrieBackwards() {
79 Trie t = new Trie(false);
81 String keys[] = {"a", "ba", "bb", "c"};
82 String vals[] = {"1", "2", "2", "4"};
84 for (int i = 0; i < keys.length; i++) {
85 t.add(keys[i], vals[i]);
88 assertTrieContents(t, keys, vals);
91 public void testMultiTrie() {
92 Trie t = new MultiTrie(true);
94 String keys[] = {"a", "ba", "bb", "c"};
95 String vals[] = {"1", "2", "2", "4"};
97 for (int i = 0; i < keys.length; i++) {
98 t.add(keys[i], vals[i]);
101 assertTrieContents(t, keys, vals);
104 public void testMultiTrieBackwards() {
105 Trie t = new MultiTrie(false);
107 String keys[] = {"a", "ba", "bb", "c"};
108 String vals[] = {"1", "2", "2", "4"};
110 for (int i = 0; i < keys.length; i++) {
111 t.add(keys[i], vals[i]);
114 assertTrieContents(t, keys, vals);
117 public void testMultiTrie2() {
118 Trie t = new MultiTrie2(true);
120 String keys[] = {"a", "ba", "bb", "c"};
122 * short vals won't work, see line 155 for example
123 * the IOOBE is caught (wierd), but shouldnt affect patch cmds?
125 String vals[] = {"1111", "2222", "2223", "4444"};
127 for (int i = 0; i < keys.length; i++) {
128 t.add(keys[i], vals[i]);
131 assertTrieContents(t, keys, vals);
134 public void testMultiTrie2Backwards() {
135 Trie t = new MultiTrie2(false);
137 String keys[] = {"a", "ba", "bb", "c"};
139 * short vals won't work, see line 155 for example
140 * the IOOBE is caught (wierd), but shouldnt affect patch cmds?
142 String vals[] = {"1111", "2222", "2223", "4444"};
144 for (int i = 0; i < keys.length; i++) {
145 t.add(keys[i], vals[i]);
148 assertTrieContents(t, keys, vals);
151 private static void assertTrieContents(Trie trie, String keys[], String vals[]) {
152 Trie[] tries = new Trie[] {
154 trie.reduce(new Optimizer()),
155 trie.reduce(new Optimizer2()),
156 trie.reduce(new Gener()),
157 trie.reduce(new Lift(true)),
158 trie.reduce(new Lift(false))
161 for (Trie t : tries) {
162 for (int i = 0; i < keys.length; i++) {
163 assertEquals(vals[i], t.getFully(keys[i]).toString());
164 assertEquals(vals[i], t.getLastOnPath(keys[i]).toString());