FST  openfst-1.8.3
OpenFst Library
randequivalent.h
Go to the documentation of this file.
1 // Copyright 2005-2024 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 <random>
23 #include <tuple>
24 
25 #include <fst/fst.h>
26 #include <fst/randequivalent.h>
27 #include <fst/randgen.h>
28 #include <fst/weight.h>
29 #include <fst/script/arg-packs.h>
30 #include <fst/script/fst-class.h>
31 #include <fst/script/script-impl.h>
32 
33 namespace fst {
34 namespace script {
35 
37  std::tuple<const FstClass &, const FstClass &, int32_t,
38  const RandGenOptions<RandArcSelection> &, float, uint64_t>;
39 
41 
42 template <class Arc>
44  const Fst<Arc> &fst1 = *std::get<0>(args->args).GetFst<Arc>();
45  const Fst<Arc> &fst2 = *std::get<1>(args->args).GetFst<Arc>();
46  const int32_t npath = std::get<2>(args->args);
47  const auto &opts = std::get<3>(args->args);
48  const float delta = std::get<4>(args->args);
49  const uint64_t seed = std::get<5>(args->args);
50  switch (opts.selector) {
52  const UniformArcSelector<Arc> selector(seed);
53  const RandGenOptions<UniformArcSelector<Arc>> ropts(selector,
54  opts.max_length);
55  args->retval = RandEquivalent(fst1, fst2, npath, ropts, delta, seed);
56  return;
57  }
59  const FastLogProbArcSelector<Arc> selector(seed);
60  const RandGenOptions<FastLogProbArcSelector<Arc>> ropts(selector,
61  opts.max_length);
62  args->retval = RandEquivalent(fst1, fst2, npath, ropts, delta, seed);
63  return;
64  }
66  const LogProbArcSelector<Arc> selector(seed);
67  const RandGenOptions<LogProbArcSelector<Arc>> ropts(selector,
68  opts.max_length);
69  args->retval = RandEquivalent(fst1, fst2, npath, ropts, delta, seed);
70  return;
71  }
72  }
73 }
74 
75 bool RandEquivalent(
76  const FstClass &fst1, const FstClass &fst2, int32_t npath = 1,
79  float delta = kDelta, uint64_t seed = std::random_device()());
80 
81 } // namespace script
82 } // namespace fst
83 
84 #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:133