Class RunAutomaton
- java.lang.Object
-
- org.apache.pinot.segment.local.utils.nativefst.automaton.RunAutomaton
-
- All Implemented Interfaces:
Serializable
- Direct Known Subclasses:
CharacterRunAutomaton
public class RunAutomaton extends Object implements Serializable
Finite-state automaton with fast run operation.- See Also:
- Serialized Form
-
-
Constructor Summary
Constructors Constructor Description RunAutomaton(Automaton a)Constructs a newRunAutomatonfrom a deterministicAutomaton.RunAutomaton(Automaton a, boolean tableize)Constructs a newRunAutomatonfrom a deterministicAutomaton.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description intgetInitialState()Returns initial state.intgetSize()Returns number of states in automaton.booleanisAccept(int state)Returns acceptance status for given state.static RunAutomatonload(InputStream stream)Retrieves a serializedRunAutomatonfrom a stream.static RunAutomatonload(URL url)Retrieves a serializedRunAutomatonlocated by a URL.AutomatonMatchernewMatcher(CharSequence s)Creates a new automaton matcher for the given input.AutomatonMatchernewMatcher(CharSequence s, int startOffset, int endOffset)Creates a new automaton matcher for the given input.booleanrun(String s)Returns true if the given string is accepted by this automaton.intrun(String s, int offset)Returns the length of the longest accepted run of the given string starting at the given offset.intstep(int state, char c)Returns the state obtained by reading the given char from the given state.intstep(int state, int c)Returns the state obtained by reading the given char from the given state.voidstore(OutputStream stream)Writes thisRunAutomatonto the given stream.StringtoString()Returns a string representation of this automaton.
-
-
-
Constructor Detail
-
RunAutomaton
public RunAutomaton(Automaton a)
Constructs a newRunAutomatonfrom a deterministicAutomaton. Same asRunAutomaton(a, true).- Parameters:
a- an automaton
-
RunAutomaton
public RunAutomaton(Automaton a, boolean tableize)
Constructs a newRunAutomatonfrom a deterministicAutomaton. If the given automaton is not deterministic, it is determinized first.- Parameters:
a- an automatontableize- if true, a transition table is created which makes therunmethod faster in return of a higher memory usage
-
-
Method Detail
-
load
public static RunAutomaton load(URL url) throws IOException, ClassCastException, ClassNotFoundException
Retrieves a serializedRunAutomatonlocated by a URL.- Parameters:
url- URL of serialized automaton- Throws:
IOException- if input/output related exception occursClassCastException- if the data is not a serializedRunAutomatonClassNotFoundException- if the class of the serialized object cannot be found
-
load
public static RunAutomaton load(InputStream stream) throws IOException, ClassCastException, ClassNotFoundException
Retrieves a serializedRunAutomatonfrom a stream.- Parameters:
stream- input stream with serialized automaton- Throws:
IOException- if input/output related exception occursClassCastException- if the data is not a serializedRunAutomatonClassNotFoundException- if the class of the serialized object cannot be found
-
toString
public String toString()
Returns a string representation of this automaton.
-
getSize
public int getSize()
Returns number of states in automaton.
-
isAccept
public boolean isAccept(int state)
Returns acceptance status for given state.
-
getInitialState
public int getInitialState()
Returns initial state.
-
store
public void store(OutputStream stream) throws IOException
Writes thisRunAutomatonto the given stream.- Parameters:
stream- output stream for serialized automaton- Throws:
IOException- if input/output related exception occurs
-
step
public final int step(int state, int c)Returns the state obtained by reading the given char from the given state. Returns -1 if not obtaining any such state. (If the originalAutomatonhad no dead states, -1 is returned here if and only if a dead state is entered in an equivalent automaton with a total transition function.)
-
step
public int step(int state, char c)Returns the state obtained by reading the given char from the given state. Returns -1 if not obtaining any such state. (If the originalAutomatonhad no dead states, -1 is returned here if and only if a dead state is entered in an equivalent automaton with a total transition function.)
-
run
public boolean run(String s)
Returns true if the given string is accepted by this automaton.
-
run
public int run(String s, int offset)
Returns the length of the longest accepted run of the given string starting at the given offset.- Parameters:
s- the stringoffset- offset intoswhere the run starts- Returns:
- length of the longest accepted run, -1 if no run is accepted
-
newMatcher
public AutomatonMatcher newMatcher(CharSequence s)
Creates a new automaton matcher for the given input.- Parameters:
s- the CharSequence to search- Returns:
- A new automaton matcher for the given input
-
newMatcher
public AutomatonMatcher newMatcher(CharSequence s, int startOffset, int endOffset)
Creates a new automaton matcher for the given input.- Parameters:
s- the CharSequence to searchstartOffset- the starting offset of the given character sequenceendOffset- the ending offset of the given character sequence- Returns:
- A new automaton matcher for the given input
-
-