19 using System.Collections;
21 using Lucene.Net.Analysis;
22 using Lucene.Net.Analysis.Tokenattributes;
23 using Lucene.Net.Util;
25 namespace Lucene.Net.Analysis.NGram
38 public static int DEFAULT_MAX_GRAM_SIZE = 1;
39 public static int DEFAULT_MIN_GRAM_SIZE = 1;
51 private bool started =
false;
67 init(side, minGram, maxGram);
83 init(side, minGram, maxGram);
96 : base(factory, input)
99 init(side, minGram, maxGram);
111 : this(input, SideExtensions.GetSide(sideLabel), minGram, maxGram)
126 : this(source, input, SideExtensions.GetSide(sideLabel), minGram, maxGram)
141 this(factory, input, SideExtensions.GetSide(sideLabel), minGram, maxGram)
145 private void init(
Side side,
int minGram,
int maxGram)
149 throw new System.ArgumentException(
"sideLabel must be either front or back");
154 throw new System.ArgumentException(
"minGram must be greater than zero");
157 if (minGram > maxGram)
159 throw new System.ArgumentException(
"minGram must not be greater than maxGram");
162 this.minGram = minGram;
163 this.maxGram = maxGram;
166 this.termAtt = AddAttribute<ITermAttribute>();
167 this.offsetAtt = AddAttribute<IOffsetAttribute>();
172 public override bool IncrementToken()
179 char[] chars =
new char[1024];
180 inStr = input.ReadToEnd().Trim();
181 inLen = inStr.Length;
186 if (gramSize > inLen)
192 if (gramSize > maxGram)
198 int start = side ==
Side.FRONT ? 0 : inLen - gramSize;
199 int end = start + gramSize;
200 termAtt.SetTermBuffer(inStr, start, gramSize);
201 offsetAtt.SetOffset(CorrectOffset(start), CorrectOffset(end));
206 public override void End()
209 int finalOffset = inLen;
210 this.offsetAtt.SetOffset(finalOffset, finalOffset);
213 public override void Reset(TextReader input)
219 public override void Reset()