1 package org.apache.lucene.analysis.br; 2 3 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 ; 24 import java.util.HashSet ; 25 import java.util.Hashtable ; 26 import java.util.Set ; 27 28 33 public final class BrazilianStemFilter extends TokenFilter { 34 35 38 private Token token = null; 39 private BrazilianStemmer stemmer = null; 40 private Set exclusions = null; 41 42 public BrazilianStemFilter(TokenStream in) { 43 super(in); 44 stemmer = new BrazilianStemmer(); 45 } 46 47 52 public BrazilianStemFilter(TokenStream in, Hashtable exclusiontable) { 53 this(in); 54 this.exclusions = new HashSet (exclusiontable.keySet()); 55 } 56 57 public BrazilianStemFilter(TokenStream in, Set exclusiontable) { 58 this(in); 59 this.exclusions = exclusiontable; 60 } 61 62 65 public final Token next() 66 throws IOException { 67 if ((token = input.next()) == null) { 68 return null; 69 } 70 else if (exclusions != null && exclusions.contains(token.termText())) { 72 return token; 73 } else { 74 String s = stemmer.stem(token.termText()); 75 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 |