Package fsa_recognizer :: Module class_det_fsa_recognize :: Class det_fsa_recognizer_with_sink_state
[hide private]
[frames] | no frames]

Class det_fsa_recognizer_with_sink_state

source code

class_fsa_recognize.fsa_recognizer --+
                                     |
                                    det_fsa_recognizer_with_sink_state

Deterministic fsa recognizer which adds a sink state to its fsa upon initializiation, if necessary, and has a slightly simplified recognition algorithm as a result.

Instance Methods [hide private]
 
__init__(self, fsa_inst, trace=False) source code
 
add_sink_state(self)
self.transitions is a list of k dictionaries,indexed 0:k-1, all storing integer values < k, representing an FSA transition table with each integer value corresponding to a state.
source code
Boolean
recognize(self, string)
Iterate through string making state transitions where possible, and failing if unable to reach the end of string in a final state.
source code
 
sink_state_message(self, state) source code

Inherited from class_fsa_recognize.fsa_recognizer: __repr__, non_final_state_message, not_in_alphabet_message, state_not_defined_for_message, trace

Method Details [hide private]

__init__(self, fsa_inst, trace=False)
(Constructor)

source code 
Parameters:
  • fsa - The fsa to be used for recognizing
  • trace - If True, gives verbose output on recognizing
Overrides: class_fsa_recognize.fsa_recognizer.__init__
(inherited documentation)

add_sink_state(self)

source code 

self.transitions is a list of k dictionaries,indexed 0:k-1, all storing integer values < k, representing an FSA transition table with each integer value corresponding to a state. If there is any state undefined for some input symbol in self.alphabet, update self.transitions with a copy of transitions, new_transitions, such that new_transitions adds a k+1th state, indexed k. For each x in self.alphabet, new_transitions[k][x]=k. For each x in self.alphabet and each state i, if transitions[i][x]='und' (or if 'x' is not a key for transitions[i]), new_transitions[i][x]=k.

recognize(self, string)

source code 

Iterate through string making state transitions where possible, and failing if unable to reach the end of string in a final state.

Differs from the recognize method for det_fsa_recognizer in that every state transition function is a total function over the alphabet, so if a symbol is not a key, it is not in the alphabet.

The sink state means that no failure with an in-alphabet string is due to a state being undefined for the input:

>>> R1 = det_fsa_recognizer(fsa1, True)
>>> R2 = det_fsa_recognizer_with_sink_state(fsa1, True)
>>> R1.recognize('baa!a')
State 4 not defined for a
False
>>> R2.recognize('baa!a')
Ending in sink state 5
False
>>>
Parameters:
  • string - the string to be recognized.
Returns: Boolean
Overrides: class_fsa_recognize.fsa_recognizer.recognize