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

EdgeNGramTokenFilterTest

public class EdgeNGramTokenFilterTest extends TestCase
Tests {@link EdgeNGramTokenFilter} for correctness.
author
Otis Gospodnetic

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

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

    EdgeNGramTokenFilter tokenizer = new EdgeNGramTokenFilter(input, EdgeNGramTokenFilter.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()

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

    EdgeNGramTokenFilter tokenizer = new EdgeNGramTokenFilter(input, EdgeNGramTokenFilter.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()

    EdgeNGramTokenFilter tokenizer = new EdgeNGramTokenFilter(input, EdgeNGramTokenFilter.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 EdgeNGramTokenFilter(input, EdgeNGramTokenFilter.Side.FRONT, 0, 0);
    } catch (IllegalArgumentException e) {
      gotException = true;
    }
    assertTrue(gotException);
  
public voidtestInvalidInput2()

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

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

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