Exemplo n.º 1
0
        //JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET:
        //ORIGINAL LINE: @Override public boolean incrementToken() throws java.io.IOException
        public override bool incrementToken()
        {
            if (hasMoreTokensInClone)
            {
              int start = breaker.current();
              int end = breaker.next();
              if (end != BreakIterator.DONE)
              {
            clonedToken.copyTo(this);
            termAtt.copyBuffer(clonedTermAtt.buffer(), start, end - start);
            if (hasIllegalOffsets)
            {
              offsetAtt.setOffset(clonedOffsetAtt.startOffset(), clonedOffsetAtt.endOffset());
            }
            else
            {
              offsetAtt.setOffset(clonedOffsetAtt.startOffset() + start, clonedOffsetAtt.startOffset() + end);
            }
            if (handlePosIncr)
            {
                posAtt.PositionIncrement = 1;
            }
            return true;
              }
              hasMoreTokensInClone = false;
            }

            if (!input.incrementToken())
            {
              return false;
            }

            if (termAtt.length() == 0 || char.UnicodeBlock.of(termAtt.charAt(0)) != char.UnicodeBlock.THAI)
            {
              return true;
            }

            hasMoreTokensInClone = true;

            // if length by start + end offsets doesn't match the term text then assume
            // this is a synonym and don't adjust the offsets.
            hasIllegalOffsets = offsetAtt.endOffset() - offsetAtt.startOffset() != termAtt.length();

            // we lazy init the cloned token, as in ctor not all attributes may be added
            if (clonedToken == null)
            {
              clonedToken = cloneAttributes();
              clonedTermAtt = clonedToken.getAttribute(typeof(CharTermAttribute));
              clonedOffsetAtt = clonedToken.getAttribute(typeof(OffsetAttribute));
            }
            else
            {
              this.copyTo(clonedToken);
            }

            // reinit CharacterIterator
            charIterator.setText(clonedTermAtt.buffer(), 0, clonedTermAtt.length());
            breaker.Text = charIterator;
            int end = breaker.next();
            if (end != BreakIterator.DONE)
            {
              termAtt.Length = end;
              if (hasIllegalOffsets)
              {
            offsetAtt.setOffset(clonedOffsetAtt.startOffset(), clonedOffsetAtt.endOffset());
              }
              else
              {
            offsetAtt.setOffset(clonedOffsetAtt.startOffset(), clonedOffsetAtt.startOffset() + end);
              }
              // position increment keeps as it is for first token
              return true;
            }
            return false;
        }
Exemplo n.º 2
0
 public override bool accept(AttributeSource a)
 {
     CharTermAttribute termAtt = a.getAttribute(typeof(CharTermAttribute));
     return termAtt.ToString().Equals("Dogs", StringComparison.CurrentCultureIgnoreCase);
 }