1 package org.apache.lucene.analysis.nl; 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.HashMap ; 25 import java.util.HashSet ; 26 import java.util.Set ; 27 import java.util.Map ; 28 29 36 public final class DutchStemFilter extends TokenFilter { 37 40 private Token token = null; 41 private DutchStemmer stemmer = null; 42 private Set exclusions = null; 43 44 public DutchStemFilter(TokenStream _in) { 45 super(_in); 46 stemmer = new DutchStemmer(); 47 } 48 49 52 public DutchStemFilter(TokenStream _in, Set exclusiontable) { 53 this(_in); 54 exclusions = exclusiontable; 55 } 56 57 60 public DutchStemFilter(TokenStream _in, Set exclusiontable, Map stemdictionary) { 61 this(_in, exclusiontable); 62 stemmer.setStemDictionary(stemdictionary); 63 } 64 65 68 public Token next() throws IOException { 69 if ((token = input.next()) == null) { 70 return null; 71 } 72 73 else if (exclusions != null && exclusions.contains(token.termText())) { 75 return token; 76 } else { 77 String s = stemmer.stem(token.termText()); 78 if (!s.equals(token.termText())) { 80 return new Token(s, token.startOffset(), 81 token.endOffset(), token.type()); 82 } 83 return token; 84 } 85 } 86 87 90 public void setStemmer(DutchStemmer stemmer) { 91 if (stemmer != null) { 92 this.stemmer = stemmer; 93 } 94 } 95 96 99 public void setExclusionTable(HashSet exclusiontable) { 100 exclusions = exclusiontable; 101 } 102 103 107 public void setStemDictionary(HashMap dict) { 108 if (stemmer != null) 109 stemmer.setStemDictionary(dict); 110 } 111 } | Popular Tags |