Package ca.phon.fsa

Class SimpleFSA<T>

java.lang.Object
ca.phon.fsa.SimpleFSA<T>
Direct Known Subclasses:
PhonexFSA

public class SimpleFSA<T> extends Object
A basic implementation of a fsa. The input to the machine must be an array of type T.
  • 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

      public List<String> getGroupNames()
      Get a list of all named groups
      Returns:
      list of group names
    • getGroupIndex

      public int getGroupIndex(String groupName)
      Get index of named group.
      Returns:
      index of named group or -1 if not found
    • getGroupName

      public String getGroupName(int groupIndex)
      Get the group name for the given index.
      Parameters:
      groupIndex -
      Returns:
      the group name or null if group is not named
    • setGroupName

      public void setGroupName(int groupIndex, String groupName)
      Set name of a group. Set during compile time.
      Parameters:
      groupIndex -
      groupName -
    • stripGroups

      public void stripGroups()
    • addState

      public void addState(String stateName)
      Add a new state to the machine.
      Parameters:
      stateName -
    • removeState

      public void removeState(String stateName)
      Remove a state (and all transitions to/from it)
      Parameters:
      stateName -
    • addTransition

      public void addTransition(FSATransition<T> transition)
      Add a new transition
      Parameters:
      transition -
    • removeTransition

      public void removeTransition(FSATransition<T> transition)
      Remove a transition
      Parameters:
      transition -
    • getInitialState

      public String getInitialState()
    • setInitialState

      public void setInitialState(String initialState)
    • addFinalState

      public void addFinalState(String state)
      Add a final state
    • removeFinalState

      public void removeFinalState(String state)
      Remove a final state
    • getTransitionsForState

      public List<FSATransition<T>> getTransitionsForState(String state)
      Get the transitions for a paticular state
      Parameters:
      state -
      Returns:
      the transitions for the state
    • getTransitionsToState

      public List<FSATransition<T>> getTransitionsToState(String state)
      Get the transitions for a paticular state
      Parameters:
      state -
      Returns:
      the transitions for the state
    • getTransitions

      public List<FSATransition<T>> getTransitions()
    • runWithTape

      public FSAState<T> runWithTape(T[] tape)
    • runWithTape

      public FSAState<T> runWithTape(T[] tape, FSAState<T> machineState)
    • runWithTape

      public FSAState<T> runWithTape(T[] tape, FSAState<T> machineState, boolean forceReluctant)
      Run the machine with the given tape
      Parameters:
      tape -
      machineState -
      forceReluctant - if true 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

      public String[] getFinalStates()
    • getStates

      public String[] getStates()
    • isFinalState

      public boolean isFinalState(String q)
    • printDef

      public void printDef()
    • getDotText

      public String getDotText()
      Get the dot representation of the machine.