KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > lucene > analysis > br > BrazilianStemFilter


1 package org.apache.lucene.analysis.br;
2
3 /**
4  * Copyright 2004-2005 The Apache Software Foundation
5  *
6  * Licensed under the Apache License, Version 2.0 (the "License");
7  * you may not use this file except in compliance with the License.
8  * You may obtain a copy of the License at
9  *
10  * http://www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing, software
13  * distributed under the License is distributed on an "AS IS" BASIS,
14  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15  * See the License for the specific language governing permissions and
16  * limitations under the License.
17  */

18
19 import org.apache.lucene.analysis.Token;
20 import org.apache.lucene.analysis.TokenFilter;
21 import org.apache.lucene.analysis.TokenStream;
22
23 import java.io.IOException JavaDoc;
24 import java.util.HashSet JavaDoc;
25 import java.util.Hashtable JavaDoc;
26 import java.util.Set JavaDoc;
27
28 /**
29  * Based on GermanStemFilter
30  *
31  * @author João Kramer
32  */

33 public final class BrazilianStemFilter extends TokenFilter {
34
35   /**
36    * The actual token in the input stream.
37    */

38   private Token token = null;
39   private BrazilianStemmer stemmer = null;
40   private Set JavaDoc exclusions = null;
41
42   public BrazilianStemFilter(TokenStream in) {
43     super(in);
44     stemmer = new BrazilianStemmer();
45   }
46
47   /**
48    * Builds a BrazilianStemFilter that uses an exclusiontable.
49    *
50    * @deprecated
51    */

52   public BrazilianStemFilter(TokenStream in, Hashtable JavaDoc exclusiontable) {
53     this(in);
54     this.exclusions = new HashSet JavaDoc(exclusiontable.keySet());
55   }
56
57   public BrazilianStemFilter(TokenStream in, Set JavaDoc exclusiontable) {
58     this(in);
59     this.exclusions = exclusiontable;
60   }
61
62   /**
63    * @return Returns the next token in the stream, or null at EOS.
64    */

65   public final Token next()
66       throws IOException JavaDoc {
67     if ((token = input.next()) == null) {
68       return null;
69     }
70     // Check the exclusiontable.
71
else if (exclusions != null && exclusions.contains(token.termText())) {
72       return token;
73     } else {
74       String JavaDoc s = stemmer.stem(token.termText());
75       // If not stemmed, dont waste the time creating a new token.
76
if ((s != null) && !s.equals(token.termText())) {
77         return new Token(s, token.startOffset(), token.endOffset(), token.type());
78       }
79       return token;
80     }
81   }
82 }
83
84
85
Popular Tags