44 using namespace kaldi;
58 "Composition algorithm [between two FSTs of standard type, in tropical\n" 59 "semiring] that is more efficient for certain cases-- in particular,\n" 60 "where one of the FSTs (the left one, if --match-side=left) has large\n" 63 "Usage: fsttablecompose (fst1-rxfilename|fst1-rspecifier) " 64 "(fst2-rxfilename|fst2-rspecifier) [(out-rxfilename|out-rspecifier)]\n";
69 std::string match_side =
"left";
70 std::string compose_filter =
"sequence";
72 po.Register(
"connect", &opts.
connect,
"If true, trim FST before output.");
73 po.Register(
"match-side", &match_side,
"Side of composition to do table " 74 "match, one of: \"left\" or \"right\".");
75 po.Register(
"compose-filter", &compose_filter,
"Composition filter to use, " 76 "one of: \"alt_sequence\", \"auto\", \"match\", \"sequence\"");
80 if (match_side ==
"left") {
82 }
else if (match_side ==
"right") {
85 KALDI_ERR <<
"Invalid match-side option: " << match_side;
88 if (compose_filter ==
"alt_sequence") {
90 }
else if (compose_filter ==
"auto") {
92 }
else if (compose_filter ==
"match") {
94 }
else if (compose_filter ==
"sequence") {
97 KALDI_ERR <<
"Invalid compose-filter option: " << compose_filter;
100 if (po.NumArgs() < 2 || po.NumArgs() > 3) {
105 std::string fst1_in_str = po.GetArg(1),
106 fst2_in_str = po.GetArg(2),
107 fst_out_str = po.GetOptArg(3);
119 if (is_table_out != (is_table_1 || is_table_2))
120 KALDI_ERR <<
"Incompatible combination of archives and files";
122 if (!is_table_1 && !is_table_2) {
128 if (fst1->Properties(fst::kOLabelSorted,
true) == 0) {
129 KALDI_WARN <<
"The first FST is not olabel sorted.";
131 if (fst2->Properties(fst::kILabelSorted,
true) == 0) {
132 KALDI_WARN <<
"The second FST is not ilabel sorted.";
135 VectorFst<StdArc> composed_fst;
144 }
else if (!is_table_1 && is_table_2
154 if (fst1->Properties(fst::kOLabelSorted,
true) == 0) {
155 KALDI_WARN <<
"The first FST is not olabel sorted.";
157 for (; !fst2_reader.Done(); fst2_reader.Next(), n_done++) {
158 VectorFst<StdArc> fst2(fst2_reader.Value());
159 VectorFst<StdArc> fst_out;
161 fst_writer.Write(fst2_reader.Key(), fst_out);
163 KALDI_LOG <<
"Composed " << n_done <<
" FSTs.";
164 return (n_done != 0 ? 0 : 1);
165 }
else if (is_table_1 && is_table_2) {
169 int32 n_done = 0, n_err = 0;
170 for (; !fst1_reader.Done(); fst1_reader.Next()) {
171 std::string key = fst1_reader.Key();
172 if (!fst2_reader.HasKey(key)) {
173 KALDI_WARN <<
"No such key " << key <<
" in second table.";
176 const VectorFst<StdArc> &fst1(fst1_reader.Value()),
177 &fst2(fst2_reader.Value(key));
178 VectorFst<StdArc> result;
180 if (result.NumStates() == 0) {
184 fst_writer.Write(key, result);
189 KALDI_LOG <<
"Successfully composed " << n_done <<
" FSTs, errors or " 190 <<
"empty output on " << n_err;
192 KALDI_ERR <<
"The combination of tables/non-tables and match-type that you " 193 <<
"supplied is not currently supported. Either implement this, " 194 <<
"ask the maintainers to implement it, or call this program " 197 }
catch(
const std::exception &e) {
198 std::cerr << e.what();
This code computes Goodness of Pronunciation (GOP) and extracts phone-level pronunciation feature for...
void TableCompose(const Fst< Arc > &ifst1, const Fst< Arc > &ifst2, MutableFst< Arc > *ofst, const TableComposeOptions &opts=TableComposeOptions())
For an extended explanation of the framework of which grammar-fsts are a part, please see Support for...
A templated class for writing objects to an archive or script file; see The Table concept...
RspecifierType ClassifyRspecifier(const std::string &rspecifier, std::string *rxfilename, RspecifierOptions *opts)
Allows random access to a collection of objects in an archive or script file; see The Table concept...
TableComposeCache lets us do multiple compositions while caching the same matcher.
The class ParseOptions is for parsing command-line options; see Parsing command-line options for more...
ComposeFilter filter_type
A templated class for reading objects sequentially from an archive or script file; see The Table conc...
WspecifierType ClassifyWspecifier(const std::string &wspecifier, std::string *archive_wxfilename, std::string *script_wxfilename, WspecifierOptions *opts)
MatchType table_match_type
void WriteFstKaldi(std::ostream &os, bool binary, const VectorFst< Arc > &t)
void ReadFstKaldi(std::istream &is, bool binary, VectorFst< Arc > *fst)