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 #include <fst/script/randgen.h>
00023
00024 DEFINE_int32(max_length, INT_MAX, "Maximum path length");
00025 DEFINE_int32(npath, 1, "Number of paths to generate");
00026 DEFINE_int32(seed, time(0), "Random seed");
00027 DEFINE_string(select, "uniform", "Selection type: one of: "
00028 " \"uniform\", \"log_prob\" (when appropriate),"
00029 " \"fast_log_prob\" (when appropriate)");
00030
00031 int main(int argc, char **argv) {
00032 namespace s = fst::script;
00033 using fst::script::FstClass;
00034 using fst::script::VectorFstClass;
00035
00036 string usage = "Generates random paths through an FST.\n\n Usage: ";
00037 usage += argv[0];
00038 usage += " [in.fst [out.fst]]\n";
00039
00040 std::set_new_handler(FailedNewHandler);
00041 SetFlags(usage.c_str(), &argc, &argv, true);
00042 if (argc > 3) {
00043 ShowUsage();
00044 return 1;
00045 }
00046
00047 string in_name = (argc > 1 && strcmp(argv[1], "-") != 0) ? argv[1] : "";
00048 string out_name = argc > 2 ? argv[2] : "";
00049
00050 FstClass *ifst = FstClass::Read(in_name);
00051 if (!ifst) return 1;
00052
00053 VectorFstClass ofst(ifst->ArcType());
00054
00055 s::RandArcSelection ras;
00056
00057 if (FLAGS_select == "uniform") {
00058 ras = s::UNIFORM_ARC_SELECTOR;
00059 } else if (FLAGS_select == "log_prob") {
00060 ras = s::LOG_PROB_ARC_SELECTOR;
00061 } else if (FLAGS_select == "fast_log_prob") {
00062 ras = s::FAST_LOG_PROB_ARC_SELECTOR;
00063 } else {
00064 LOG(ERROR) << argv[0] << ": Unknown selection type \""
00065 << FLAGS_select << "\"\n";
00066 return 1;
00067 }
00068
00069 s::RandGen(*ifst, &ofst, FLAGS_seed,
00070 fst::RandGenOptions<s::RandArcSelection>(
00071 ras, FLAGS_max_length, FLAGS_npath));
00072
00073 ofst.Write(out_name);
00074 return 0;
00075 }
00076