49 std::string usage =
"Compose an MPDT and an FST.\n\n Usage: ";
51 usage +=
" in.pdt in.fst [out.mpdt]\n";
52 usage +=
" in.fst in.pdt [out.mpdt]\n";
54 SET_FLAGS(usage.c_str(), &argc, &argv,
true);
55 if (argc < 3 || argc > 4) {
60 const std::string in1_name = strcmp(argv[1],
"-") == 0 ?
"" : argv[1];
61 const std::string in2_name = strcmp(argv[2],
"-") == 0 ?
"" : argv[2];
62 const std::string out_name =
63 argc > 3 && strcmp(argv[3],
"-") != 0 ? argv[3] :
"";
65 if (in1_name.empty() && in2_name.empty()) {
66 LOG(ERROR) << argv[0] <<
": Can't take both inputs from standard input.";
70 std::unique_ptr<FstClass> ifst1(FstClass::Read(in1_name));
72 std::unique_ptr<FstClass> ifst2(FstClass::Read(in2_name));
75 if (FST_FLAGS_mpdt_parentheses.empty()) {
76 LOG(ERROR) << argv[0] <<
": No MPDT parenthesis label pairs provided";
80 std::vector<std::pair<int64_t, int64_t>> parens;
81 std::vector<int64_t> assignments;
87 VectorFstClass ofst(ifst1->ArcType());
92 LOG(ERROR) << argv[0] <<
": Unknown or unsupported compose filter type: " 93 << FST_FLAGS_compose_filter;
97 const MPdtComposeOptions opts(FST_FLAGS_connect, compose_filter);
99 s::Compose(*ifst1, *ifst2, parens, assignments, &ofst, opts,
100 FST_FLAGS_left_mpdt);
102 return !ofst.Write(out_name);
void ShowUsage(bool long_usage=true)
int mpdtcompose_main(int argc, char **argv)
DECLARE_string(mpdt_parentheses)
#define SET_FLAGS(usage, argc, argv, rmflags)
bool ReadLabelTriples(const std::string &source, std::vector< std::pair< Label, Label >> *pairs, std::vector< Label > *assignments)
bool GetPdtComposeFilter(std::string_view str, PdtComposeFilter *cf)
void Compose(const FstClass &ifst1, const FstClass &ifst2, const std::vector< std::pair< int64_t, int64_t >> &parens, const std::vector< int64_t > &assignments, MutableFstClass *ofst, const MPdtComposeOptions &copts, bool left_pdt)