44 std::string usage =
"Expand a (bounded-stack) PDT as an FST.\n\n Usage: ";
46 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_pdt_parentheses.empty()) {
64 LOG(ERROR) << argv[0] <<
": No PDT parenthesis label pairs provided";
68 std::vector<std::pair<int64, int64>> parens;
72 const auto weight_threshold =
73 FST_FLAGS_weight.empty()
74 ? WeightClass::Zero(ifst->WeightType())
75 : WeightClass(ifst->WeightType(), FST_FLAGS_weight);
77 VectorFstClass ofst(ifst->ArcType());
79 s::PdtExpandOptions(FST_FLAGS_connect,
80 FST_FLAGS_keep_parentheses,
83 return !ofst.Write(out_name);
void ShowUsage(bool long_usage=true)
int pdtexpand_main(int argc, char **argv)
#define SET_FLAGS(usage, argc, argv, rmflags)
bool ReadLabelPairs(const std::string &source, std::vector< std::pair< Label, Label >> *pairs, bool allow_negative=false)
void PdtExpand(const FstClass &ifst, const std::vector< std::pair< int64, int64 >> &parens, MutableFstClass *ofst, const PdtExpandOptions &opts)
DECLARE_string(pdt_parentheses)