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.io.DataInput;
58 import java.io.DataOutput;
59 import java.io.IOException;
60 import java.util.Iterator;
61 import java.util.TreeMap;
64 * The Row class represents a row in a matrix representation of a trie.
67 TreeMap<Character,Cell> cells = new TreeMap<Character,Cell>();
72 * Construct a Row object from input carried in via the given input stream.
74 * @param is the input stream
75 * @exception IOException if an I/O error occurs
77 public Row(DataInput is) throws IOException {
78 for (int i = is.readInt(); i > 0; i--) {
79 char ch = is.readChar();
84 c.skip = is.readInt();
90 * The default constructor for the Row object.
95 * Construct a Row using the cells of the given Row.
97 * @param old the Row to copy
104 * Set the command in the Cell of the given Character to the given integer.
106 * @param way the Character defining the Cell
107 * @param cmd the new command
109 public void setCmd(Character way, int cmd) {
118 c.cnt = (cmd >= 0) ? 1 : 0;
122 * Set the reference to the next row in the Cell of the given Character to the
125 * @param way the Character defining the Cell
126 * @param ref The new ref value
128 public void setRef(Character way, int ref) {
140 * Return the number of cells in use.
142 * @return the number of cells in use
144 public int getCells() {
145 Iterator<Character> i = cells.keySet().iterator();
147 for (; i.hasNext();) {
148 Character c = i.next();
150 if (e.cmd >= 0 || e.ref >= 0) {
158 * Return the number of references (how many transitions) to other rows.
160 * @return the number of references
162 public int getCellsPnt() {
163 Iterator<Character> i = cells.keySet().iterator();
165 for (; i.hasNext();) {
166 Character c = i.next();
176 * Return the number of patch commands saved in this Row.
178 * @return the number of patch commands
180 public int getCellsVal() {
181 Iterator<Character> i = cells.keySet().iterator();
183 for (; i.hasNext();) {
184 Character c = i.next();
194 * Return the command in the Cell associated with the given Character.
196 * @param way the Character associated with the Cell holding the desired
198 * @return the command
200 public int getCmd(Character way) {
202 return (c == null) ? -1 : c.cmd;
206 * Return the number of patch commands were in the Cell associated with the
207 * given Character before the Trie containing this Row was reduced.
209 * @param way the Character associated with the desired Cell
210 * @return the number of patch commands before reduction
212 public int getCnt(Character way) {
214 return (c == null) ? -1 : c.cnt;
218 * Return the reference to the next Row in the Cell associated with the given
221 * @param way the Character associated with the desired Cell
222 * @return the reference, or -1 if the Cell is <tt>null,/tt>
224 public int getRef(Character way) {
226 return (c == null) ? -1 : c.ref;
230 * Write the contents of this Row to the given output stream.
232 * @param os the output stream
233 * @exception IOException if an I/O error occurs
235 public void store(DataOutput os) throws IOException {
236 os.writeInt(cells.size());
237 Iterator<Character> i = cells.keySet().iterator();
238 for (; i.hasNext();) {
239 Character c = i.next();
241 if (e.cmd < 0 && e.ref < 0) {
245 os.writeChar(c.charValue());
254 * Return the number of identical Cells (containing patch commands) in this
257 * @param eqSkip when set to <tt>false</tt> the removed patch commands are
259 * @return the number of identical Cells, or -1 if there are (at least) two
262 public int uniformCmd(boolean eqSkip) {
263 Iterator<Cell> i = cells.values().iterator();
267 for (; i.hasNext();) {
275 uniformSkip = c.skip;
276 } else if (ret == c.cmd) {
278 if (uniformSkip == c.skip) {
295 * Write the contents of this Row to stdout.
297 public void print() {
298 for (Iterator<Character> i = cells.keySet().iterator(); i.hasNext();) {
299 Character ch = i.next();
301 System.out.print("[" + ch + ":" + c + "]");
303 System.out.println();
306 Cell at(Character index) {
307 return cells.get(index);