~ubuntu-branches/ubuntu/precise/weka/precise

« back to all changes in this revision

Viewing changes to weka/core/stemmers/IteratedLovinsStemmer.java

  • Committer: Bazaar Package Importer
  • Author(s): Soeren Sonnenburg
  • Date: 2008-02-24 09:18:45 UTC
  • Revision ID: james.westby@ubuntu.com-20080224091845-1l8zy6fm6xipbzsr
Tags: upstream-3.5.7+tut1
ImportĀ upstreamĀ versionĀ 3.5.7+tut1

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 *    This program is free software; you can redistribute it and/or modify
 
3
 *    it under the terms of the GNU General Public License as published by
 
4
 *    the Free Software Foundation; either version 2 of the License, or
 
5
 *    (at your option) any later version.
 
6
 *
 
7
 *    This program is distributed in the hope that it will be useful,
 
8
 *    but WITHOUT ANY WARRANTY; without even the implied warranty of
 
9
 *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
10
 *    GNU General Public License for more details.
 
11
 *
 
12
 *    You should have received a copy of the GNU General Public License
 
13
 *    along with this program; if not, write to the Free Software
 
14
 *    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
 
15
 */
 
16
 
 
17
/*
 
18
 * IteratedLovinsStemmer.java
 
19
 * Copyright (C) 2001 University of Waikato, Hamilton, New Zealand
 
20
 *
 
21
 */
 
22
 
 
23
package weka.core.stemmers;
 
24
 
 
25
/**
 
26
 <!-- globalinfo-start -->
 
27
 * An iterated version of the Lovins stemmer. It stems the word (in case it's longer than 2 characters) until it no further changes.<br/>
 
28
 * <br/>
 
29
 * For more information about the Lovins stemmer see:<br/>
 
30
 * <br/>
 
31
 * Julie Beth Lovins (1968). Development of a stemming algorithm. Mechanical Translation and Computational Linguistics. 11:22-31.
 
32
 * <p/>
 
33
 <!-- globalinfo-end -->
 
34
 * 
 
35
 <!-- technical-bibtex-start -->
 
36
 * BibTeX:
 
37
 * <pre>
 
38
 * &#64;article{Lovins1968,
 
39
 *    author = {Julie Beth Lovins},
 
40
 *    journal = {Mechanical Translation and Computational Linguistics},
 
41
 *    pages = {22-31},
 
42
 *    title = {Development of a stemming algorithm},
 
43
 *    volume = {11},
 
44
 *    year = {1968}
 
45
 * }
 
46
 * </pre>
 
47
 * <p/>
 
48
 <!-- technical-bibtex-end -->
 
49
 *
 
50
 * @author  Eibe Frank (eibe at cs dot waikato dot ac dot nz)
 
51
 * @version $Revision: 1.6 $
 
52
 * @see     LovinsStemmer
 
53
 */
 
54
public class IteratedLovinsStemmer 
 
55
  extends LovinsStemmer {
 
56
 
 
57
  /** for serialization */
 
58
  static final long serialVersionUID = 960689687163788264L;
 
59
  
 
60
  /**
 
61
   * Returns a string describing the stemmer
 
62
   * @return a description suitable for
 
63
   *         displaying in the explorer/experimenter gui
 
64
   */
 
65
  public String globalInfo() {
 
66
    return 
 
67
        "An iterated version of the Lovins stemmer. It stems the word (in "
 
68
      + "case it's longer than 2 characters) until it no further changes.\n\n"
 
69
      + "For more information about the Lovins stemmer see:\n\n"
 
70
      + getTechnicalInformation().toString();
 
71
  }
 
72
 
 
73
  /**
 
74
   * Iterated stemming of the given word.
 
75
   * Word is converted to lower case.
 
76
   * 
 
77
   * @param str         the word to stem
 
78
   * @return            the stemmed word
 
79
   */
 
80
  public String stem(String str) {
 
81
 
 
82
    if (str.length() <= 2) {
 
83
      return str;
 
84
    }
 
85
    String stemmed = super.stem(str);
 
86
    while (!stemmed.equals(str)) {
 
87
      str = stemmed;
 
88
      stemmed = super.stem(stemmed);
 
89
    }
 
90
    return stemmed;
 
91
  }
 
92
 
 
93
  /**
 
94
   * Runs the stemmer with the given options
 
95
   *
 
96
   * @param args      the options
 
97
   */
 
98
  public static void main(String[] args) {
 
99
    try {
 
100
      Stemming.useStemmer(new IteratedLovinsStemmer(), args);
 
101
    }
 
102
    catch (Exception e) {
 
103
      e.printStackTrace();
 
104
    }
 
105
  }
 
106
}
 
107