47 "Recursively replaces FST arcs with other FST(s).\n\n" 50 usage +=
" root.fst rootlabel [rule1.fst label1 ...] [out.fst]\n";
52 SET_FLAGS(usage.c_str(), &argc, &argv,
true);
58 const std::string out_name = argc % 2 == 0 ? argv[argc - 1] :
"";
60 std::vector<std::pair<int64_t, std::unique_ptr<const FstClass>>> pairs;
61 for (
auto i = 1; i < argc - 1; i += 2) {
62 std::unique_ptr<const FstClass> ifst(FstClass::Read(argv[i]));
66 const auto label = atoll(argv[i + 1]);
67 pairs.emplace_back(label, std::move(ifst));
72 FST_FLAGS_epsilon_on_replace,
74 LOG(ERROR) << argv[0] <<
": Unknown or unsupported call arc replace " 75 <<
"label type: " << FST_FLAGS_call_arc_labeling;
79 FST_FLAGS_epsilon_on_replace,
80 &return_label_type)) {
81 LOG(ERROR) << argv[0] <<
": Unknown or unsupported return arc replace " 82 <<
"label type: " << FST_FLAGS_return_arc_labeling;
85 LOG(ERROR) << argv[0] <<
"At least one replace pair must be provided.";
88 const auto root = pairs.front().first;
89 const s::ReplaceOptions opts(root, call_label_type, return_label_type,
90 FST_FLAGS_return_label);
92 VectorFstClass ofst(pairs.back().second->ArcType());
95 return !ofst.Write(out_name);
void ShowUsage(bool long_usage=true)
DECLARE_string(call_arc_labeling)
DECLARE_int64(return_label)
void Replace(const std::vector< std::pair< int64_t, const FstClass * >> &pairs, MutableFstClass *ofst, std::vector< std::pair< int64_t, int64_t >> *parens, int64_t root, PdtParserType parser_type, int64_t start_paren_labels, const std::string &left_paren_prefix, const std::string &right_paren_prefix)
#define SET_FLAGS(usage, argc, argv, rmflags)
bool GetReplaceLabelType(std::string_view str, bool epsilon_on_replace, ReplaceLabelType *rlt)
int fstreplace_main(int argc, char **argv)
std::vector< std::pair< int64_t, const FstClass * > > BorrowPairs(const std::vector< std::pair< int64_t, std::unique_ptr< const FstClass >>> &pairs)
DECLARE_bool(epsilon_on_replace)