48 std::string usage =
"Compose a PDT and an FST.\n\n Usage: ";
50 usage +=
" in.pdt in.fst [out.pdt]\n";
51 usage +=
" in.fst in.pdt [out.pdt]\n";
53 SET_FLAGS(usage.c_str(), &argc, &argv,
true);
54 if (argc < 3 || argc > 4) {
59 const std::string in1_name = strcmp(argv[1],
"-") == 0 ?
"" : argv[1];
60 const std::string in2_name = strcmp(argv[2],
"-") == 0 ?
"" : argv[2];
61 const std::string out_name =
62 argc > 3 && strcmp(argv[3],
"-") != 0 ? argv[3] :
"";
64 if (in1_name.empty() && in2_name.empty()) {
65 LOG(ERROR) << argv[0] <<
": Can't take both inputs from standard input.";
69 std::unique_ptr<FstClass> ifst1(FstClass::Read(in1_name));
71 std::unique_ptr<FstClass> ifst2(FstClass::Read(in2_name));
74 if (FST_FLAGS_pdt_parentheses.empty()) {
75 LOG(ERROR) << argv[0] <<
": No PDT parenthesis label pairs provided";
79 std::vector<std::pair<int64_t, int64_t>> parens;
82 VectorFstClass ofst(ifst1->ArcType());
87 LOG(ERROR) << argv[0] <<
": Unknown or unsupported compose filter type: " 88 << FST_FLAGS_compose_filter;
92 const PdtComposeOptions copts(FST_FLAGS_connect, compose_filter);
94 s::Compose(*ifst1, *ifst2, parens, &ofst, copts,
97 return !ofst.Write(out_name);
void ShowUsage(bool long_usage=true)
DECLARE_string(pdt_parentheses)
#define SET_FLAGS(usage, argc, argv, rmflags)
int pdtcompose_main(int argc, char **argv)
bool GetPdtComposeFilter(std::string_view str, PdtComposeFilter *cf)
bool ReadLabelPairs(std::string_view source, std::vector< std::pair< Label, Label >> *pairs)
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)