Package ca.phon.fsa
Class SimpleFSA<T>
java.lang.Object
ca.phon.fsa.SimpleFSA<T>
- Direct Known Subclasses:
PhonexFSA
A basic implementation of a fsa. The
input to the machine must be an array of
type
T
.-
Nested Class Summary
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionvoid
addFinalState
(String state) Add a final statevoid
Add a new state to the machine.void
addTransition
(FSATransition<T> transition) Add a new transitionprotected FSATransition<T>
This method is called when the machine fails before end of input during delta.This method chooses which state the machine should move to given a machine state.Get the dot representation of the machine.String[]
int
getGroupIndex
(String groupName) Get index of named group.getGroupName
(int groupIndex) Get the group name for the given index.Get a list of all named groupsint
Get the number of groupsString[]
getTransitionsForState
(String state) Get the transitions for a paticular stategetTransitionsToState
(String state) Get the transitions for a paticular stateboolean
void
printDef()
void
removeFinalState
(String state) Remove a final statevoid
removeState
(String stateName) Remove a state (and all transitions to/from it)void
removeTransition
(FSATransition<T> transition) Remove a transitionrunWithTape
(T[] tape) runWithTape
(T[] tape, FSAState<T> machineState) runWithTape
(T[] tape, FSAState<T> machineState, boolean forceReluctant) Run the machine with the given tapevoid
setGroupName
(int groupIndex, String groupName) Set name of a group.void
setInitialState
(String initialState) void
setNumberOfGroups
(int numberOfGroups) Set the number of groupsvoid
-
Constructor Details
-
SimpleFSA
public SimpleFSA()
-
-
Method Details
-
setNumberOfGroups
public void setNumberOfGroups(int numberOfGroups) Set the number of groups- Parameters:
numberOfGroups
-
-
getNumberOfGroups
public int getNumberOfGroups()Get the number of groups- Returns:
- the number of groups
-
getGroupNames
Get a list of all named groups- Returns:
- list of group names
-
getGroupIndex
Get index of named group.- Returns:
- index of named group or -1 if not found
-
getGroupName
Get the group name for the given index.- Parameters:
groupIndex
-- Returns:
- the group name or
null
if group is not named
-
setGroupName
Set name of a group. Set during compile time.- Parameters:
groupIndex
-groupName
-
-
stripGroups
public void stripGroups() -
addState
Add a new state to the machine.- Parameters:
stateName
-
-
removeState
Remove a state (and all transitions to/from it)- Parameters:
stateName
-
-
addTransition
Add a new transition- Parameters:
transition
-
-
removeTransition
Remove a transition- Parameters:
transition
-
-
getInitialState
-
setInitialState
-
addFinalState
Add a final state -
removeFinalState
Remove a final state -
getTransitionsForState
Get the transitions for a paticular state- Parameters:
state
-- Returns:
- the transitions for the state
-
getTransitionsToState
Get the transitions for a paticular state- Parameters:
state
-- Returns:
- the transitions for the state
-
getTransitions
-
runWithTape
-
runWithTape
-
runWithTape
Run the machine with the given tape- Parameters:
tape
-machineState
-forceReluctant
- iftrue
reluctant quantifiers will be forced to match to attempt a full-input match.
-
delta
public FSATransition<T> delta(FSAState<T> machineState, Stack<SimpleFSA.DecisionTracker<T>> decisions) This method chooses which state the machine should move to given a machine state. If more than one choice is available they are added to the decision stack. Using backtrack will reset the machine tape index and return the next state the machine should move to using the next possible path choice.- Parameters:
machineState
-decisions
-- Returns:
- the next machine state. If no transition can be followed,
or we have reached the end of input
null
is returned.
-
backtrack
protected FSATransition<T> backtrack(FSAState<T> machineState, Stack<SimpleFSA.DecisionTracker<T>> decisions) This method is called when the machine fails before end of input during delta. The method resets to the last path decision and attempts to choose a new path through the machine. The machine tape index is reset by this method.- Parameters:
machineState
-decisions
-- Returns:
- the next state of the machine or
null
if no path choices exist on the decision stack.
-
getFinalStates
-
getStates
-
isFinalState
-
printDef
public void printDef() -
getDotText
Get the dot representation of the machine.
-