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
33 public static int DEFAULT_MIN_NGRAM_SIZE = 1;
34 public static int DEFAULT_MAX_NGRAM_SIZE = 2;
36 private int minGram, maxGram;
41 private bool started =
false;
55 init(minGram, maxGram);
68 init(minGram, maxGram);
79 : base(factory, input)
81 init(minGram, maxGram);
89 : this(input, DEFAULT_MIN_NGRAM_SIZE, DEFAULT_MAX_NGRAM_SIZE)
94 private void init(
int minGram,
int maxGram)
98 throw new System.ArgumentException(
"minGram must be greater than zero");
100 if (minGram > maxGram)
102 throw new System.ArgumentException(
"minGram must not be greater than maxGram");
104 this.minGram = minGram;
105 this.maxGram = maxGram;
107 this.termAtt = AddAttribute<ITermAttribute>();
108 this.offsetAtt = AddAttribute<IOffsetAttribute>();
112 public override bool IncrementToken()
119 char[] chars =
new char[1024];
120 inStr = input.ReadToEnd();
121 inLen = inStr.Length;
124 if (pos + gramSize > inLen)
128 if (gramSize > maxGram)
130 if (pos + gramSize > inLen)
136 termAtt.SetTermBuffer(inStr, oldPos, gramSize);
137 offsetAtt.SetOffset(CorrectOffset(oldPos), CorrectOffset(oldPos + gramSize));
141 public override void End()
144 int finalOffset = inLen;
145 this.offsetAtt.SetOffset(finalOffset, finalOffset);
148 public override void Reset(TextReader input)
154 public override void Reset()