19 #include <fst/flags.h> 21 #include <fst/fst-decl.h> 23 #include <fst/mutable-fst.h> 24 #include <fst/properties.h> 28 "Specifies failure label (default: none)");
30 "Removes inaccessible transitions due to failure labels");
32 "Removes ApproxZero() weight transitions");
34 "Removes ApproxZero() weight transitions wrt the phi-summed SFST");
36 "Include phi transitions when weight trimming");
38 "Removes inaccessible/non-accessible states treating" 39 " failure labels as regular labels");
40 DEFINE_string(trim_type,
"needed_final",
"Trim type, one of: " 41 "\"needed_trim\", \"needed_final\", " 45 int main(
int argc,
char **argv) {
47 std::string usage =
"Removes useless states and transitions in stochastic ";
48 usage +=
" automata.\n\n Usage: ";
50 usage +=
" [in.fst [out.fst]]\n";
52 SET_FLAGS(usage.c_str(), &argc, &argv,
true);
59 (argc > 1 && (strcmp(argv[1],
"-") != 0)) ? argv[1] :
"";
60 std::string out_name = argc > 2 ? argv[2] :
"";
62 f::StdMutableFst *
fst = f::StdMutableFst::Read(in_name,
true);
66 if (FST_FLAGS_trim_type ==
"needed_trim") {
68 }
else if (FST_FLAGS_trim_type ==
"needed_final") {
70 }
else if (FST_FLAGS_trim_type ==
"needed_nonfinal") {
74 <<
": Bad trim type: " << FST_FLAGS_trim_type;
80 if (FST_FLAGS_phi_trim) trim.
PhiTrim();
82 if (FST_FLAGS_weight_trim)
86 if (FST_FLAGS_sum_weight_trim)
90 if (FST_FLAGS_connect) trim.
Connect();
94 if (fst->Properties(f::kError,
false)) {
95 LOG(ERROR) << argv[0] <<
": trimming failed";
99 if (!fst->Write(out_name))
DEFINE_bool(phi_trim, true,"Removes inaccessible transitions due to failure labels")
int main(int argc, char **argv)
void WeightTrim(bool include_phi, Weight approx_zero=ApproxZeroWeight())
void SumWeightTrim(bool include_phi, Weight approx_zero=ApproxZeroWeight())
DEFINE_string(trim_type,"needed_final","Trim type, one of: ""\"needed_trim\", \"needed_final\", ""\"needed_nonfinal")
DEFINE_double(weight, 99.0,"Weight threshold")
DEFINE_int64(phi_label, fst::kNoLabel,"Specifies failure label (default: none)")