/** tests intersect: TODO start at a random term! */ public void testIntersect() throws Exception { for (int i = 0; i < numIterations; i++) { String reg = AutomatonTestUtil.randomRegexp(random()); Automaton automaton = new RegExp(reg, RegExp.NONE).toAutomaton(); CompiledAutomaton ca = new CompiledAutomaton(automaton, SpecialOperations.isFinite(automaton), false); TermsEnum te = MultiFields.getTerms(reader, "field").intersect(ca, null); Automaton expected = BasicOperations.intersection(termsAutomaton, automaton); TreeSet<BytesRef> found = new TreeSet<BytesRef>(); while (te.next() != null) { found.add(BytesRef.deepCopyOf(te.term())); } Automaton actual = BasicAutomata.makeStringUnion(found); assertTrue(BasicOperations.sameLanguage(expected, actual)); } }
/** Minimizes the given automaton using Brzozowski's algorithm. */ public static void minimizeBrzozowski(Automaton a) { if (a.isSingleton()) return; BasicOperations.determinize(a, SpecialOperations.reverse(a)); BasicOperations.determinize(a, SpecialOperations.reverse(a)); }
/** Gets character class of given char. */ int getCharClass(char c) { return SpecialOperations.findIndex(c, points); }
/** Simple, original brics implementation of Brzozowski minimize() */ public static void minimizeSimple(Automaton a) { if (a.isSingleton()) return; determinizeSimple(a, SpecialOperations.reverse(a)); determinizeSimple(a, SpecialOperations.reverse(a)); }