39 std::string usage =
"Intersects two FSAs.\n\n Usage: ";
41 usage +=
" in1.fst in2.fst [out.fst]\n";
42 usage +=
" Flags: connect\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 = strcmp(argv[2],
"-") == 0 ?
"" : argv[2];
53 const std::string out_name =
54 argc > 3 && strcmp(argv[3],
"-") != 0 ? argv[3] :
"";
56 if (in1_name.empty() && in2_name.empty()) {
57 LOG(ERROR) << argv[0] <<
": Can't take both inputs from standard input";
61 std::unique_ptr<FstClass> ifst1(FstClass::Read(in1_name));
63 std::unique_ptr<FstClass> ifst2(FstClass::Read(in2_name));
66 VectorFstClass ofst(ifst1->ArcType());
71 LOG(ERROR) << argv[0] <<
": Unknown or unsupported compose filter type: " 72 << FST_FLAGS_compose_filter;
80 return !ofst.Write(out_name);
void ShowUsage(bool long_usage=true)
int fstintersect_main(int argc, char **argv)
void Intersect(const Fst< Arc > &ifst1, const Fst< Arc > &ifst2, MutableFst< Arc > *ofst, const IntersectOptions &opts=IntersectOptions())
#define SET_FLAGS(usage, argc, argv, rmflags)
bool GetComposeFilter(std::string_view str, ComposeFilter *compose_filter)
DECLARE_string(compose_filter)
ComposeOptions IntersectOptions