28 const std::vector<int32> &
words,
35 lat_out->DeleteStates();
36 StateId cur_state = lat_out->AddState();
37 lat_out->SetStart(cur_state);
38 for (
size_t i = 0;
i < ali.size() ||
i < words.size();
i++) {
39 Label ilabel = (
i < ali.size() ? ali[
i] : 0);
40 Label olabel = (
i < words.size() ? words[
i] : 0);
41 StateId next_state = lat_out->AddState();
42 lat_out->AddArc(cur_state,
43 LatticeArc(ilabel, olabel, Weight::One(), next_state));
44 cur_state = next_state;
46 lat_out->SetFinal(cur_state,
Weight(lm_cost, ac_cost));
50 int main(
int argc,
char *argv[]) {
52 using namespace kaldi;
54 typedef kaldi::int64 int64;
55 using fst::SymbolTable;
60 "This does the opposite of nbest-to-linear. It takes 4 archives,\n" 61 "containing alignments, word-sequences, and acoustic and LM costs,\n" 62 "and turns it into a single archive containing FSTs with a linear\n" 63 "structure. The program is called linear-to-nbest because very often\n" 64 "the archives concerned will represent N-best lists\n" 65 "Usage: linear-to-nbest [options] <alignments-rspecifier> " 66 "<transcriptions-rspecifier> (<lm-cost-rspecifier>|'') (<ac-cost-rspecifier>|'') " 67 "<nbest-wspecifier>\n" 68 "Note: if the rspecifiers for lm-cost or ac-cost are the empty string,\n" 69 "these value will default to zero.\n" 70 " e.g.: linear-to-nbest ark:1.ali 'ark:sym2int.pl -f 2- words.txt text|' " 71 "ark:1.lmscore ark:1.acscore " 83 std::string ali_rspecifier = po.
GetArg(1),
84 trans_rspecifier = po.
GetArg(2),
85 lm_cost_rspecifier = po.
GetArg(3),
86 ac_cost_rspecifier = po.
GetArg(4),
87 lats_wspecifier = po.
GetArg(5);
98 int32 n_done = 0, n_err = 0;
100 for (; !ali_reader.
Done(); ali_reader.
Next()) {
101 std::string key = ali_reader.
Key();
102 if (!trans_reader.
HasKey(key)) {
103 KALDI_ERR <<
"No transcription for key " << key;
107 if (lm_cost_rspecifier !=
"" && !lm_cost_reader.
HasKey(key)) {
108 KALDI_ERR <<
"No LM cost for key " << key;
112 if (ac_cost_rspecifier !=
"" && !ac_cost_reader.
HasKey(key)) {
113 KALDI_ERR <<
"No acoustic cost for key " << key;
117 const std::vector<int32> &ali = ali_reader.
Value();
118 const std::vector<int32> &
words = trans_reader.
Value(key);
120 ac_cost = (ac_cost_rspecifier ==
"") ? 0.0 : ac_cost_reader.
Value(key),
121 lm_cost = (lm_cost_rspecifier ==
"") ? 0.0 : lm_cost_reader.
Value(key);
127 compact_lattice_writer.
Write(key, clat);
130 KALDI_LOG <<
"Done " << n_done <<
" n-best entries ," 131 << n_err <<
" had errors.";
132 return (n_done != 0 ? 0 : 1);
133 }
catch(
const std::exception &e) {
134 std::cerr << e.what();
fst::StdArc::StateId StateId
This code computes Goodness of Pronunciation (GOP) and extracts phone-level pronunciation feature for...
fst::ArcTpl< LatticeWeight > LatticeArc
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...
void Write(const std::string &key, const T &value) const
Allows random access to a collection of objects in an archive or script file; see The Table concept...
void MakeLatticeFromLinear(const std::vector< int32 > &ali, const std::vector< int32 > &words, BaseFloat lm_cost, BaseFloat ac_cost, Lattice *lat_out)
The class ParseOptions is for parsing command-line options; see Parsing command-line options for more...
const T & Value(const std::string &key)
void ConvertLattice(const ExpandedFst< ArcTpl< Weight > > &ifst, MutableFst< ArcTpl< CompactLatticeWeightTpl< Weight, Int > > > *ofst, bool invert)
Convert lattice from a normal FST to a CompactLattice FST.
A templated class for reading objects sequentially from an archive or script file; see The Table conc...
fst::VectorFst< LatticeArc > Lattice
int Read(int argc, const char *const *argv)
Parses the command line options and fills the ParseOptions-registered variables.
int main(int argc, char *argv[])
std::string GetArg(int param) const
Returns one of the positional parameters; 1-based indexing for argc/argv compatibility.
bool HasKey(const std::string &key)
fst::VectorFst< CompactLatticeArc > CompactLattice
fst::StdArc::Weight Weight
int NumArgs() const
Number of positional parameters (c.f. argc-1).