42 "Applies an operation to each arc of an FST.\n\n Usage: ";
44 usage +=
" [in.fst [out.fst]]\n";
46 SET_FLAGS(usage.c_str(), &argc, &argv,
true);
52 const std::string in_name =
53 (argc > 1 && strcmp(argv[1],
"-") != 0) ? argv[1] :
"";
54 const std::string out_name =
55 (argc > 2 && strcmp(argv[2],
"-") != 0) ? argv[2] :
"";
57 std::unique_ptr<FstClass> ifst(FstClass::Read(in_name));
62 LOG(ERROR) << argv[0] <<
": Unknown or unsupported map type " 63 << FST_FLAGS_map_type;
67 const auto weight_param =
68 !FST_FLAGS_weight.empty()
69 ? WeightClass(ifst->WeightType(), FST_FLAGS_weight)
70 : (FST_FLAGS_map_type ==
"times" 71 ? WeightClass::One(ifst->WeightType())
72 : WeightClass::Zero(ifst->WeightType()));
74 std::unique_ptr<FstClass> ofst(
75 s::Map(*ifst, map_type, FST_FLAGS_delta,
76 FST_FLAGS_power, weight_param));
78 return !ofst->Write(out_name);
void ShowUsage(bool long_usage=true)
bool GetMapType(std::string_view str, MapType *map_type)
void Map(FarReader< Arc > &reader, FarWriter< Arc > &writer, Functor functor)
#define SET_FLAGS(usage, argc, argv, rmflags)
int fstmap_main(int argc, char **argv)