24 int main(
int argc,
char *argv[]) {
26 using namespace kaldi;
28 typedef kaldi::int64 int64;
29 using fst::SymbolTable;
34 "Expand lattices so that each arc has a unique n-label history, for\n" 35 "a specified n (defaults to 3).\n" 36 "Usage: lattice-expand-ngram [options] lattice-rspecifier " 37 "lattice-wspecifier\n" 38 "e.g.: lattice-expand-ngram --n=3 ark:lat ark:expanded_lat\n";
43 std::string word_syms_filename;
44 po.
Register(
"n", &n,
"n-gram context to expand to.");
55 std::string lats_rspecifier = po.
GetArg(1),
63 int32 n_done = 0, n_fail = 0;
65 for (; !lat_reader.
Done(); lat_reader.
Next()) {
66 std::string key = lat_reader.
Key();
67 KALDI_LOG <<
"Processing lattice for key " << key;
71 if (expanded_lat.Start() == fst::kNoStateId) {
72 KALDI_WARN <<
"Empty lattice for utterance " << key;
75 if (lat.NumStates() == expanded_lat.NumStates()) {
77 <<
" did not need to be expanded for order " << n <<
".";
79 KALDI_LOG <<
"Lattice expanded from " << lat.NumStates() <<
" to " 80 << expanded_lat.NumStates() <<
" states for order " << n <<
".";
82 lat_writer.
Write(key, expanded_lat);
87 KALDI_LOG <<
"Processed " << n_done <<
" lattices with " << n_fail
90 }
catch(
const std::exception &e) {
91 std::cerr << e.what();
This code computes Goodness of Pronunciation (GOP) and extracts phone-level pronunciation feature for...
void ComposeDeterministicOnDemand(const Fst< Arc > &fst1, DeterministicOnDemandFst< Arc > *fst2, MutableFst< Arc > *fst_composed)
void PrintUsage(bool print_command_line=false)
Prints the usage documentation [provided in the constructor].
int main(int argc, char *argv[])
A templated class for writing objects to an archive or script file; see The Table concept...
void Write(const std::string &key, const T &value) const
void Register(const std::string &name, bool *ptr, const std::string &doc)
The class ParseOptions is for parsing command-line options; see Parsing command-line options for more...
A templated class for reading objects sequentially from an archive or script file; see The Table conc...
int Read(int argc, const char *const *argv)
Parses the command line options and fills the ParseOptions-registered variables.
std::string GetArg(int param) const
Returns one of the positional parameters; 1-based indexing for argc/argv compatibility.
fst::VectorFst< CompactLatticeArc > CompactLattice
int NumArgs() const
Number of positional parameters (c.f. argc-1).
The class UnweightedNgramFst is a DeterministicOnDemandFst whose states encode an n-gram history...
#define KALDI_ASSERT(cond)
fst::ArcTpl< CompactLatticeWeight > CompactLatticeArc
std::string GetOptArg(int param) const