21 #include <fst/flags.h> 23 #include <fst/extensions/far/far-class.h> 24 #include <fst/extensions/far/far.h> 26 #include <fst/script/fst-class.h> 32 using fst::script::FarReaderClass;
33 using fst::script::FarWriterClass;
34 using fst::script::FstClass;
36 std::string usage =
"Decodes a WFST model\n\n Usage: ";
38 usage +=
" input.f(ar|st) output.far model.fst [out.far]\n";
40 SET_FLAGS(usage.c_str(), &argc, &argv,
true);
42 if (argc < 4 || argc > 5) {
47 const std::string input_name = strcmp(argv[1],
"-") != 0 ? argv[1] :
"";
48 const std::string output_name = strcmp(argv[2],
"-") != 0 ? argv[2] :
"";
49 const std::string model_name = strcmp(argv[3],
"-") != 0 ? argv[3] :
"";
50 const std::string hypotext_name = argc > 4 ? argv[4] :
"";
52 if (input_name.empty() && (output_name.empty() || model_name.empty())) {
53 LOG(ERROR) << argv[0] <<
": Can't take more than one input from standard " 57 if (output_name.empty() && model_name.empty()) {
58 LOG(ERROR) << argv[0] <<
": Can't take more than one input from standard " 63 const std::unique_ptr<FarReaderClass> input(FarReaderClass::Open(input_name));
66 const std::unique_ptr<FarReaderClass> output(
67 FarReaderClass::Open(output_name));
68 if (!output)
return 1;
70 const std::unique_ptr<const FstClass> model(FstClass::Read(model_name));
73 const std::unique_ptr<FarWriterClass> hypotext(
74 FarWriterClass::Create(hypotext_name, output->ArcType()));
75 if (!hypotext)
return 1;
77 s::Decode(*input, *output, *model, *hypotext);
80 FSTERROR() <<
"Error reading FAR: " << input_name;
83 if (output->Error()) {
84 FSTERROR() <<
"Error reading FAR: " << output_name;
87 if (hypotext->Error()) {
88 FSTERROR() <<
"Error writing FAR: " << hypotext_name;
void Decode(FarReader< Arc > &input, FarReader< Arc > &output, const Fst< Arc > &model, FarWriter< Arc > &hypotext)
int baumwelchdecode_main(int argc, char **argv)