1 package org.apache.lucene.analysis.fr; 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 import java.io.IOException ; 23 import java.util.Hashtable ; 24 import java.util.HashSet ; 25 import java.util.Set ; 26 27 34 public final class FrenchStemFilter extends TokenFilter { 35 36 39 private Token token = null; 40 private FrenchStemmer stemmer = null; 41 private Set exclusions = null; 42 43 public FrenchStemFilter( TokenStream in ) { 44 super(in); 45 stemmer = new FrenchStemmer(); 46 } 47 48 53 public FrenchStemFilter( TokenStream in, Hashtable exclusiontable ) { 54 this( in ); 55 exclusions = new HashSet (exclusiontable.keySet()); 56 } 57 58 public FrenchStemFilter( TokenStream in, Set exclusiontable ) { 59 this( in ); 60 exclusions = exclusiontable; 61 } 62 63 66 public final Token next() 67 throws IOException { 68 if ( ( token = input.next() ) == null ) { 69 return null; 70 } 71 else if ( exclusions != null && exclusions.contains( token.termText() ) ) { 73 return token; 74 } 75 else { 76 String s = stemmer.stem( token.termText() ); 77 if ( !s.equals( token.termText() ) ) { 79 return new Token( s, token.startOffset(), token.endOffset(), token.type()); 80 } 81 return token; 82 } 83 } 84 87 public void setStemmer( FrenchStemmer stemmer ) { 88 if ( stemmer != null ) { 89 this.stemmer = stemmer; 90 } 91 } 92 95 public void setExclusionTable( Hashtable exclusiontable ) { 96 exclusions = new HashSet (exclusiontable.keySet()); 97 } 98 } 99 100 101 | Popular Tags |