#include <util.H>
Public Member Functions | |
Graph (const string &fileName=string(), const string &symFile=string()) | |
Ctor; loads from file fileName if argument present, and loads sym table from file symFile if argument present. | |
void | read (const string &fileName, const string &symFile=string()) |
Reads graph from file fileName . | |
string | read (istream &inStrm, const string &name=string()) |
Reads graph from stream inStrm . | |
void | write (const string &fileName) const |
Writes graph to file fileName . | |
void | write (ostream &outStrm, const string &name=string()) const |
Writes graph to stream outStrm . | |
void | read_word_sym_table (const string &symFile) |
Reads word symbol table from file symFile . | |
void | clear () |
Clears object except for symbol table; i.e., delete all states and arcs. | |
bool | empty () const |
Returns whether there are no states. | |
const SymbolTable & | get_word_sym_table () const |
Returns a reference to the word symbol table. | |
unsigned | get_gmm_count () const |
Returns one above highest GMM index in graph. | |
unsigned | get_state_count () const |
Returns total number of states. | |
int | get_start_state () const |
Returns index of start state, or -1 if unset. | |
unsigned | get_arc_count (unsigned stateIdx) const |
Returns number of outgoing arcs for state stateIdx . | |
unsigned | get_first_arc_id (unsigned stateIdx) const |
Returns arc ID of first outgoing arc of state stateIdx . | |
unsigned | get_arc (unsigned arcId, Arc &arc) const |
Places arc with ID arcId in arc . | |
unsigned | get_src_state (unsigned arcId) const |
Returns src state of an arc given its ID. | |
bool | is_final_state (unsigned stateIdx) const |
Returns wheter state stateIdx is final state. | |
double | get_final_log_prob (unsigned stateIdx) const |
Returns final log prob (base e) of state stateIdx or g_zeroLogProb if not final. | |
unsigned | get_final_state_list (vector< int > &stateList) const |
Returns number of final states; places list in stateList . |
This object holds a graph as needed for training or decoding. A graph has a set of states numbered starting from 0 (see get_state_count()), one of which is a start state (see get_start_state()), and many of which may be final states (see is_final_state(), get_final_state_list()). Final states have an associated final log prob (see get_final_log_prob()).
For each state, you can access the list of outgoing arcs using get_arc_count(), get_first_arc_id(), and get_arc(). Each arc has an associated ID, which is used for iterating through arcs. Here is an example of how to iterate through the outgoing arcs of state stateIdx
of graph graph
.
// Get number of outgoing arcs. int arcCnt = graph.get_arc_count(stateIdx); // Get arc ID of first outgoing arc. int arcId = graph.get_first_arc_id(stateIdx); for (int arcIdx = 0; arcIdx < arcCnt; ++arcIdx) { Arc arc; // Place arc with ID "arcId" in "arc"; set "arcId" // to arc ID of the next outgoing arc. arcId = graph.get_arc(arcId, arc); // You can now access elements of the Arc "arc", e.g., int dstState = arc.get_dst_state(); ... }
void Graph::read | ( | const string & | fileName, | |
const string & | symFile = string() | |||
) |
Reads graph from file fileName
.
Reads symbol table from file symFile
if not empty string.
string Graph::read | ( | istream & | inStrm, | |
const string & | name = string() | |||
) |
Reads graph from stream inStrm
.
If argument name
is provided, checks that name associated with graph matches. Returns name given in graph header, or empty string if none provided.
void Graph::write | ( | const string & | fileName | ) | const |
Writes graph to file fileName
.
void Graph::write | ( | ostream & | outStrm, | |
const string & | name = string() | |||
) | const |
Writes graph to stream outStrm
.
If the argument name
is provided, this name will be written in the graph header.
void Graph::read_word_sym_table | ( | const string & | symFile | ) |
Reads word symbol table from file symFile
.
Pass in the empty string to load an empty symbol table.
bool Graph::empty | ( | ) | const [inline] |
Returns whether there are no states.
const SymbolTable& Graph::get_word_sym_table | ( | ) | const [inline] |
Returns a reference to the word symbol table.
unsigned Graph::get_gmm_count | ( | ) | const |
Returns one above highest GMM index in graph.
unsigned Graph::get_state_count | ( | ) | const [inline] |
Returns total number of states.
int Graph::get_start_state | ( | ) | const [inline] |
Returns index of start state, or -1 if unset.
unsigned Graph::get_arc_count | ( | unsigned | stateIdx | ) | const [inline] |
Returns number of outgoing arcs for state stateIdx
.
States are numbered from 0.
unsigned Graph::get_first_arc_id | ( | unsigned | stateIdx | ) | const [inline] |
Returns arc ID of first outgoing arc of state stateIdx
.
States are numbered from 0.
unsigned Graph::get_arc | ( | unsigned | arcId, | |
Arc & | arc | |||
) | const [inline] |
Places arc with ID arcId
in arc
.
Returns ID of next outgoing arc of same state.
unsigned Graph::get_src_state | ( | unsigned | arcId | ) | const |
Returns src state of an arc given its ID.
bool Graph::is_final_state | ( | unsigned | stateIdx | ) | const [inline] |
Returns wheter state stateIdx
is final state.
States are numbered from 0.
double Graph::get_final_log_prob | ( | unsigned | stateIdx | ) | const [inline] |
Returns final log prob (base e) of state stateIdx
or g_zeroLogProb if not final.
States are numbered from 0.
unsigned Graph::get_final_state_list | ( | vector< int > & | stateList | ) | const [inline] |
Returns number of final states; places list in stateList
.