41 std::string usage =
"Composes two FSTs.\n\n Usage: ";
43 usage +=
" in1.fst in2.fst [out.fst]\n";
45 SET_FLAGS(usage.c_str(), &argc, &argv,
true);
46 if (argc < 3 || argc > 4) {
51 const std::string in1_name = strcmp(argv[1],
"-") != 0 ? argv[1] :
"";
52 const std::string in2_name =
53 (argc > 2 && (strcmp(argv[2],
"-") != 0)) ? argv[2] :
"";
54 const std::string out_name =
55 (argc > 3 && (strcmp(argv[3],
"-") != 0)) ? argv[3] :
"";
57 if (in1_name.empty() && in2_name.empty()) {
58 LOG(ERROR) << argv[0] <<
": Can't take both inputs from standard input";
62 std::unique_ptr<FstClass> ifst1(FstClass::Read(in1_name));
65 std::unique_ptr<FstClass> ifst2(FstClass::Read(in2_name));
68 if (ifst1->ArcType() != ifst2->ArcType()) {
69 LOG(ERROR) << argv[0] <<
": Input FSTs must have the same arc type";
73 VectorFstClass ofst(ifst1->ArcType());
78 LOG(ERROR) << argv[0] <<
": Unknown or unsupported compose filter type: " 79 << FST_FLAGS_compose_filter;
83 const ComposeOptions opts(FST_FLAGS_connect, compose_filter);
87 return !ofst.Write(out_name);
void ShowUsage(bool long_usage=true)
#define SET_FLAGS(usage, argc, argv, rmflags)
bool GetComposeFilter(std::string_view str, ComposeFilter *compose_filter)
DECLARE_string(compose_filter)
int fstcompose_main(int argc, char **argv)
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)