FST  openfst-1.8.2.post1
OpenFst Library
determinize.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_DETERMINIZE_H_
19 #define FST_SCRIPT_DETERMINIZE_H_
20 
21 #include <cstdint>
22 #include <tuple>
23 
24 #include <fst/determinize.h>
25 #include <fst/script/fst-class.h>
27 
28 namespace fst {
29 namespace script {
30 
32  const float delta;
34  const int64_t state_threshold;
35  const int64_t subsequential_label;
38 
39  DeterminizeOptions(float delta, const WeightClass &weight_threshold,
40  int64_t state_threshold = kNoStateId,
41  int64_t subsequential_label = 0,
43  bool increment_subsequential_label = false)
44  : delta(delta),
45  weight_threshold(weight_threshold),
46  state_threshold(state_threshold),
47  subsequential_label(subsequential_label),
48  det_type(det_type),
49  increment_subsequential_label(increment_subsequential_label) {}
50 };
51 
52 using FstDeterminizeArgs =
53  std::tuple<const FstClass &, MutableFstClass *, const DeterminizeOptions &>;
54 
55 template <class Arc>
57  using Weight = typename Arc::Weight;
58  const Fst<Arc> &ifst = *std::get<0>(*args).GetFst<Arc>();
59  MutableFst<Arc> *ofst = std::get<1>(*args)->GetMutableFst<Arc>();
60  const auto &opts = std::get<2>(*args);
61  const auto weight_threshold = *opts.weight_threshold.GetWeight<Weight>();
62  const fst::DeterminizeOptions<Arc> detargs(
63  opts.delta, weight_threshold, opts.state_threshold,
64  opts.subsequential_label, opts.det_type,
65  opts.increment_subsequential_label);
66  Determinize(ifst, ofst, detargs);
67 }
68 
69 void Determinize(const FstClass &ifst, MutableFstClass *ofst,
70  const DeterminizeOptions &opts);
71 
72 } // namespace script
73 } // namespace fst
74 
75 #endif // FST_SCRIPT_DETERMINIZE_H_
std::tuple< const FstClass &, MutableFstClass *, const DeterminizeOptions & > FstDeterminizeArgs
Definition: determinize.h:53
void Determinize(FstDeterminizeArgs *args)
Definition: determinize.h:56
constexpr int kNoStateId
Definition: fst.h:202
const WeightClass & weight_threshold
Definition: determinize.h:33
const DeterminizeType det_type
Definition: determinize.h:36
const W * GetWeight() const
Definition: weight-class.h:143
const bool increment_subsequential_label
Definition: determinize.h:37
DeterminizeOptions(float delta, const WeightClass &weight_threshold, int64_t state_threshold=kNoStateId, int64_t subsequential_label=0, DeterminizeType det_type=DETERMINIZE_FUNCTIONAL, bool increment_subsequential_label=false)
Definition: determinize.h:39
DeterminizeType
Definition: determinize.h:377