Package fsa_recognizer :: Module read_fst_file :: Class FstCompiler
[hide private]
[frames] | no frames]

Class FstCompiler

source code

object --+
         |
        FstCompiler
Known Subclasses:

Class for compiling FST representations in various file formats into equivalent raw Python dictionaries such that:

  D[state][upper_char][lower_char] = set of states

The intent of this 'raw' dictionary representation is to be a modular portable representation of the FST transitions and final and initial state. Alphabet and feasible_pair info is stored on the compiler instance.

The raw dictionary is not suitable for the code in fsa_recognizer.fta_rec because it does not define a total functions on the alphabet. To produce dictionaries of that form call fsa_recognizer.fta_rec.make_fst_from_file, which calls an instance of this class for initial file processing and then fills out the partial transition functions.

Default assumptions for FST:

Instance Methods [hide private]
 
__init__(self)
x.__init__(...) initializes x; see x.__class__.__doc__ for signature
source code
dictionary of dictionary of dictionaries
read_file(self, file)
Abstract interface for generic read file fn.
source code
 
initialize_reader(self)
Zero out all file specific attributes before compiling a new file.
source code

Inherited from object: __delattr__, __getattribute__, __hash__, __new__, __reduce__, __reduce_ex__, __repr__, __setattr__, __str__

Properties [hide private]

Inherited from object: __class__

Method Details [hide private]

__init__(self)
(Constructor)

source code 

x.__init__(...) initializes x; see x.__class__.__doc__ for signature

Overrides: object.__init__
(inherited documentation)

read_file(self, file)

source code 

Abstract interface for generic read file fn.

Open FST file file and return raw_dic, a dictionary representation of the FST represented there.

The keys of the dictionary are state names, possibly renamed from the original representation. raw_dic[state_name] is a transition function for that state represented as a dictionary.

Two keys are special in transition functions:

  • 'final' takes a boolean value specifying whether this is a final state.
  • 'start' takes a boolean value specifying whether this is a start state. (not used)

All other keys in transition fns are upper lg chars whose values are dictionaries whose keys are lower lg chars:

   raw_dic[state][upper][lower] = the set of states transitioned to
                                  in the state C{state} when upper
                                  char C{char} is paired with lower lg
                                  char C{lower}

Implementations of this method should always call initialize reader first, to zero out all the file-specific attributes of self.

Parameters:
  • file - file containing some representation of an FST.
Returns: dictionary of dictionary of dictionaries

initialize_reader(self)

source code 

Zero out all file specific attributes before compiling a new file.

Called by all implementations of read_file.