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