FST  openfst-1.8.2.post1
OpenFst Library
relabel.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_RELABEL_H_
19 #define FST_SCRIPT_RELABEL_H_
20 
21 #include <algorithm>
22 #include <cstdint>
23 #include <string>
24 #include <tuple>
25 #include <utility>
26 #include <vector>
27 
28 #include <fst/relabel.h>
29 #include <fst/script/fst-class.h>
30 
31 namespace fst {
32 namespace script {
33 
34 using FstRelabelArgs1 =
35  std::tuple<MutableFstClass *, const SymbolTable *, const SymbolTable *,
36  const std::string &, bool, const SymbolTable *,
37  const SymbolTable *, const std::string &, bool>;
38 
39 template <class Arc>
40 void Relabel(FstRelabelArgs1 *args) {
41  MutableFst<Arc> *ofst = std::get<0>(*args)->GetMutableFst<Arc>();
42  Relabel(ofst, std::get<1>(*args), std::get<2>(*args), std::get<3>(*args),
43  std::get<4>(*args), std::get<5>(*args), std::get<6>(*args),
44  std::get<7>(*args), std::get<8>(*args));
45 }
46 
47 using FstRelabelArgs2 =
48  std::tuple<MutableFstClass *,
49  const std::vector<std::pair<int64_t, int64_t>> &,
50  const std::vector<std::pair<int64_t, int64_t>> &>;
51 
52 template <class Arc>
53 void Relabel(FstRelabelArgs2 *args) {
54  MutableFst<Arc> *ofst = std::get<0>(*args)->GetMutableFst<Arc>();
55  using LabelPair = std::pair<typename Arc::Label, typename Arc::Label>;
56  // In case the MutableFstClass::Label is not the same as Arc::Label,
57  // make a copy.
58  std::vector<LabelPair> typed_ipairs(std::get<1>(*args).size());
59  std::copy(std::get<1>(*args).begin(), std::get<1>(*args).end(),
60  typed_ipairs.begin());
61  std::vector<LabelPair> typed_opairs(std::get<2>(*args).size());
62  std::copy(std::get<2>(*args).begin(), std::get<2>(*args).end(),
63  typed_opairs.begin());
64  Relabel(ofst, typed_ipairs, typed_opairs);
65 }
66 
67 void Relabel(MutableFstClass *ofst, const SymbolTable *old_isymbols,
68  const SymbolTable *new_isymbols,
69  const std::string &unknown_isymbol, bool attach_new_isymbols,
70  const SymbolTable *old_osymbols, const SymbolTable *new_osymbols,
71  const std::string &unknown_osymbol, bool attach_new_osymbols);
72 
73 void Relabel(MutableFstClass *ofst,
74  const std::vector<std::pair<int64_t, int64_t>> &ipairs,
75  const std::vector<std::pair<int64_t, int64_t>> &opairs);
76 
77 } // namespace script
78 } // namespace fst
79 
80 #endif // FST_SCRIPT_RELABEL_H_
void Relabel(FstRelabelArgs1 *args)
Definition: relabel.h:40
std::tuple< MutableFstClass *, const SymbolTable *, const SymbolTable *, const std::string &, bool, const SymbolTable *, const SymbolTable *, const std::string &, bool > FstRelabelArgs1
Definition: relabel.h:37
std::tuple< MutableFstClass *, const std::vector< std::pair< int64_t, int64_t >> &, const std::vector< std::pair< int64_t, int64_t >> & > FstRelabelArgs2
Definition: relabel.h:50