FST  openfst-1.7.2
OpenFst Library
randequivalent.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_RANDEQUIVALENT_H_
5 #define FST_SCRIPT_RANDEQUIVALENT_H_
6 
7 #include <climits>
8 #include <ctime>
9 
10 #include <tuple>
11 
12 #include <fst/randequivalent.h>
13 #include <fst/script/arg-packs.h>
14 #include <fst/script/fst-class.h>
15 #include <fst/script/script-impl.h>
16 
17 namespace fst {
18 namespace script {
19 
20 using RandEquivalentInnerArgs = std::tuple<const FstClass &, const FstClass &,
21  int32, float, time_t, const RandGenOptions<RandArcSelection> &>;
22 
24 
25 template <class Arc>
27  const Fst<Arc> &fst1 = *(std::get<0>(args->args).GetFst<Arc>());
28  const Fst<Arc> &fst2 = *(std::get<1>(args->args).GetFst<Arc>());
29  const auto seed = std::get<4>(args->args);
30  const auto &opts = std::get<5>(args->args);
31  switch (opts.selector) {
32  case UNIFORM_ARC_SELECTOR: {
33  const UniformArcSelector<Arc> selector(seed);
34  const RandGenOptions<UniformArcSelector<Arc>> ropts(selector,
35  opts.max_length);
36  args->retval = RandEquivalent(fst1, fst2, std::get<2>(args->args),
37  std::get<3>(args->args), ropts);
38  return;
39  }
41  const FastLogProbArcSelector<Arc> selector(seed);
42  const RandGenOptions<FastLogProbArcSelector<Arc>> ropts(selector,
43  opts.max_length);
44  args->retval = RandEquivalent(fst1, fst2, std::get<2>(args->args),
45  std::get<3>(args->args), ropts);
46  return;
47  }
48  case LOG_PROB_ARC_SELECTOR: {
49  const LogProbArcSelector<Arc> selector(seed);
50  const RandGenOptions<LogProbArcSelector<Arc>> ropts(selector,
51  opts.max_length);
52  args->retval = RandEquivalent(fst1, fst2, std::get<2>(args->args),
53  std::get<3>(args->args), ropts);
54  return;
55  }
56  }
57 }
58 
59 bool RandEquivalent(const FstClass &fst1, const FstClass &fst2, int32 npath = 1,
60  float delta = kDelta, time_t seed = time(nullptr),
61  const RandGenOptions<RandArcSelection> &opts =
62  RandGenOptions<RandArcSelection>(UNIFORM_ARC_SELECTOR));
63 
64 } // namespace script
65 } // namespace fst
66 
67 #endif // FST_SCRIPT_RANDEQUIVALENT_H_
std::tuple< const FstClass &, const FstClass &, int32, float, time_t, const RandGenOptions< RandArcSelection > & > RandEquivalentInnerArgs
int32_t int32
Definition: types.h:26
constexpr float kDelta
Definition: weight.h:109
void RandEquivalent(RandEquivalentArgs *args)