示例#1
0
  private boolean verifyPushBack(int current, int next) {
    int shortenedSyllable = next - current - 1;

    verifyText.setText(text.getText(), text.getStart() + current, shortenedSyllable);
    verify.setText(verifyText);
    if (verify.next() != shortenedSyllable || verify.getRuleStatus() == 0) return false;

    verifyText.setText(text.getText(), text.getStart() + next - 1, text.getLength() - next + 1);
    verify.setText(verifyText);

    return (verify.next() != BreakIterator.DONE && verify.getRuleStatus() != 0);
  }
示例#2
0
  private void doMultipleSelectionTest(RuleBasedBreakIterator iterator, String testText) {
    logln("Multiple selection test...");
    RuleBasedBreakIterator testIterator = (RuleBasedBreakIterator) iterator.clone();
    int offset = iterator.first();
    int testOffset;
    int count = 0;

    do {
      testOffset = testIterator.first();
      testOffset = testIterator.next(count);
      logln("next(" + count + ") -> " + testOffset);
      if (offset != testOffset)
        errln(
            "next(n) and next() not returning consistent results: for step "
                + count
                + ", next(n) returned "
                + testOffset
                + " and next() had "
                + offset);

      if (offset != RuleBasedBreakIterator.DONE) {
        count++;
        offset = iterator.next();
      }
    } while (offset != RuleBasedBreakIterator.DONE);

    // now do it backwards...
    offset = iterator.last();
    count = 0;

    do {
      testOffset = testIterator.last();
      testOffset = testIterator.next(count);
      logln("next(" + count + ") -> " + testOffset);
      if (offset != testOffset)
        errln(
            "next(n) and next() not returning consistent results: for step "
                + count
                + ", next(n) returned "
                + testOffset
                + " and next() had "
                + offset);

      if (offset != RuleBasedBreakIterator.DONE) {
        count--;
        offset = iterator.previous();
      }
    } while (offset != RuleBasedBreakIterator.DONE);
  }
示例#3
0
  private List<String> _testFirstAndNext(RuleBasedBreakIterator rbbi, String text) {
    int p = rbbi.first();
    int lastP = p;
    List<String> result = new ArrayList<String>();

    if (p != 0) {
      errln("first() returned " + p + " instead of 0");
    }

    while (p != RuleBasedBreakIterator.DONE) {
      p = rbbi.next();
      if (p != RuleBasedBreakIterator.DONE) {
        if (p <= lastP) {
          errln("next() failed to move forward: next() on position " + lastP + " yielded " + p);
        }
        result.add(text.substring(lastP, p));
      } else {
        if (lastP != text.length()) {
          errln(
              "next() returned DONE prematurely: offset was "
                  + lastP
                  + " instead of "
                  + text.length());
        }
      }
      lastP = p;
    }
    return result;
  }
示例#4
0
  /*
   * Tests the method public int first()
   */
  public void TestFirst() {
    RuleBasedBreakIterator rbbi = new RuleBasedBreakIterator(".;");
    // Tests when "if (fText == null)" is true
    rbbi.setText((CharacterIterator) null);
    assertEquals("RuleBasedBreakIterator.first()", BreakIterator.DONE, rbbi.first());

    rbbi.setText("abc");
    assertEquals("RuleBasedBreakIterator.first()", 0, rbbi.first());
    assertEquals("RuleBasedBreakIterator.next()", 1, rbbi.next());
  }
示例#5
0
  @Override
  public int next() {
    int current = current();
    int next = rules.next();
    if (next == BreakIterator.DONE) return next;
    else next += workingOffset;

    char c = working.current();
    int following = rules.next(); // lookahead
    if (following != BreakIterator.DONE) {
      following += workingOffset;
      if (rules.getRuleStatus() == 0 && laoSet.contains(c) && verifyPushBack(current, next)) {
        workingOffset = next - 1;
        working.setText(
            text.getText(), text.getStart() + workingOffset, text.getLength() - workingOffset);
        return next - 1;
      }
      rules.previous(); // undo the lookahead
    }

    return next;
  }
示例#6
0
  @Override
  public Lexem lexer_next() {

    end = iterator.next();
    if (end == BreakIterator.DONE) return null;

    if (start >= end) return null;

    int lexemId = iterator.getRuleStatus();
    Lexem lexem = new Lexem(lexemId, text.substring(start, end), start, end);

    // System.out.println(lexem.toString());
    start = end; // Prepare for the next iteration

    return lexem;
  }