public void Test() { TokenRangeSinkFilter sinkFilter = new TokenRangeSinkFilter(2, 4); String test = "The quick red fox jumped over the lazy brown dogs"; TeeSinkTokenFilter tee = new TeeSinkTokenFilter(new WhitespaceTokenizer(new StringReader(test))); TeeSinkTokenFilter.SinkTokenStream rangeToks = tee.NewSinkTokenStream(sinkFilter); int count = 0; tee.Reset(); while (tee.IncrementToken()) { count++; } int sinkCount = 0; rangeToks.Reset(); while (rangeToks.IncrementToken()) { sinkCount++; } Assert.True(count == 10, count + " does not equal: " + 10); Assert.True(sinkCount == 2, "rangeToks Size: " + sinkCount + " is not: " + 2); }
public void Test() { TokenTypeSinkFilter sinkFilter = new TokenTypeSinkFilter("D"); String test = "The quick red fox jumped over the lazy brown dogs"; TeeSinkTokenFilter ttf = new TeeSinkTokenFilter(new WordTokenFilter(new WhitespaceTokenizer(new StringReader(test)))); TeeSinkTokenFilter.SinkTokenStream sink = ttf.NewSinkTokenStream(sinkFilter); bool seenDogs = false; ITermAttribute termAtt = ttf.AddAttribute <ITermAttribute>(); ITypeAttribute typeAtt = ttf.AddAttribute <ITypeAttribute>(); ttf.Reset(); while (ttf.IncrementToken()) { if (termAtt.Term.Equals("dogs")) { seenDogs = true; Assert.True(typeAtt.Type.Equals("D") == true, typeAtt.Type + " is not equal to " + "D"); } else { Assert.True(typeAtt.Type.Equals("word"), typeAtt.Type + " is not null and it should be"); } } Assert.True(seenDogs == true, seenDogs + " does not equal: " + true); int sinkCount = 0; sink.Reset(); while (sink.IncrementToken()) { sinkCount++; } Assert.True(sinkCount == 1, "sink Size: " + sinkCount + " is not: " + 1); }