27 int main(
int argc,
char *argv[]) {
29 using namespace kaldi;
34 "Convert lattices so that the arcs in the CompactLattice format correspond with\n" 35 "words (i.e. aligned with word boundaries). Note: it will generally be more\n" 36 "efficient if you apply 'lattice-push' before this program.\n" 37 "Usage: lattice-align-words [options] <word-boundary-file> <model> <lattice-rspecifier> <lattice-wspecifier>\n" 38 " e.g.: lattice-align-words --silence-label=4320 --partial-word-label=4324 \\\n" 39 " data/lang/phones/word_boundary.int final.mdl ark:1.lats ark:aligned.lats\n" 40 "Note: word-boundary file has format (on each line):\n" 41 "<integer-phone-id> [begin|end|singleton|internal|nonword]\n" 42 "See also: lattice-align-words-lexicon, for use in cases where phones\n" 43 "don't have word-position information.\n";
47 bool output_if_error =
true;
50 po.
Register(
"output-error-lats", &output_if_error,
"Output lattices that aligned " 51 "with errors (e.g. due to force-out");
52 po.
Register(
"test", &do_test,
"Test the algorithm while running it.");
53 po.
Register(
"max-expand", &max_expand,
"If >0, the maximum amount by which this " 54 "program will expand lattices before refusing to continue. E.g. 10." 55 "This can be used to prevent this program consuming excessive memory " 56 "if there is a mismatch on the command-line or a 'problem' lattice.");
69 word_boundary_rxfilename = po.
GetArg(1),
70 model_rxfilename = po.
GetArg(2),
71 lats_rspecifier = po.
GetArg(3),
72 lats_wspecifier = po.
GetArg(4);
82 int32 num_done = 0, num_err = 0;
84 for (; !clat_reader.
Done(); clat_reader.
Next()) {
85 std::string key = clat_reader.
Key();
90 if (max_expand > 0) max_states = 1000 + max_expand * clat.NumStates();
100 if (!output_if_error)
102 <<
" did not align correctly, producing no output.";
104 if (aligned_clat.Start() != fst::kNoStateId) {
105 KALDI_WARN <<
"Outputting partial lattice for " << key;
107 clat_writer.
Write(key, aligned_clat);
109 KALDI_WARN <<
"Empty aligned lattice for " << key
110 <<
", producing no output.";
114 if (aligned_clat.Start() == fst::kNoStateId) {
116 KALDI_WARN <<
"Lattice was empty for key " << key;
119 KALDI_VLOG(2) <<
"Aligned lattice for " << key;
121 clat_writer.
Write(key, aligned_clat);
125 KALDI_LOG <<
"Successfully aligned " << num_done <<
" lattices; " 126 << num_err <<
" had errors.";
127 return (num_done > num_err ? 0 : 1);
130 }
catch(
const std::exception &e) {
131 std::cerr << e.what();
This code computes Goodness of Pronunciation (GOP) and extracts phone-level pronunciation feature for...
void PrintUsage(bool print_command_line=false)
Prints the usage documentation [provided in the constructor].
A templated class for writing objects to an archive or script file; see The Table concept...
bool WordAlignLattice(const CompactLattice &lat, const TransitionModel &tmodel, const WordBoundaryInfo &info, int32 max_states, CompactLattice *lat_out)
Align lattice so that each arc has the transition-ids on it that correspond to the word that is on th...
void Write(const std::string &key, const T &value) const
void Register(const std::string &name, bool *ptr, const std::string &doc)
static bool TestWordAlignedLattice(const WordAlignLatticeLexiconInfo &lexicon_info, const TransitionModel &tmodel, CompactLattice clat, CompactLattice aligned_clat, bool allow_duplicate_paths)
void ReadKaldiObject(const std::string &filename, Matrix< float > *m)
int main(int argc, char *argv[])
The class ParseOptions is for parsing command-line options; see Parsing command-line options for more...
void Register(OptionsItf *opts)
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).
void TopSortCompactLatticeIfNeeded(CompactLattice *clat)
Topologically sort the compact lattice if not already topologically sorted.