Thumbnail file hits. Based on a patch from D Bera
[beagle.git] / beagled / Lucene.Net / Analysis / DE / GermanStemFilter.cs
blobc7df6730263d8eeaa54e0724399a7d8f4374ada3
1 /*
2 * Copyright 2004 The Apache Software Foundation
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
16 using System;
17 using Token = Lucene.Net.Analysis.Token;
18 using TokenFilter = Lucene.Net.Analysis.TokenFilter;
19 using TokenStream = Lucene.Net.Analysis.TokenStream;
20 namespace Lucene.Net.Analysis.DE
23 /// <summary> A filter that stems German words. It supports a table of words that should
24 /// not be stemmed at all. The stemmer used can be changed at runtime after the
25 /// filter object is created (as long as it is a GermanStemmer).
26 ///
27 /// </summary>
28 /// <author> Gerhard Schwarz
29 /// </author>
30 /// <version> $Id: GermanStemFilter.cs,v 1.2 2005/01/17 19:54:27 joeshaw Exp $
31 /// </version>
32 public sealed class GermanStemFilter : TokenFilter
34 /// <summary> The actual token in the input stream.</summary>
35 private Token token = null;
36 private GermanStemmer stemmer = null;
37 private System.Collections.Hashtable exclusionSet = null;
39 public GermanStemFilter(TokenStream in_Renamed) : base(in_Renamed)
41 stemmer = new GermanStemmer();
44 /// <summary> Builds a GermanStemFilter that uses an exclusiontable.</summary>
45 /// <deprecated> Use {@link #GermanStemFilter(Lucene.Net.Analysis.TokenStream, java.util.Set)} instead.
46 /// </deprecated>
47 public GermanStemFilter(TokenStream in_Renamed, System.Collections.Hashtable exclusiontable):this(in_Renamed)
49 exclusionSet = new System.Collections.Hashtable(new System.Collections.Hashtable(exclusiontable));
52 /// <returns> Returns the next token in the stream, or null at EOS
53 /// </returns>
54 public override Token Next()
56 if ((token = input.Next()) == null)
58 return null;
60 // Check the exclusiontable
61 else if (exclusionSet != null && exclusionSet.Contains(token.TermText()))
63 return token;
65 else
67 System.String s = stemmer.Stem(token.TermText());
68 // If not stemmed, dont waste the time creating a new token
69 if (!s.Equals(token.TermText()))
71 return new Token(s, token.StartOffset(), token.EndOffset(), token.Type());
73 return token;
77 /// <summary> Set a alternative/custom GermanStemmer for this filter.</summary>
78 public void SetStemmer(GermanStemmer stemmer)
80 if (stemmer != null)
82 this.stemmer = stemmer;
86 /// <summary> Set an alternative exclusion list for this filter.</summary>
87 /// <deprecated> Use {@link #SetExclusionSet(java.util.Set)} instead.
88 /// </deprecated>
89 public void SetExclusionTable(System.Collections.Hashtable exclusiontable)
91 exclusionSet = new System.Collections.Hashtable(new System.Collections.Hashtable(exclusiontable));
94 /// <summary> Set an alternative exclusion list for this filter.</summary>
95 public void SetExclusionSet(System.Collections.Hashtable exclusionSet)
97 this.exclusionSet = exclusionSet;