Search in sources :

Example 56 with Automaton

use of org.apache.lucene.util.automaton.Automaton in project lucene-solr by apache.

the class TestGraphTokenizers method testOverlappedTokensSausage.

public void testOverlappedTokensSausage() throws Exception {
    // Two tokens on top of each other (sausage):
    final TokenStream ts = new CannedTokenStream(new Token[] { token("abc", 1, 1), token("xyz", 0, 1) });
    final Automaton a1 = s2a("abc");
    final Automaton a2 = s2a("xyz");
    assertSameLanguage(Operations.union(a1, a2), ts);
}
Also used : Automaton(org.apache.lucene.util.automaton.Automaton)

Example 57 with Automaton

use of org.apache.lucene.util.automaton.Automaton in project lucene-solr by apache.

the class TestRegexpQuery method testCustomProvider.

public void testCustomProvider() throws IOException {
    AutomatonProvider myProvider = new AutomatonProvider() {

        // automaton that matches quick or brown
        private Automaton quickBrownAutomaton = Operations.union(Arrays.asList(Automata.makeString("quick"), Automata.makeString("brown"), Automata.makeString("bob")));

        @Override
        public Automaton getAutomaton(String name) {
            if (name.equals("quickBrown"))
                return quickBrownAutomaton;
            else
                return null;
        }
    };
    RegexpQuery query = new RegexpQuery(newTerm("<quickBrown>"), RegExp.ALL, myProvider, DEFAULT_MAX_DETERMINIZED_STATES);
    assertEquals(1, searcher.search(query, 5).totalHits);
}
Also used : Automaton(org.apache.lucene.util.automaton.Automaton) AutomatonProvider(org.apache.lucene.util.automaton.AutomatonProvider)

Aggregations

Automaton (org.apache.lucene.util.automaton.Automaton)57 TokenStreamToAutomaton (org.apache.lucene.analysis.TokenStreamToAutomaton)17 IntsRef (org.apache.lucene.util.IntsRef)13 BytesRef (org.apache.lucene.util.BytesRef)12 ArrayList (java.util.ArrayList)11 Directory (org.apache.lucene.store.Directory)8 HashSet (java.util.HashSet)7 MockAnalyzer (org.apache.lucene.analysis.MockAnalyzer)7 Document (org.apache.lucene.document.Document)6 CompiledAutomaton (org.apache.lucene.util.automaton.CompiledAutomaton)6 Transition (org.apache.lucene.util.automaton.Transition)6 TokenStream (org.apache.lucene.analysis.TokenStream)5 BytesRefBuilder (org.apache.lucene.util.BytesRefBuilder)5 CharsRefBuilder (org.apache.lucene.util.CharsRefBuilder)5 CharacterRunAutomaton (org.apache.lucene.util.automaton.CharacterRunAutomaton)5 Analyzer (org.apache.lucene.analysis.Analyzer)4 IntsRefBuilder (org.apache.lucene.util.IntsRefBuilder)4 FiniteStringsIterator (org.apache.lucene.util.automaton.FiniteStringsIterator)4 LevenshteinAutomata (org.apache.lucene.util.automaton.LevenshteinAutomata)4 RegExp (org.apache.lucene.util.automaton.RegExp)4