2 Egothor Software License version 1.00
3 Copyright (C) 1997-2004 Leo Galambos.
4 Copyright (C) 2002-2004 "Egothor developers"
5 on behalf of the Egothor Project.
8 This software is copyrighted by the "Egothor developers". If this
9 license applies to a single file or document, the "Egothor developers"
10 are the people or entities mentioned as copyright holders in that file
11 or document. If this license applies to the Egothor project as a
12 whole, the copyright holders are the people or entities mentioned in
13 the file CREDITS. This file can be found in the same location as this
14 license in the distribution.
16 Redistribution and use in source and binary forms, with or without
17 modification, are permitted provided that the following conditions are
19 1. Redistributions of source code must retain the above copyright
20 notice, the list of contributors, this list of conditions, and the
22 2. Redistributions in binary form must reproduce the above copyright
23 notice, the list of contributors, this list of conditions, and the
24 disclaimer that follows these conditions in the documentation
25 and/or other materials provided with the distribution.
26 3. The name "Egothor" must not be used to endorse or promote products
27 derived from this software without prior written permission. For
28 written permission, please contact Leo.G@seznam.cz
29 4. Products derived from this software may not be called "Egothor",
30 nor may "Egothor" appear in their name, without prior written
31 permission from Leo.G@seznam.cz.
33 In addition, we request that you include in the end-user documentation
34 provided with the redistribution and/or in the software itself an
35 acknowledgement equivalent to the following:
36 "This product includes software developed by the Egothor Project.
37 http://egothor.sf.net/"
39 THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
40 WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
41 MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
42 IN NO EVENT SHALL THE EGOTHOR PROJECT OR ITS CONTRIBUTORS BE LIABLE
43 FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
44 CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
45 SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
46 BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
47 WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
48 OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
49 IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
51 This software consists of voluntary contributions made by many
52 individuals on behalf of the Egothor Project and was originally
53 created by Leo Galambos (Leo.G@seznam.cz).
55 package org.egothor.stemmer;
57 import java.util.ArrayList;
58 import java.util.Arrays;
59 import java.util.Iterator;
60 import java.util.List;
63 * The Gener object helps in the discarding of nodes which break the reduction
64 * effort and defend the structure against large reductions.
66 public class Gener extends Reduce {
68 * Constructor for the Gener object.
73 * Return a Trie with infrequent values occurring in the given Trie removed.
75 * @param orig the Trie to optimize
76 * @return a new optimized Trie
79 public Trie optimize(Trie orig) {
80 List<CharSequence> cmds = orig.cmds;
81 List<Row> rows = new ArrayList<Row>();
82 List<Row> orows = orig.rows;
83 int remap[] = new int[orows.size()];
85 Arrays.fill(remap, 1);
86 for (int j = orows.size() - 1; j >= 0; j--) {
87 if (eat(orows.get(j), remap)) {
92 Arrays.fill(remap, -1);
93 rows = removeGaps(orig.root, orows, new ArrayList<Row>(), remap);
95 return new Trie(orig.forward, remap[orig.root], cmds, rows);
99 * Test whether the given Row of Cells in a Trie should be included in an
102 * @param in the Row to test
103 * @param remap Description of the Parameter
104 * @return <tt>true</tt> if the Row should remain, <tt>false
107 public boolean eat(Row in, int remap[]) {
109 for (Iterator<Cell> i = in.cells.values().iterator(); i.hasNext();) {
113 if (remap[c.ref] == 0) {
118 int frame = sum / 10;
119 boolean live = false;
120 for (Iterator<Cell> i = in.cells.values().iterator(); i.hasNext();) {
122 if (c.cnt < frame && c.cmd >= 0) {
126 if (c.cmd >= 0 || c.ref >= 0) {