FileDocCategorySizeDatePackage
EdgeNGramTokenizerTest.javaAPI DocApache Lucene 2.2.03885Sat Jun 16 22:21:04 BST 2007org.apache.lucene.analysis.ngram

EdgeNGramTokenizerTest

public class EdgeNGramTokenizerTest extends TestCase
Tests {@link EdgeNGramTokenizer} for correctness.
author
Otis Gospodnetic

Fields Summary
private StringReader
input
Constructors Summary
Methods Summary
public voidsetUp()

    input = new StringReader("abcde");
  
public voidtestBackRangeOfNgrams()

    EdgeNGramTokenizer tokenizer = new EdgeNGramTokenizer(input, EdgeNGramTokenizer.Side.BACK, 1, 3);
    Token token = null;
    token = tokenizer.next();
    assertEquals("(e,4,5)", token.toString());
    token = tokenizer.next();
    assertEquals("(de,3,5)", token.toString());
    token = tokenizer.next();
    assertEquals("(cde,2,5)", token.toString());
    token = tokenizer.next();
    assertNull(token);
  
public voidtestBackUnigram()

    EdgeNGramTokenizer tokenizer = new EdgeNGramTokenizer(input, EdgeNGramTokenizer.Side.BACK, 1, 1);
    Token token = null;
    token = tokenizer.next();
    assertEquals("(e,4,5)", token.toString());
    token = tokenizer.next();
    assertNull(token);
  
public voidtestFrontRangeOfNgrams()

    EdgeNGramTokenizer tokenizer = new EdgeNGramTokenizer(input, EdgeNGramTokenizer.Side.FRONT, 1, 3);
    Token token = null;
    token = tokenizer.next();
    assertEquals("(a,0,1)", token.toString());
    token = tokenizer.next();
    assertEquals("(ab,0,2)", token.toString());
    token = tokenizer.next();
    assertEquals("(abc,0,3)", token.toString());
    token = tokenizer.next();
    assertNull(token);
  
public voidtestFrontUnigram()

    EdgeNGramTokenizer tokenizer = new EdgeNGramTokenizer(input, EdgeNGramTokenizer.Side.FRONT, 1, 1);
    Token token = null;
    token = tokenizer.next();
    assertEquals("(a,0,1)", token.toString());
    token = tokenizer.next();
    assertNull(token);
  
public voidtestInvalidInput()

    boolean gotException = false;
    try {        
      new EdgeNGramTokenizer(input, EdgeNGramTokenizer.Side.FRONT, 0, 0);
    } catch (IllegalArgumentException e) {
      gotException = true;
    }
    assertTrue(gotException);
  
public voidtestInvalidInput2()

    boolean gotException = false;
    try {        
      new EdgeNGramTokenizer(input, EdgeNGramTokenizer.Side.FRONT, 2, 1);
    } catch (IllegalArgumentException e) {
      gotException = true;
    }
    assertTrue(gotException);
  
public voidtestInvalidInput3()

    boolean gotException = false;
    try {        
      new EdgeNGramTokenizer(input, EdgeNGramTokenizer.Side.FRONT, -1, 2);
    } catch (IllegalArgumentException e) {
      gotException = true;
    }
    assertTrue(gotException);
  
public voidtestOversizedNgrams()

    EdgeNGramTokenizer tokenizer = new EdgeNGramTokenizer(input, EdgeNGramTokenizer.Side.FRONT, 6, 6);
    Token token = null;
    token = tokenizer.next();
    assertNull(token);