source: trunk/gsdl/packages/kea/kea-3.0/IteratedLovinsStemmer.java@ 8815

Last change on this file since 8815 was 8815, checked in by mdewsnip, 19 years ago

Kea 3.0, as downloaded from http://www.nzdl.org/kea but with CSTR_abstracts_test, CSTR_abstracts_train, Chinese_test, and Chinese_train directories removed.

  • Property svn:keywords set to Author Date Id Revision
File size: 2.0 KB
Line 
1/*
2 * IteratedLovinsStemmer.java
3 * Copyright (C) 2001 Eibe Frank
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
18 */
19
20import java.util.*;
21
22/**
23 * Implements the iterated version of the Lovins stemmer.
24 *
25 * @author Eibe Frank ([email protected])
26 * @version 1.0
27 */
28public class IteratedLovinsStemmer extends LovinsStemmer {
29
30 /**
31 * Iterated stemming of the given word.
32 */
33 public String stem(String str) {
34
35 if (str.length() <= 2) {
36 return str;
37 }
38 String stemmed = super.stem(str);
39 while (!stemmed.equals(str)) {
40 str = stemmed;
41 stemmed = super.stem(stemmed);
42 }
43 return stemmed;
44 }
45
46 /**
47 * Stems text coming into stdin and writes it to stdout.
48 */
49 public static void main(String[] ops) {
50
51 IteratedLovinsStemmer ls = new IteratedLovinsStemmer();
52
53 try {
54 int num;
55 StringBuffer wordBuffer = new StringBuffer();
56 while ((num = System.in.read()) != -1) {
57 char c = (char)num;
58 if (((num >= (int)'A') && (num <= (int)'Z')) ||
59 ((num >= (int)'a') && (num <= (int)'z'))) {
60 wordBuffer.append(c);
61 } else {
62 if (wordBuffer.length() > 0) {
63 System.out.print(ls.stem(wordBuffer.toString().
64 toLowerCase()));
65 wordBuffer = new StringBuffer();
66 }
67 System.out.print(c);
68 }
69 }
70 } catch (Exception e) {
71 System.err.println(e.getMessage());
72 }
73 }
74}
75
76
Note: See TracBrowser for help on using the repository browser.