use of org.apache.lucene.analysis.TokenStream in project lucene-solr by apache.
the class TestGraphTokenStreamFiniteStrings method testGraphAndGapSameToken.
public void testGraphAndGapSameToken() throws Exception {
TokenStream ts = new CannedTokenStream(token("fast", 1, 1), token("wi", 2, 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, 2, 1, 1 });
assertTrue(it.hasNext());
assertTokenStream(it.next(), new String[] { "fast", "wifi", "network" }, new int[] { 1, 2, 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[] { 2, 1 });
assertTrue(it.hasNext());
assertTokenStream(it.next(), new String[] { "wifi" }, new int[] { 2 });
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.TokenStream in project lucene-solr by apache.
the class TestGraphTokenStreamFiniteStrings method testMultiGraph.
public void testMultiGraph() throws Exception {
TokenStream ts = new CannedTokenStream(token("turbo", 1, 1), token("fast", 0, 2), token("charged", 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[] { "turbo", "charged", "wi", "fi", "network" }, new int[] { 1, 1, 1, 1, 1 });
assertTrue(it.hasNext());
assertTokenStream(it.next(), new String[] { "turbo", "charged", "wifi", "network" }, new int[] { 1, 1, 1, 1 });
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[] { 2, 4 });
assertTrue(graph.hasSidePath(0));
it = graph.getFiniteStrings(0, 2);
assertTrue(it.hasNext());
assertTokenStream(it.next(), new String[] { "turbo", "charged" }, new int[] { 1, 1 });
assertTrue(it.hasNext());
assertTokenStream(it.next(), new String[] { "fast" }, new int[] { 1 });
assertFalse(it.hasNext());
assertTrue(graph.hasSidePath(2));
it = graph.getFiniteStrings(2, 4);
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(4));
it = graph.getFiniteStrings(4, -1);
assertTrue(it.hasNext());
assertTokenStream(it.next(), new String[] { "network" }, new int[] { 1 });
assertFalse(it.hasNext());
Term[] terms = graph.getTerms("field", 4);
assertArrayEquals(terms, new Term[] { new Term("field", "network") });
}
use of org.apache.lucene.analysis.TokenStream in project lucene-solr by apache.
the class TestGraphTokenStreamFiniteStrings method testSingleGraphWithGap.
public void testSingleGraphWithGap() throws Exception {
// "hey the fast wifi network", where "the" removed
TokenStream ts = new CannedTokenStream(token("hey", 1, 1), token("fast", 2, 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[] { "hey", "fast", "wi", "fi", "network" }, new int[] { 1, 2, 1, 1, 1 });
assertTrue(it.hasNext());
assertTokenStream(it.next(), new String[] { "hey", "fast", "wifi", "network" }, new int[] { 1, 2, 1, 1 });
assertFalse(it.hasNext());
int[] points = graph.articulationPoints();
assertArrayEquals(points, new int[] { 1, 2, 4 });
assertFalse(graph.hasSidePath(0));
it = graph.getFiniteStrings(0, 1);
assertTrue(it.hasNext());
assertTokenStream(it.next(), new String[] { "hey" }, new int[] { 1 });
assertFalse(it.hasNext());
Term[] terms = graph.getTerms("field", 0);
assertArrayEquals(terms, new Term[] { new Term("field", "hey") });
assertFalse(graph.hasSidePath(1));
it = graph.getFiniteStrings(1, 2);
assertTrue(it.hasNext());
assertTokenStream(it.next(), new String[] { "fast" }, new int[] { 2 });
assertFalse(it.hasNext());
terms = graph.getTerms("field", 1);
assertArrayEquals(terms, new Term[] { new Term("field", "fast") });
assertTrue(graph.hasSidePath(2));
it = graph.getFiniteStrings(2, 4);
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(4));
it = graph.getFiniteStrings(4, -1);
assertTrue(it.hasNext());
assertTokenStream(it.next(), new String[] { "network" }, new int[] { 1 });
assertFalse(it.hasNext());
terms = graph.getTerms("field", 4);
assertArrayEquals(terms, new Term[] { new Term("field", "network") });
}
use of org.apache.lucene.analysis.TokenStream in project lucene-solr by apache.
the class TestGraphTokenStreamFiniteStrings method testStackedGraphWithGap.
public void testStackedGraphWithGap() throws Exception {
TokenStream ts = new CannedTokenStream(token("fast", 1, 1), token("wi", 2, 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, 2, 1, 1 });
assertTrue(it.hasNext());
assertTokenStream(it.next(), new String[] { "fast", "wifi", "network" }, new int[] { 1, 2, 1 });
assertTrue(it.hasNext());
assertTokenStream(it.next(), new String[] { "fast", "wireless", "network" }, new int[] { 1, 2, 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[] { 2, 1 });
assertTrue(it.hasNext());
assertTokenStream(it.next(), new String[] { "wifi" }, new int[] { 2 });
assertTrue(it.hasNext());
assertTokenStream(it.next(), new String[] { "wireless" }, new int[] { 2 });
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.TokenStream in project lucene-solr by apache.
the class TestGraphTokenStreamFiniteStrings method testGraphWithRegularSynonym.
public void testGraphWithRegularSynonym() throws Exception {
TokenStream ts = new CannedTokenStream(token("fast", 1, 1), token("speedy", 0, 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 });
assertTrue(it.hasNext());
assertTokenStream(it.next(), new String[] { "speedy", "wi", "fi", "network" }, new int[] { 1, 1, 1, 1 });
assertTrue(it.hasNext());
assertTokenStream(it.next(), new String[] { "speedy", "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 });
assertTrue(it.hasNext());
assertTokenStream(it.next(), new String[] { "speedy" }, new int[] { 1 });
assertFalse(it.hasNext());
Term[] terms = graph.getTerms("field", 0);
assertArrayEquals(terms, new Term[] { new Term("field", "fast"), new Term("field", "speedy") });
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") });
}
Aggregations