source: branches/MetisMQI/src/main/java/weka/core/stemmers/IteratedLovinsStemmer.java

Last change on this file was 29, checked in by gnappo, 15 years ago

Taggata versione per la demo e aggiunto branch.

File size: 3.2 KB
Line 
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
23package weka.core.stemmers;
24
25import weka.core.RevisionUtils;
26
27/**
28 <!-- globalinfo-start -->
29 * 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/>
30 * <br/>
31 * For more information about the Lovins stemmer see:<br/>
32 * <br/>
33 * Julie Beth Lovins (1968). Development of a stemming algorithm. Mechanical Translation and Computational Linguistics. 11:22-31.
34 * <p/>
35 <!-- globalinfo-end -->
36 *
37 <!-- technical-bibtex-start -->
38 * BibTeX:
39 * <pre>
40 * &#64;article{Lovins1968,
41 *    author = {Julie Beth Lovins},
42 *    journal = {Mechanical Translation and Computational Linguistics},
43 *    pages = {22-31},
44 *    title = {Development of a stemming algorithm},
45 *    volume = {11},
46 *    year = {1968}
47 * }
48 * </pre>
49 * <p/>
50 <!-- technical-bibtex-end -->
51 *
52 * @author  Eibe Frank (eibe at cs dot waikato dot ac dot nz)
53 * @version $Revision: 5953 $
54 * @see     LovinsStemmer
55 */
56public class IteratedLovinsStemmer 
57  extends LovinsStemmer {
58
59  /** for serialization */
60  static final long serialVersionUID = 960689687163788264L;
61 
62  /**
63   * Returns a string describing the stemmer
64   * @return a description suitable for
65   *         displaying in the explorer/experimenter gui
66   */
67  public String globalInfo() {
68    return 
69        "An iterated version of the Lovins stemmer. It stems the word (in "
70      + "case it's longer than 2 characters) until it no further changes.\n\n"
71      + "For more information about the Lovins stemmer see:\n\n"
72      + getTechnicalInformation().toString();
73  }
74
75  /**
76   * Iterated stemming of the given word.
77   * Word is converted to lower case.
78   *
79   * @param str         the word to stem
80   * @return            the stemmed word
81   */
82  public String stem(String str) {
83
84    if (str.length() <= 2) {
85      return str;
86    }
87    String stemmed = super.stem(str);
88    while (!stemmed.equals(str)) {
89      str = stemmed;
90      stemmed = super.stem(stemmed);
91    }
92    return stemmed;
93  }
94 
95  /**
96   * Returns the revision string.
97   *
98   * @return            the revision
99   */
100  public String getRevision() {
101    return RevisionUtils.extract("$Revision: 5953 $");
102  }
103
104  /**
105   * Runs the stemmer with the given options
106   *
107   * @param args      the options
108   */
109  public static void main(String[] args) {
110    try {
111      Stemming.useStemmer(new IteratedLovinsStemmer(), args);
112    }
113    catch (Exception e) {
114      e.printStackTrace();
115    }
116  }
117}
118
Note: See TracBrowser for help on using the repository browser.