Lucene.Net  3.0.3
Lucene.Net is a .NET port of the Java Lucene Indexing Library
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Properties
GermanStemFilter.cs
Go to the documentation of this file.
1 /*
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements. See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership. The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License. You may obtain a copy of the License at
10  *
11  * http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied. See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20 */
21 
22 using System;
23 using System.Collections.Generic;
24 using System.IO;
25 using System.Collections;
26 using Lucene.Net.Analysis.Tokenattributes;
27 
28 namespace Lucene.Net.Analysis.De
29 {
35  public sealed class GermanStemFilter : TokenFilter
36  {
40  private GermanStemmer stemmer = null;
41  private ISet<string> exclusionSet = null;
42 
43  private ITermAttribute termAtt;
44 
46  : this(_in, false)
47  { }
48 
49  public GermanStemFilter(TokenStream _in, bool useDin2Stemmer)
50  : this(_in, null, useDin2Stemmer)
51  { }
52 
58  public GermanStemFilter(TokenStream _in, ISet<string> exclusiontable)
59  : this(_in, exclusiontable, false)
60  { }
61 
70  public GermanStemFilter(TokenStream _in, ISet<string> exclusiontable, bool normalizeDin2)
71  : base(_in)
72  {
73  exclusionSet = exclusiontable;
74  stemmer = normalizeDin2 ? new GermanDIN2Stemmer() : new GermanStemmer();
75  termAtt = AddAttribute<ITermAttribute>();
76  }
77 
81  public override bool IncrementToken()
82  {
83  if (input.IncrementToken())
84  {
85  String term = termAtt.Term;
86  // Check the exclusion table.
87  if (exclusionSet == null || !exclusionSet.Contains(term))
88  {
89  String s = stemmer.Stem(term);
90  // If not stemmed, don't waste the time adjusting the token.
91  if ((s != null) && !s.Equals(term))
92  termAtt.SetTermBuffer(s);
93  }
94  return true;
95  }
96  else
97  {
98  return false;
99  }
100  }
101 
106  public void SetStemmer(GermanStemmer stemmer)
107  {
108  if (stemmer != null)
109  {
110  this.stemmer = stemmer;
111  }
112  }
113 
118  public void SetExclusionTable(ISet<string> exclusiontable)
119  {
120  exclusionSet = exclusiontable;
121  }
122  }
123 }