use of org.apache.lucene.analysis.CannedTokenStream in project lucene-solr by apache.
the class TestGraphTokenStreamFiniteStrings method testStackedGraph.
public void testStackedGraph() throws Exception {
TokenStream ts = new CannedTokenStream(token("fast", 1, 1), token("wi", 1, 1), token("wifi", 0, 2), token("wireless", 0, 2), token("fi", 1, 1), token("network", 1, 1));
GraphTokenStreamFiniteStrings graph = new GraphTokenStreamFiniteStrings(ts);
Iterator<TokenStream> it = graph.getFiniteStrings();
assertTrue(it.hasNext());
assertTokenStream(it.next(), new String[] { "fast", "wi", "fi", "network" }, new int[] { 1, 1, 1, 1 });
assertTrue(it.hasNext());
assertTokenStream(it.next(), new String[] { "fast", "wifi", "network" }, new int[] { 1, 1, 1 });
assertTrue(it.hasNext());
assertTokenStream(it.next(), new String[] { "fast", "wireless", "network" }, new int[] { 1, 1, 1 });
assertFalse(it.hasNext());
int[] points = graph.articulationPoints();
assertArrayEquals(points, new int[] { 1, 3 });
assertFalse(graph.hasSidePath(0));
it = graph.getFiniteStrings(0, 1);
assertTrue(it.hasNext());
assertTokenStream(it.next(), new String[] { "fast" }, new int[] { 1 });
assertFalse(it.hasNext());
Term[] terms = graph.getTerms("field", 0);
assertArrayEquals(terms, new Term[] { new Term("field", "fast") });
assertTrue(graph.hasSidePath(1));
it = graph.getFiniteStrings(1, 3);
assertTrue(it.hasNext());
assertTokenStream(it.next(), new String[] { "wi", "fi" }, new int[] { 1, 1 });
assertTrue(it.hasNext());
assertTokenStream(it.next(), new String[] { "wifi" }, new int[] { 1 });
assertTrue(it.hasNext());
assertTokenStream(it.next(), new String[] { "wireless" }, new int[] { 1 });
assertFalse(it.hasNext());
assertFalse(graph.hasSidePath(3));
it = graph.getFiniteStrings(3, -1);
assertTrue(it.hasNext());
assertTokenStream(it.next(), new String[] { "network" }, new int[] { 1 });
assertFalse(it.hasNext());
terms = graph.getTerms("field", 3);
assertArrayEquals(terms, new Term[] { new Term("field", "network") });
}
use of org.apache.lucene.analysis.CannedTokenStream in project lucene-solr by apache.
the class TestGraphTokenStreamFiniteStrings method testStackedGraphWithRepeat.
public void testStackedGraphWithRepeat() throws Exception {
TokenStream ts = new CannedTokenStream(token("ny", 1, 4), token("new", 0, 1), token("new", 0, 3), token("york", 1, 1), token("city", 1, 2), token("york", 1, 1), token("is", 1, 1), token("great", 1, 1));
GraphTokenStreamFiniteStrings graph = new GraphTokenStreamFiniteStrings(ts);
Iterator<TokenStream> it = graph.getFiniteStrings();
assertTrue(it.hasNext());
assertTokenStream(it.next(), new String[] { "ny", "is", "great" }, new int[] { 1, 1, 1 });
assertTrue(it.hasNext());
assertTokenStream(it.next(), new String[] { "new", "york", "city", "is", "great" }, new int[] { 1, 1, 1, 1, 1 });
assertTrue(it.hasNext());
assertTokenStream(it.next(), new String[] { "new", "york", "is", "great" }, new int[] { 1, 1, 1, 1 });
assertFalse(it.hasNext());
int[] points = graph.articulationPoints();
assertArrayEquals(points, new int[] { 4, 5 });
assertTrue(graph.hasSidePath(0));
it = graph.getFiniteStrings(0, 4);
assertTrue(it.hasNext());
assertTokenStream(it.next(), new String[] { "ny" }, new int[] { 1 });
assertTrue(it.hasNext());
assertTokenStream(it.next(), new String[] { "new", "york", "city" }, new int[] { 1, 1, 1 });
assertTrue(it.hasNext());
assertTokenStream(it.next(), new String[] { "new", "york" }, new int[] { 1, 1 });
assertFalse(it.hasNext());
assertFalse(graph.hasSidePath(4));
it = graph.getFiniteStrings(4, 5);
assertTrue(it.hasNext());
assertTokenStream(it.next(), new String[] { "is" }, new int[] { 1 });
assertFalse(it.hasNext());
Term[] terms = graph.getTerms("field", 4);
assertArrayEquals(terms, new Term[] { new Term("field", "is") });
assertFalse(graph.hasSidePath(5));
it = graph.getFiniteStrings(5, -1);
assertTrue(it.hasNext());
assertTokenStream(it.next(), new String[] { "great" }, new int[] { 1 });
assertFalse(it.hasNext());
terms = graph.getTerms("field", 5);
assertArrayEquals(terms, new Term[] { new Term("field", "great") });
}
use of org.apache.lucene.analysis.CannedTokenStream in project lucene-solr by apache.
the class TestGraphTokenStreamFiniteStrings method testSingleGraph.
public void testSingleGraph() throws Exception {
TokenStream ts = new CannedTokenStream(token("fast", 1, 1), token("wi", 1, 1), token("wifi", 0, 2), token("fi", 1, 1), token("network", 1, 1));
GraphTokenStreamFiniteStrings graph = new GraphTokenStreamFiniteStrings(ts);
Iterator<TokenStream> it = graph.getFiniteStrings();
assertTrue(it.hasNext());
assertTokenStream(it.next(), new String[] { "fast", "wi", "fi", "network" }, new int[] { 1, 1, 1, 1 });
assertTrue(it.hasNext());
assertTokenStream(it.next(), new String[] { "fast", "wifi", "network" }, new int[] { 1, 1, 1 });
assertFalse(it.hasNext());
int[] points = graph.articulationPoints();
assertArrayEquals(points, new int[] { 1, 3 });
assertFalse(graph.hasSidePath(0));
it = graph.getFiniteStrings(0, 1);
assertTrue(it.hasNext());
assertTokenStream(it.next(), new String[] { "fast" }, new int[] { 1 });
assertFalse(it.hasNext());
Term[] terms = graph.getTerms("field", 0);
assertArrayEquals(terms, new Term[] { new Term("field", "fast") });
assertTrue(graph.hasSidePath(1));
it = graph.getFiniteStrings(1, 3);
assertTrue(it.hasNext());
assertTokenStream(it.next(), new String[] { "wi", "fi" }, new int[] { 1, 1 });
assertTrue(it.hasNext());
assertTokenStream(it.next(), new String[] { "wifi" }, new int[] { 1 });
assertFalse(it.hasNext());
assertFalse(graph.hasSidePath(3));
it = graph.getFiniteStrings(3, -1);
assertTrue(it.hasNext());
assertTokenStream(it.next(), new String[] { "network" }, new int[] { 1 });
assertFalse(it.hasNext());
terms = graph.getTerms("field", 3);
assertArrayEquals(terms, new Term[] { new Term("field", "network") });
}
use of org.apache.lucene.analysis.CannedTokenStream in project lucene-solr by apache.
the class TestGraphTokenStreamFiniteStrings method testIllegalState.
public void testIllegalState() throws Exception {
expectThrows(IllegalStateException.class, () -> {
TokenStream ts = new CannedTokenStream(token("a", 0, 1), token("b", 1, 1));
new GraphTokenStreamFiniteStrings(ts).getFiniteStrings();
});
}
use of org.apache.lucene.analysis.CannedTokenStream in project lucene-solr by apache.
the class AnalyzingSuggesterTest method testTooManyExpansions.
public void testTooManyExpansions() throws Exception {
final Analyzer a = new Analyzer() {
@Override
protected TokenStreamComponents createComponents(String fieldName) {
Tokenizer tokenizer = new MockTokenizer(MockTokenizer.SIMPLE, true);
return new TokenStreamComponents(tokenizer) {
@Override
public TokenStream getTokenStream() {
Token a = new Token("a", 0, 1);
a.setPositionIncrement(1);
Token b = new Token("b", 0, 1);
b.setPositionIncrement(0);
return new CannedTokenStream(new Token[] { a, b });
}
@Override
protected void setReader(final Reader reader) {
}
};
}
};
Directory tempDir = getDirectory();
AnalyzingSuggester suggester = new AnalyzingSuggester(tempDir, "suggest", a, a, 0, 256, 1, true);
suggester.build(new InputArrayIterator(new Input[] { new Input("a", 1) }));
assertEquals("[a/1]", suggester.lookup("a", false, 1).toString());
IOUtils.close(a, tempDir);
}
Aggregations