use of org.apache.lucene.util.automaton.Automaton in project lucene-solr by apache.
the class TestGraphTokenizers method testSynOverMultipleHoles.
public void testSynOverMultipleHoles() throws Exception {
final TokenStream ts = new CannedTokenStream(new Token[] { token("a", 1, 1), token("x", 0, 3), token("b", 3, 1) });
final Automaton a1 = join(s2a("a"), SEP_A, HOLE_A, SEP_A, HOLE_A, SEP_A, s2a("b"));
final Automaton a2 = join(s2a("x"), SEP_A, s2a("b"));
assertSameLanguage(Operations.union(a1, a2), ts);
}
use of org.apache.lucene.util.automaton.Automaton in project lucene-solr by apache.
the class TestGraphTokenizers method testSynOverHole.
public void testSynOverHole() throws Exception {
final TokenStream ts = new CannedTokenStream(new Token[] { token("a", 1, 1), token("X", 0, 2), token("b", 2, 1) });
final Automaton a1 = Operations.union(join(s2a("a"), SEP_A, HOLE_A), s2a("X"));
final Automaton expected = Operations.concatenate(a1, join(SEP_A, s2a("b")));
assertSameLanguage(expected, ts);
}
use of org.apache.lucene.util.automaton.Automaton in project lucene-solr by apache.
the class PrefixQuery method toAutomaton.
/** Build an automaton accepting all terms with the specified prefix. */
public static Automaton toAutomaton(BytesRef prefix) {
final int numStatesAndTransitions = prefix.length + 1;
final Automaton automaton = new Automaton(numStatesAndTransitions, numStatesAndTransitions);
int lastState = automaton.createState();
for (int i = 0; i < prefix.length; i++) {
int state = automaton.createState();
automaton.addTransition(lastState, state, prefix.bytes[prefix.offset + i] & 0xff);
lastState = state;
}
automaton.setAccept(lastState, true);
automaton.addTransition(lastState, lastState, 0, 255);
automaton.finishState();
assert automaton.isDeterministic();
return automaton;
}
use of org.apache.lucene.util.automaton.Automaton in project lucene-solr by apache.
the class TestAutomatonQuery method testNFA.
/**
* Test that a nondeterministic automaton works correctly. (It should will be
* determinized)
*/
public void testNFA() throws IOException {
// accept this or three, the union is an NFA (two transitions for 't' from
// initial state)
Automaton nfa = Operations.union(Automata.makeString("this"), Automata.makeString("three"));
assertAutomatonHits(2, nfa);
}
use of org.apache.lucene.util.automaton.Automaton in project lucene-solr by apache.
the class TestAutomatonQueryUnicode method testSortOrder.
/**
* Test that AutomatonQuery interacts with lucene's sort order correctly.
*
* This expression matches something either starting with the arabic
* presentation forms block, or a supplementary character.
*/
public void testSortOrder() throws IOException {
Automaton a = new RegExp("((𩬅)|ﮔ).*").toAutomaton();
assertAutomatonHits(2, a);
}
Aggregations