FST  openfst-1.8.2.post1
OpenFst Library
randequivalent.h
Go to the documentation of this file.
1 // Copyright 2005-2020 Google LLC
2 //
3 // Licensed under the Apache License, Version 2.0 (the 'License');
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 // http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an 'AS IS' BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14 //
15 // See www.openfst.org for extensive documentation on this weighted
16 // finite-state transducer library.
17 
18 #ifndef FST_SCRIPT_RANDEQUIVALENT_H_
19 #define FST_SCRIPT_RANDEQUIVALENT_H_
20 
21 #include <cstdint>
22 #include <tuple>
23 
24 #include <fst/randequivalent.h>
25 #include <fst/script/arg-packs.h>
26 #include <fst/script/fst-class.h>
27 #include <fst/script/script-impl.h>
28 
29 namespace fst {
30 namespace script {
31 
33  std::tuple<const FstClass &, const FstClass &, int32_t,
34  const RandGenOptions<RandArcSelection> &, float, uint64_t>;
35 
37 
38 template <class Arc>
40  const Fst<Arc> &fst1 = *std::get<0>(args->args).GetFst<Arc>();
41  const Fst<Arc> &fst2 = *std::get<1>(args->args).GetFst<Arc>();
42  const int32_t npath = std::get<2>(args->args);
43  const auto &opts = std::get<3>(args->args);
44  const float delta = std::get<4>(args->args);
45  const uint64_t seed = std::get<5>(args->args);
46  switch (opts.selector) {
48  const UniformArcSelector<Arc> selector(seed);
49  const RandGenOptions<UniformArcSelector<Arc>> ropts(selector,
50  opts.max_length);
51  args->retval = RandEquivalent(fst1, fst2, npath, ropts, delta, seed);
52  return;
53  }
55  const FastLogProbArcSelector<Arc> selector(seed);
56  const RandGenOptions<FastLogProbArcSelector<Arc>> ropts(selector,
57  opts.max_length);
58  args->retval = RandEquivalent(fst1, fst2, npath, ropts, delta, seed);
59  return;
60  }
62  const LogProbArcSelector<Arc> selector(seed);
63  const RandGenOptions<LogProbArcSelector<Arc>> ropts(selector,
64  opts.max_length);
65  args->retval = RandEquivalent(fst1, fst2, npath, ropts, delta, seed);
66  return;
67  }
68  }
69 }
70 
71 bool RandEquivalent(
72  const FstClass &fst1, const FstClass &fst2, int32_t npath = 1,
75  float delta = kDelta, uint64_t seed = std::random_device()());
76 
77 } // namespace script
78 } // namespace fst
79 
80 #endif // FST_SCRIPT_RANDEQUIVALENT_H_
void RandEquivalent(FstRandEquivalentArgs *args)
std::tuple< const FstClass &, const FstClass &, int32_t, const RandGenOptions< RandArcSelection > &, float, uint64_t > FstRandEquivalentInnerArgs
constexpr float kDelta
Definition: weight.h:130