FST  openfst-1.7.1
OpenFst Library
randgen.h
Go to the documentation of this file.
1 // See www.openfst.org for extensive documentation on this weighted
2 // finite-state transducer library.
3 
4 #ifndef FST_SCRIPT_RANDGEN_H_
5 #define FST_SCRIPT_RANDGEN_H_
6 
7 #include <ctime>
8 
9 #include <tuple>
10 
11 #include <fst/randgen.h>
12 #include <fst/script/fst-class.h>
13 #include <fst/script/script-impl.h>
14 
15 namespace fst {
16 namespace script {
17 
18 using RandGenArgs = std::tuple<const FstClass &, MutableFstClass *, time_t,
20 
21 template <class Arc>
22 void RandGen(RandGenArgs *args) {
23  const Fst<Arc> &ifst = *(std::get<0>(*args).GetFst<Arc>());
24  MutableFst<Arc> *ofst = std::get<1>(*args)->GetMutableFst<Arc>();
25  const time_t seed = std::get<2>(*args);
26  const auto &opts = std::get<3>(*args);
27  switch (opts.selector) {
28  case UNIFORM_ARC_SELECTOR: {
29  const UniformArcSelector<Arc> selector(seed);
31  selector, opts.max_length, opts.npath, opts.weighted,
32  opts.remove_total_weight);
33  RandGen(ifst, ofst, ropts);
34  return;
35  }
37  const FastLogProbArcSelector<Arc> selector(seed);
39  selector, opts.max_length, opts.npath, opts.weighted,
40  opts.remove_total_weight);
41  RandGen(ifst, ofst, ropts);
42  return;
43  }
44  case LOG_PROB_ARC_SELECTOR: {
45  const LogProbArcSelector<Arc> selector(seed);
47  selector, opts.max_length, opts.npath, opts.weighted,
48  opts.remove_total_weight);
49  RandGen(ifst, ofst, ropts);
50  return;
51  }
52  }
53 }
54 
55 void RandGen(const FstClass &ifst, MutableFstClass *ofst,
56  time_t seed = time(nullptr),
59 
60 } // namespace script
61 } // namespace fst
62 
63 #endif // FST_SCRIPT_RANDGEN_H_
std::tuple< const FstClass &, MutableFstClass *, time_t, const RandGenOptions< RandArcSelection > & > RandGenArgs
Definition: randgen.h:19
void RandGen(RandGenArgs *args)
Definition: randgen.h:22