27 int main(
int argc,
char *argv[]) {
29 using namespace kaldi;
32 typedef kaldi::uint64 uint64;
35 "Reads a kaldi archive of FSTs. Performs the FST operation union on\n" 36 "all fsts sharing the same key. Assumes the archive is sorted by key.\n" 38 "Usage: fsts-union [options] <fsts-rspecifier> <fsts-wspecifier>\n" 39 " e.g.: fsts-union ark:keywords_tmp.fsts ark,t:keywords.fsts\n" 41 "see also: fstunion (from the OpenFst toolkit)\n";
52 std::string fsts_rspecifier = po.
GetArg(1),
53 fsts_wspecifier = po.
GetArg(2);
61 std::string res_key =
"";
62 VectorFst<StdArc> res_fst;
64 for (; !fst_reader.
Done(); fst_reader.
Next()) {
65 std::string key = fst_reader.
Key();
66 VectorFst<StdArc>
fst(fst_reader.
Value());
70 fst::Union(&res_fst,
fst);
73 VectorFst<StdArc> out_fst;
74 fst::Determinize(res_fst, &out_fst);
75 fst::Minimize(&out_fst);
76 fst::RmEpsilon(&out_fst);
77 fst_writer.
Write(res_key, out_fst);
85 VectorFst<StdArc> out_fst;
86 fst::Determinize(res_fst, &out_fst);
87 fst::Minimize(&out_fst);
88 fst::RmEpsilon(&out_fst);
89 fst_writer.
Write(res_key, out_fst);
93 KALDI_LOG <<
"Applied fst union on " << n_in_done
94 <<
" FSTs, produced " << n_out_done <<
" FSTs";
95 return (n_out_done != 0 ? 0 : 1);
96 }
catch(
const std::exception &e) {
97 std::cerr << e.what();
This code computes Goodness of Pronunciation (GOP) and extracts phone-level pronunciation feature for...
For an extended explanation of the framework of which grammar-fsts are a part, please see Support for...
int main(int argc, char *argv[])
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
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.
int NumArgs() const
Number of positional parameters (c.f. argc-1).