FST  openfst-1.8.3
OpenFst Library
disambiguate.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_DISAMBIGUATE_H_
19 #define FST_SCRIPT_DISAMBIGUATE_H_
20 
21 #include <cstdint>
22 #include <tuple>
23 #include <utility>
24 
25 #include <fst/disambiguate.h>
26 #include <fst/fst.h>
27 #include <fst/mutable-fst.h>
28 #include <fst/script/fst-class.h>
30 
31 namespace fst {
32 namespace script {
33 
35  const float delta;
37  const int64_t state_threshold;
38  const int64_t subsequential_label;
39 
40  DisambiguateOptions(float delta, const WeightClass &weight_threshold,
41  int64_t state_threshold = kNoStateId,
42  int64_t subsequential_label = 0)
43  : delta(delta),
44  weight_threshold(weight_threshold),
45  state_threshold(state_threshold),
46  subsequential_label(subsequential_label) {}
47 };
48 
49 using FstDisambiguateArgs = std::tuple<const FstClass &, MutableFstClass *,
51 
52 template <class Arc>
54  using Weight = typename Arc::Weight;
55  const Fst<Arc> &ifst = *std::get<0>(*args).GetFst<Arc>();
56  MutableFst<Arc> *ofst = std::get<1>(*args)->GetMutableFst<Arc>();
57  const auto &opts = std::get<2>(*args);
58  const auto weight_threshold = *opts.weight_threshold.GetWeight<Weight>();
59  const fst::DisambiguateOptions<Arc> disargs(opts.delta, weight_threshold,
60  opts.state_threshold,
61  opts.subsequential_label);
62  Disambiguate(ifst, ofst, disargs);
63 }
64 
65 void Disambiguate(const FstClass &ifst, MutableFstClass *ofst,
66  const DisambiguateOptions &opts);
67 
68 } // namespace script
69 } // namespace fst
70 
71 #endif // FST_SCRIPT_DISAMBIGUATE_H_
constexpr int kNoStateId
Definition: fst.h:196
DisambiguateOptions(float delta, const WeightClass &weight_threshold, int64_t state_threshold=kNoStateId, int64_t subsequential_label=0)
Definition: disambiguate.h:40
std::tuple< const FstClass &, MutableFstClass *, const DisambiguateOptions & > FstDisambiguateArgs
Definition: disambiguate.h:50
void Disambiguate(FstDisambiguateArgs *args)
Definition: disambiguate.h:53
const W * GetWeight() const
Definition: weight-class.h:144
const WeightClass & weight_threshold
Definition: disambiguate.h:36