45 std::string usage =
"Expand a (bounded-stack) MPDT as an FST.\n\n Usage: ";
47 usage +=
" in.pdt [out.fst]\n";
49 SET_FLAGS(usage.c_str(), &argc, &argv,
true);
55 const std::string in_name =
56 (argc > 1 && (strcmp(argv[1],
"-") != 0)) ? argv[1] :
"";
57 const std::string out_name =
58 (argc > 2 && (strcmp(argv[2],
"-") != 0)) ? argv[2] :
"";
60 std::unique_ptr<FstClass> ifst(FstClass::Read(in_name));
63 if (FST_FLAGS_mpdt_parentheses.empty()) {
64 LOG(ERROR) << argv[0] <<
": No MPDT parenthesis label pairs provided";
68 std::vector<std::pair<int64_t, int64_t>> parens;
69 std::vector<int64_t> assignments;
75 VectorFstClass ofst(ifst->ArcType());
77 const MPdtExpandOptions opts(FST_FLAGS_connect,
78 FST_FLAGS_keep_parentheses);
80 s::Expand(*ifst, parens, assignments, &ofst, opts);
82 return !ofst.Write(out_name);
void ShowUsage(bool long_usage=true)
#define SET_FLAGS(usage, argc, argv, rmflags)
bool ReadLabelTriples(const std::string &source, std::vector< std::pair< Label, Label >> *pairs, std::vector< Label > *assignments)
void Expand(const FstClass &ifst, const std::vector< std::pair< int64_t, int64_t >> &parens, const std::vector< int64_t > &assignments, MutableFstClass *ofst, const MPdtExpandOptions &opts)
DECLARE_string(mpdt_parentheses)
int mpdtexpand_main(int argc, char **argv)