Class Automaton
- java.lang.Object
-
- org.apache.pinot.segment.local.utils.nativefst.automaton.Automaton
-
- All Implemented Interfaces:
Serializable,Cloneable
public class Automaton extends Object implements Serializable, Cloneable
Finite-state automaton with regular expression operations.Class invariants:
- An automaton is either represented explicitly (with
StateandTransitionobjects) or with a singleton string (expandSingleton()) in case the automaton is known to accept exactly one string. (Implicitly, all states and transitions of an automaton are reachable from its initial state.) - Automata are always reduced (see
reduce()) and have no transitions to dead states (seeremoveDeadTransitions()). - Automata provided as input to operations are generally assumed to be disjoint.
- See Also:
- Serialized Form
-
-
Field Summary
Fields Modifier and Type Field Description static boolean_allowMutationSelects whether operations may modify the input automata (default:false).static int_minimizationSelects minimization algorithm (default:MINIMIZE_HOPCROFT).static boolean_minimizeAlwaysMinimize always flag.static intMINIMIZE_BRZOZOWSKIMinimize using Brzozowski's O(2n) algorithm.static intMINIMIZE_HOPCROFTMinimize using Hopcroft's O(n log n) algorithm.static intMINIMIZE_HUFFMANMinimize using Huffman's O(n2) algorithm.static intMINIMIZE_VALMARIMinimize using Valmari's O(n + m log m) algorithm.
-
Constructor Summary
Constructors Constructor Description Automaton()Constructs a new automaton that accepts the empty language.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description voidaddEpsilons(Collection<StatePair> pairs)Automatonclone()Returns a clone of this automaton.Automatoncomplement()voiddeterminize()booleanequals(Object obj)Returns true if the language of this automaton is equal to the language of the given automaton.voidexpandSingleton()Expands singleton representation to normal representation.Set<State>getAcceptStates()Returns the set of reachable accept states.StategetInitialState()Gets initial state.intgetNumberOfStates()Returns the number of states in this automaton.intgetNumberOfTransitions()Returns the number of transitions in this automaton.Set<State>getStates()Returns the set of states that are reachable from the initial state.inthashCode()Returns hash code for this automaton.Automatonintersection(Automaton a)booleanisEmpty()booleanisEmptyString()voidminimize()static Automatonminimize(Automaton a)Automatonminus(Automaton a)Automatonoptional()voidreduce()Reduces this automaton.voidremoveDeadTransitions()Removes transitions to dead states and callsreduce()andclearHashCode().Automatonrepeat()Automatonrepeat(int min)Automatonrepeat(int min, int max)booleanrun(String s)static booleansetAllowMutate(boolean flag)Sets or resets allow mutate flag.voidsetInitialState(State s)Sets initial state.booleansubsetOf(Automaton a)StringtoString()Returns a string representation of this automaton.
-
-
-
Field Detail
-
MINIMIZE_HUFFMAN
public static final int MINIMIZE_HUFFMAN
Minimize using Huffman's O(n2) algorithm. This is the standard text-book algorithm.- See Also:
- Constant Field Values
-
MINIMIZE_BRZOZOWSKI
public static final int MINIMIZE_BRZOZOWSKI
Minimize using Brzozowski's O(2n) algorithm. This algorithm uses the reverse-determinize-reverse-determinize trick, which has a bad worst-case behavior but often works very well in practice (even better than Hopcroft's!).- See Also:
- Constant Field Values
-
MINIMIZE_HOPCROFT
public static final int MINIMIZE_HOPCROFT
Minimize using Hopcroft's O(n log n) algorithm.- See Also:
- Constant Field Values
-
MINIMIZE_VALMARI
public static final int MINIMIZE_VALMARI
Minimize using Valmari's O(n + m log m) algorithm.- See Also:
- Constant Field Values
-
_minimizeAlways
public static boolean _minimizeAlways
Minimize always flag.
-
_allowMutation
public static boolean _allowMutation
Selects whether operations may modify the input automata (default:false).
-
_minimization
public static int _minimization
Selects minimization algorithm (default:MINIMIZE_HOPCROFT).
-
-
Constructor Detail
-
Automaton
public Automaton()
Constructs a new automaton that accepts the empty language. Using this constructor, automata can be constructed manually fromStateandTransitionobjects.- See Also:
setInitialState(State),State,Transition
-
-
Method Detail
-
setAllowMutate
public static boolean setAllowMutate(boolean flag)
Sets or resets allow mutate flag. If this flag is set, then all automata operations may modify automata given as input; otherwise, operations will always leave input automata languages unmodified. By default, the flag is not set.- Parameters:
flag- if true, the flag is set- Returns:
- previous value of the flag
-
minimize
public static Automaton minimize(Automaton a)
SeeMinimizationOperations.minimize(Automaton). Returns the automaton being given as argument.
-
getInitialState
public State getInitialState()
Gets initial state.- Returns:
- state
-
setInitialState
public void setInitialState(State s)
Sets initial state.- Parameters:
s- state
-
getStates
public Set<State> getStates()
Returns the set of states that are reachable from the initial state.- Returns:
- set of
Stateobjects
-
getAcceptStates
public Set<State> getAcceptStates()
Returns the set of reachable accept states.- Returns:
- set of
Stateobjects
-
reduce
public void reduce()
Reduces this automaton. An automaton is "reduced" by combining overlapping and adjacent edge intervals with same destination.
-
removeDeadTransitions
public void removeDeadTransitions()
Removes transitions to dead states and callsreduce()andclearHashCode(). (A state is "dead" if no accept state is reachable from it.)
-
expandSingleton
public void expandSingleton()
Expands singleton representation to normal representation. Does nothing if not in singleton representation.
-
getNumberOfStates
public int getNumberOfStates()
Returns the number of states in this automaton.
-
getNumberOfTransitions
public int getNumberOfTransitions()
Returns the number of transitions in this automaton. This number is counted as the total number of edges, where one edge may be a character interval.
-
equals
public boolean equals(Object obj)
Returns true if the language of this automaton is equal to the language of the given automaton. Implemented usinghashCodeandsubsetOf.
-
hashCode
public int hashCode()
Returns hash code for this automaton. The hash code is based on the number of states and transitions in the minimized automaton. Invoking this method may involve minimizing the automaton.
-
toString
public String toString()
Returns a string representation of this automaton.
-
optional
public Automaton optional()
-
repeat
public Automaton repeat()
-
repeat
public Automaton repeat(int min)
-
repeat
public Automaton repeat(int min, int max)
-
complement
public Automaton complement()
-
subsetOf
public boolean subsetOf(Automaton a)
-
determinize
public void determinize()
-
addEpsilons
public void addEpsilons(Collection<StatePair> pairs)
-
isEmptyString
public boolean isEmptyString()
-
isEmpty
public boolean isEmpty()
-
run
public boolean run(String s)
-
minimize
public void minimize()
-
-