1 package org.apache.lucene.analysis.de; 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.Set ; 25 import java.util.HashSet ; 26 27 35 public final class GermanStemFilter extends TokenFilter 36 { 37 40 private Token token = null; 41 private GermanStemmer stemmer = null; 42 private Set exclusionSet = null; 43 44 public GermanStemFilter( TokenStream in ) 45 { 46 super(in); 47 stemmer = new GermanStemmer(); 48 } 49 50 54 public GermanStemFilter( TokenStream in, Hashtable exclusiontable ) 55 { 56 this( in ); 57 exclusionSet = new HashSet (exclusiontable.keySet()); 58 } 59 60 63 public GermanStemFilter( TokenStream in, Set exclusionSet ) 64 { 65 this( in ); 66 this.exclusionSet = exclusionSet; 67 } 68 69 72 public final Token next() 73 throws IOException 74 { 75 if ( ( token = input.next() ) == null ) { 76 return null; 77 } 78 else if ( exclusionSet != null && exclusionSet.contains( token.termText() ) ) { 80 return token; 81 } 82 else { 83 String s = stemmer.stem( token.termText() ); 84 if ( !s.equals( token.termText() ) ) { 86 return new Token( s, token.startOffset(), 87 token.endOffset(), token.type() ); 88 } 89 return token; 90 } 91 } 92 93 96 public void setStemmer( GermanStemmer stemmer ) 97 { 98 if ( stemmer != null ) { 99 this.stemmer = stemmer; 100 } 101 } 102 103 107 public void setExclusionTable( Hashtable exclusiontable ) 108 { 109 exclusionSet = new HashSet (exclusiontable.keySet()); 110 } 111 112 115 public void setExclusionSet( Set exclusionSet ) 116 { 117 this.exclusionSet = exclusionSet; 118 } 119 } 120 | Popular Tags |