Esempio n. 1
0
 public override bool incrementToken()
 {
     while (true)
     {
         if (curTermBuffer == null)
         {
             if (!input.incrementToken())
             {
                 return(false);
             }
             else
             {
                 curTermBuffer = (char[])termAtt.termBuffer().Clone();
                 curTermLength = termAtt.termLength();
                 curGramSize   = minGram;
                 tokStart      = offsetAtt.startOffset();
             }
         }
         if (curGramSize <= maxGram)
         {
             if (!(curGramSize > curTermLength || // if the remaining input is too short, we can't generate any n-grams
                   curGramSize > maxGram))
             {                                    // if we have hit the end of our n-gram size range, quit
                 // grab gramSize chars from front or back
                 int start = side == Side.FRONT ? 0 : curTermLength - curGramSize;
                 int end   = start + curGramSize;
                 clearAttributes();
                 offsetAtt.setOffset(tokStart + start, tokStart + end);
                 termAtt.setTermBuffer(curTermBuffer, start, curGramSize);
                 curGramSize++;
                 return(true);
             }
         }
         curTermBuffer = null;
     }
 }