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