gate.fsm
Class FSM

java.lang.Object
  extended by gate.fsm.FSM
All Implemented Interfaces:
JapeConstants, Serializable

public class FSM
extends Object
implements JapeConstants

This class implements a standard Finite State Machine. It is used for both deterministic and non-deterministic machines.

See Also:
Serialized Form

Field Summary
protected  State currentState
          Two members used by forEachState().
protected  Transition currentTransition
           
protected  State finalState
          The final state of this FSM (usually only valid during construction).
 HashMap<String,String> ruleHash
           
 
Fields inherited from interface gate.jape.JapeConstants
ALL_STYLE, APPELT_STYLE, BRILL_STYLE, DEFAULT_PRIORITY, FIRST_STYLE, INDENT_PADDING, KLEENE_PLUS, KLEENE_QUERY, KLEENE_STAR, MULTI_SPAN_BINDING, NO_BINDING, NO_KLEENE_OP, ONCE_STYLE, SINGLE_SPAN_BINDING
 
Constructor Summary
protected FSM()
          The constructor that all the other constructors should call.
protected FSM(ComplexPatternElement cpe)
          Builds a FSM starting from a ComplexPatternElement.
  FSM(Rule rule)
          Builds a FSM starting from a rule.
  FSM(SinglePhaseTransducer spt)
          Builds a standalone FSM starting from a single phase transducer.
 
Method Summary
protected  void addRules(PrioritisedRuleList rules)
          Do the work involved in creating an FSM from a PrioritisedRuleList.
 String asGraphViz(boolean includeConstraints)
          Returns a representation of this FSM in the GraphViz graph-visualization language.
 void eliminateVoidTransitions()
          Converts this FSM from a non-deterministic to a deterministic one by eliminating all the unrestricted transitions.
protected  void forEachState(Runnable r)
          Iterates over all the states in this FSM, setting currentState and currentTransition, then calling the given Runnable callback.
 Map<State,SimpleArraySet<Transition>> getAllStates()
           
 String getGML()
          Returns a GML (Graph Modelling Language) representation of the transition graph of this FSM.
 State getInitialState()
          Gets the initial state of this FSM
 ArrayList<RuleTime> getRuleTimes()
           
protected  void setRule(Rule rule)
          Do the work involved in creating an FSM from a Rule.
protected  FSM spawn(ComplexPatternElement currentPattern)
          A factory method for new FSMs like this one, given a ComplexPatternElement object.
protected  FSM spawn(Rule r)
          A factory method for new FSMs like this one, given a Rule object.
 String toString()
          Returns a textual description of this FSM.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

currentState

protected State currentState
Two members used by forEachState().


currentTransition

protected Transition currentTransition

finalState

protected State finalState
The final state of this FSM (usually only valid during construction).


ruleHash

public HashMap<String,String> ruleHash
Constructor Detail

FSM

protected FSM()
The constructor that all the other constructors should call.


FSM

public FSM(SinglePhaseTransducer spt)
Builds a standalone FSM starting from a single phase transducer.

Parameters:
spt - the single phase transducer to be used for building this FSM.

FSM

public FSM(Rule rule)
Builds a FSM starting from a rule. This FSM is actually a part of a larger one (usually the one that is built based on the single phase transducer that contains the rule). built by this constructor.

Parameters:
rule - the rule to be used for the building process.

FSM

protected FSM(ComplexPatternElement cpe)
Builds a FSM starting from a ComplexPatternElement. This FSM is usually part of a larger FSM based on the Rule that contains the ComplexPatternElement.

Parameters:
cpe - the ComplexPatternElement to be used for the building process.
Method Detail

getRuleTimes

public ArrayList<RuleTime> getRuleTimes()

addRules

protected void addRules(PrioritisedRuleList rules)
Do the work involved in creating an FSM from a PrioritisedRuleList.


setRule

protected void setRule(Rule rule)
Do the work involved in creating an FSM from a Rule.


spawn

protected FSM spawn(Rule r)
A factory method for new FSMs like this one, given a Rule object.


spawn

protected FSM spawn(ComplexPatternElement currentPattern)
A factory method for new FSMs like this one, given a ComplexPatternElement object.


getInitialState

public State getInitialState()
Gets the initial state of this FSM

Returns:
an object of type gate.fsm.State representing the initial state.

eliminateVoidTransitions

public void eliminateVoidTransitions()
Converts this FSM from a non-deterministic to a deterministic one by eliminating all the unrestricted transitions.


forEachState

protected void forEachState(Runnable r)
Iterates over all the states in this FSM, setting currentState and currentTransition, then calling the given Runnable callback.


getAllStates

public Map<State,SimpleArraySet<Transition>> getAllStates()
Returns:
a Map whose keys contain the states of this FSM, and whose values contain their corresponding transitions. This method actually walks the FSM, so it may be called before the FSM is finalized with compactTransitions().

asGraphViz

public String asGraphViz(boolean includeConstraints)
Returns a representation of this FSM in the GraphViz graph-visualization language. We use the "digraph" (directed graph) format. Nodes are labeled by their numerical indexes. A node's shape is a diamond if it's the initial state, and round otherwise. A node is green if it's an initial state, red if it's a final state, and black otherwise. Final states are also marked with a double-line outline.

Parameters:
includeConstraints - whether to include a stringified representation of each transition object as part of its label. The default is false.
See Also:
GraphViz for visulization

getGML

public String getGML()
Returns a GML (Graph Modelling Language) representation of the transition graph of this FSM.


toString

public String toString()
Returns a textual description of this FSM.

Overrides:
toString in class Object