FST  openfst-1.8.3
OpenFst Library
push.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_PUSH_H_
19 #define FST_SCRIPT_PUSH_H_
20 
21 #include <cstdint>
22 #include <tuple>
23 
24 #include <fst/fst.h>
25 #include <fst/mutable-fst.h>
26 #include <fst/push.h>
27 #include <fst/reweight.h>
28 #include <fst/shortest-distance.h>
29 #include <fst/script/fst-class.h>
30 
31 namespace fst {
32 namespace script {
33 
34 using FstPushArgs1 = std::tuple<MutableFstClass *, ReweightType, float, bool>;
35 
36 template <class Arc>
37 void Push(FstPushArgs1 *args) {
38  MutableFst<Arc> *fst = std::get<0>(*args)->GetMutableFst<Arc>();
39  Push(fst, std::get<1>(*args), std::get<2>(*args), std::get<3>(*args));
40 }
41 
42 using FstPushArgs2 = std::tuple<const FstClass &, MutableFstClass *, uint8_t,
43  ReweightType, float>;
44 
45 template <class Arc>
46 void Push(FstPushArgs2 *args) {
47  const Fst<Arc> &ifst = *std::get<0>(*args).GetFst<Arc>();
48  MutableFst<Arc> *ofst = std::get<1>(*args)->GetMutableFst<Arc>();
49  switch (std::get<3>(*args)) {
50  case REWEIGHT_TO_FINAL: {
51  Push<Arc, REWEIGHT_TO_FINAL>(ifst, ofst, std::get<2>(*args),
52  std::get<4>(*args));
53  return;
54  }
55  case REWEIGHT_TO_INITIAL: {
56  Push<Arc, REWEIGHT_TO_INITIAL>(ifst, ofst, std::get<2>(*args),
57  std::get<4>(*args));
58  return;
59  }
60  }
61 }
62 
63 void Push(MutableFstClass *fst, ReweightType type = REWEIGHT_TO_INITIAL,
64  float delta = kShortestDelta, bool remove_total_weight = false);
65 
66 void Push(const FstClass &ifst, MutableFstClass *ofst, uint8_t flags,
67  ReweightType rew_type, float delta = kShortestDelta);
68 
69 } // namespace script
70 } // namespace fst
71 
72 #endif // FST_SCRIPT_PUSH_H_
ReweightType
Definition: reweight.h:35
std::tuple< const FstClass &, MutableFstClass *, uint8_t, ReweightType, float > FstPushArgs2
Definition: push.h:43
constexpr float kShortestDelta
void Push(FstPushArgs1 *args)
Definition: push.h:37
std::tuple< MutableFstClass *, ReweightType, float, bool > FstPushArgs1
Definition: push.h:34