/** Copies over all states from other. */ public void copyStates(Automaton other) { int otherNumStates = other.getNumStates(); for (int s = 0; s < otherNumStates; s++) { int newState = createState(); setAccept(newState, other.isAccept(s)); } } }
private Automaton toAutomaton(Map<String,Automaton> automata, AutomatonProvider automaton_provider, int maxDeterminizedStates) throws IllegalArgumentException, TooComplexToDeterminizeException { try { return toAutomatonInternal(automata, automaton_provider, maxDeterminizedStates); } catch (TooComplexToDeterminizeException e) { throw new TooComplexToDeterminizeException(this, e); } }
static RegExp makeUnion(RegExp exp1, RegExp exp2) { RegExp r = new RegExp(); r.kind = Kind.REGEXP_UNION; r.exp1 = exp1; r.exp2 = exp2; return r; }
/** * Returns true if the given automaton accepts all strings for the specified min/max * range of the alphabet. The automaton must be minimized. */ public static boolean isTotal(Automaton a, int minAlphabet, int maxAlphabet) { if (a.isAccept(0) && a.getNumTransitions(0) == 1) { Transition t = new Transition(); a.getTransition(0, 0, t); return t.dest == 0 && t.min == minAlphabet && t.max == maxAlphabet; } return false; }
/** * Returns a new (deterministic) automaton that accepts only the empty string. */ public static Automaton makeEmptyString() { Automaton a = new Automaton(); a.createState(); a.setAccept(0, true); return a; }
/** * Returns true if the language of this automaton is finite. The * automaton must not have any dead states. */ public static boolean isFinite(Automaton a) { if (a.getNumStates() == 0) { return true; } return isFinite(new Transition(), a, 0, new BitSet(a.getNumStates()), new BitSet(a.getNumStates()), 0); }
final RegExp parseInterExp() throws IllegalArgumentException { RegExp e = parseConcatExp(); if (check(INTERSECTION) && match('&')) e = makeIntersection(e, parseInterExp()); return e; }
/** Appends the specified character to the specified state, returning a new state. */ public static int appendChar(Automaton a, int state, int c) { int newState = a.createState(); a.addTransition(state, newState, c, c); return newState; }
final RegExp parseUnionExp() throws IllegalArgumentException { RegExp e = parseInterExp(); if (match('|')) e = makeUnion(e, parseUnionExp()); return e; }
@Override public IntsRef next() { if (count >= limit) { // Abort on limit. return null; } IntsRef result = super.next(); if (result != null) { count++; } return result; }
public static Automaton toAutomaton(BytesRef lowerTerm, BytesRef upperTerm, boolean includeLower, boolean includeUpper) { if (lowerTerm == null) { // makeBinaryInterval is more picky than we are: includeLower = true; } if (upperTerm == null) { // makeBinaryInterval is more picky than we are: includeUpper = true; } return Automata.makeBinaryInterval(lowerTerm, includeLower, upperTerm, includeUpper); }
/** * Create a new LevenshteinAutomata for some input String. * Optionally count transpositions as a primitive edit. */ public LevenshteinAutomata(String input, boolean withTranspositions) { this(codePoints(input), Character.MAX_CODE_POINT, withTranspositions); }
/** * Return the most recent transitions's target state. */ State lastChild() { assert hasChildren() : "No outgoing transitions."; return states[states.length - 1]; }
static RegExp makeOptional(RegExp exp) { RegExp r = new RegExp(); r.kind = Kind.REGEXP_OPTIONAL; r.exp1 = exp; return r; }
/** Accept any single character starting from the specified state, returning the new state */ public static int appendAnyChar(Automaton a, int state) { int newState = a.createState(); a.addTransition(state, newState, Character.MIN_CODE_POINT, Character.MAX_CODE_POINT); return newState; }
static RegExp makeRepeat(RegExp exp, int min, int max) { RegExp r = new RegExp(); r.kind = Kind.REGEXP_REPEAT_MINMAX; r.exp1 = exp; r.min = min; r.max = max; return r; }
static RegExp makeChar(int c) { RegExp r = new RegExp(); r.kind = Kind.REGEXP_CHAR; r.c = c; return r; }
static RegExp makeAnyChar() { RegExp r = new RegExp(); r.kind = Kind.REGEXP_ANYCHAR; return r; }
static RegExp makeAutomaton(String s) { RegExp r = new RegExp(); r.kind = Kind.REGEXP_AUTOMATON; r.s = s; return r; }