Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023 #include <fst/script/difference.h>
00024 #include <fst/script/connect.h>
00025
00026 DEFINE_string(compose_filter, "auto",
00027 "Composition filter, one of: \"alt_sequence\", \"auto\","
00028 " \"match\", \"sequence\"");
00029 DEFINE_bool(connect, true, "Trim output");
00030
00031 int main(int argc, char **argv) {
00032 namespace s = fst::script;
00033 using fst::script::FstClass;
00034 using fst::script::MutableFstClass;
00035 using fst::script::VectorFstClass;
00036
00037 string usage = "Subtracts an unweighted DFA from an FSA.\n\n Usage: ";
00038 usage += argv[0];
00039 usage += " in1.fst in2.fst [out.fst]\n";
00040
00041 std::set_new_handler(FailedNewHandler);
00042 SetFlags(usage.c_str(), &argc, &argv, true);
00043 if (argc < 3 || argc > 4) {
00044 ShowUsage();
00045 return 1;
00046 }
00047
00048 string in1_name = strcmp(argv[1], "-") == 0 ? "" : argv[1];
00049 string in2_name = strcmp(argv[2], "-") == 0 ? "" : argv[2];
00050 string out_name = argc > 3 ? argv[3] : "";
00051
00052 if (in1_name.empty() && in2_name.empty()) {
00053 LOG(ERROR) << argv[0] << ": Can't take both inputs from standard input.";
00054 return 1;
00055 }
00056
00057 FstClass *ifst1 = FstClass::Read(in1_name);
00058 if (!ifst1) return 1;
00059 FstClass *ifst2 = FstClass::Read(in2_name);
00060 if (!ifst2) return 1;
00061
00062 VectorFstClass ofst(ifst1->ArcType());
00063
00064 fst::ComposeFilter cf;
00065
00066 if (FLAGS_compose_filter == "auto") {
00067 cf = fst::AUTO_FILTER;
00068 } else if (FLAGS_compose_filter == "sequence") {
00069 cf = fst::SEQUENCE_FILTER;
00070 } else if (FLAGS_compose_filter == "alt_sequence") {
00071 cf = fst::ALT_SEQUENCE_FILTER;
00072 } else if (FLAGS_compose_filter == "match") {
00073 cf = fst::MATCH_FILTER;
00074 } else {
00075 LOG(ERROR) << argv[0] << ": Bad filter type \""
00076 << FLAGS_compose_filter << "\"";
00077 return 1;
00078 }
00079
00080 fst::DifferenceOptions opts(FLAGS_connect, cf);
00081
00082 s::Difference(*ifst1, *ifst2, &ofst, opts);
00083
00084 ofst.Write(out_name);
00085
00086 return 0;
00087 }
00088