/** Add a new transition with min = max = label. */ public void addTransition(int source, int dest, int label) { addTransition(source, dest, label, label); }
/** 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; }
/** 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; }
a1.addTransition(0, 0, '0'); for (int p : initials) { a1.addEpsilon(0, p);
/** 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; }
/** * Returns a new (deterministic) automaton that accepts all strings. */ public static Automaton makeAnyString() { Automaton a = new Automaton(); int s = a.createState(); a.setAccept(s, true); a.addTransition(s, s, Character.MIN_CODE_POINT, Character.MAX_CODE_POINT); a.finishState(); return a; }
/** * Returns a new (deterministic) automaton that accepts all binary terms. */ public static Automaton makeAnyBinary() { Automaton a = new Automaton(); int s = a.createState(); a.setAccept(s, true); a.addTransition(s, s, 0, 255); a.finishState(); return a; }
result.addTransition(deadState, deadState, Character.MIN_CODE_POINT, Character.MAX_CODE_POINT); for(int j=0;j<count;j++) { a.getNextTransition(t); result.addTransition(i, t.dest, t.min, t.max); if (t.min > maxi) { result.addTransition(i, deadState, maxi, t.min-1); result.addTransition(i, deadState, maxi, Character.MAX_CODE_POINT);
/** * Returns a new (deterministic) automaton that accepts the single given * string. */ public static Automaton makeString(String s) { Automaton a = new Automaton(); int lastState = a.createState(); for (int i = 0, cp = 0; i < s.length(); i += Character.charCount(cp)) { int state = a.createState(); cp = s.codePointAt(i); a.addTransition(lastState, state, cp); lastState = state; } a.setAccept(lastState, true); a.finishState(); assert a.isDeterministic(); assert Operations.hasDeadStates(a) == false; return a; }
/** Add a [virtual] epsilon transition between source and dest. * Dest state must already have all transitions added because this * method simply copies those same transitions over to source. */ public void addEpsilon(int source, int dest) { Transition t = new Transition(); int count = initTransition(dest, t); for(int i=0;i<count;i++) { getNextTransition(t); addTransition(source, t.dest, t.min, t.max); } if (isAccept(dest)) { setAccept(source, true); } }
/** * Returns a new (deterministic) automaton that accepts the single given * string from the specified unicode code points. */ public static Automaton makeString(int[] word, int offset, int length) { Automaton a = new Automaton(); a.createState(); int s = 0; for (int i = offset; i < offset+length; i++) { int s2 = a.createState(); a.addTransition(s, s2, word[i]); s = s2; } a.setAccept(s, true); a.finishState(); return a; }
int state = a.createState(); int label = min.bytes[min.offset+i] & 0xff; a.addTransition(lastState, state, label); lastState = state; a.addTransition(lastState, state, 0); a.setAccept(state, true); lastState = state; a.addTransition(sinkState, sinkState, 0, 255); a.addTransition(lastState, nextState, minLabel); } else if (max == null) { equalPrefix = false; sharedPrefixLength = 0; a.addTransition(lastState, sinkState, minLabel+1, 0xff); a.addTransition(lastState, nextState, minLabel); } else { a.addTransition(lastState, nextState, minLabel); a.addTransition(lastState, sinkState, minLabel+1, maxLabel-1); a.addTransition(lastState, firstMaxState, maxLabel); a.addTransition(lastState, nextState, minLabel); if (minLabel < 255) { a.addTransition(lastState, sinkState, minLabel+1, 255);
a.getNextTransition(t); result.addTransition(n, stateMap[t.dest], t.min, t.max);
/** * Returns a new (deterministic) automaton that accepts a single codepoint whose * value is in the given interval (including both end points). */ public static Automaton makeCharRange(int min, int max) { if (min > max) { return makeEmpty(); } Automaton a = new Automaton(); int s1 = a.createState(); int s2 = a.createState(); a.setAccept(s2, true); a.addTransition(s1, s2, min, max); a.finishState(); return a; }
c.addTransition(p.s, r.s, min, max);
int state = a.createState(); cp = prefix.codePointAt(i); a.addTransition(lastState, state, cp, cp); lastState = state; int dest = description.transition(k, xpos, cvec); if (dest >= 0) { a.addTransition(stateOffset+k, stateOffset+dest, ch); if (dest >= 0) { for (int r = 0; r < numRanges; r++) { a.addTransition(stateOffset+k, stateOffset+dest, rangeLower[r], rangeUpper[r]);
a.getNextTransition(t); if (liveSet.get(t.dest)) { result.addTransition(map[i], map[t.dest], t.min, t.max);
for(int j=0;j<numTransitions;j++) { a.getNextTransition(t); result.addTransition(stateOffset + s, stateOffset + t.dest, t.min, t.max); for(int j=0;j<numTransitions;j++) { followA.getNextTransition(t); result.addTransition(stateOffset + s, followOffset + numStates + t.dest, t.min, t.max);
/** Compiles all added states and transitions into a new {@code Automaton} * and returns it. */ public Automaton finish() { // Create automaton with the correct size. int numStates = nextState; int numTransitions = nextTransition / 4; Automaton a = new Automaton(numStates, numTransitions); // Create all states. for (int state = 0; state < numStates; state++) { a.createState(); a.setAccept(state, isAccept(state)); } // Create all transitions sorter.sort(0, numTransitions); for (int upto = 0; upto < nextTransition; upto += 4) { a.addTransition(transitions[upto], transitions[upto+1], transitions[upto+2], transitions[upto+3]); } a.finishState(); return a; }
/** * Returns a new (deterministic) automaton that accepts the single given * binary term. */ public static Automaton makeBinary(BytesRef term) { Automaton a = new Automaton(); int lastState = a.createState(); for (int i=0;i<term.length;i++) { int state = a.createState(); int label = term.bytes[term.offset+i] & 0xff; a.addTransition(lastState, state, label); lastState = state; } a.setAccept(lastState, true); a.finishState(); assert a.isDeterministic(); assert Operations.hasDeadStates(a) == false; return a; }