FST  openfst-1.7.1
OpenFst Library
relabel.h
Go to the documentation of this file.
1 // See www.openfst.org for extensive documentation on this weighted
2 // finite-state transducer library.
3 
4 #ifndef FST_SCRIPT_RELABEL_H_
5 #define FST_SCRIPT_RELABEL_H_
6 
7 #include <algorithm>
8 #include <tuple>
9 #include <utility>
10 #include <vector>
11 
12 #include <fst/relabel.h>
13 #include <fst/script/fst-class.h>
14 
15 namespace fst {
16 namespace script {
17 
18 using RelabelArgs1 = std::tuple<MutableFstClass *, const SymbolTable *,
19  const SymbolTable *, const string &, bool,
20  const SymbolTable *, const SymbolTable *,
21  const string &, bool>;
22 
23 template <class Arc>
24 void Relabel(RelabelArgs1 *args) {
25  MutableFst<Arc> *ofst = std::get<0>(*args)->GetMutableFst<Arc>();
26  Relabel(ofst, std::get<1>(*args), std::get<2>(*args), std::get<3>(*args),
27  std::get<4>(*args), std::get<5>(*args), std::get<6>(*args),
28  std::get<7>(*args), std::get<8>(*args));
29 }
30 
31 using LabelPair = std::pair<int64, int64>;
32 
33 using RelabelArgs2 = std::tuple<MutableFstClass *,
34  const std::vector<LabelPair> &,
35  const std::vector<LabelPair> &>;
36 
37 template <class Arc>
38 void Relabel(RelabelArgs2 *args) {
39  MutableFst<Arc> *ofst = std::get<0>(*args)->GetMutableFst<Arc>();
40  using LabelPair = std::pair<typename Arc::Label, typename Arc::Label>;
41  // In case the MutableFstClass::Label is not the same as Arc::Label,
42  // make a copy.
43  std::vector<LabelPair> typed_ipairs(std::get<1>(*args).size());
44  std::copy(std::get<1>(*args).begin(), std::get<1>(*args).end(),
45  typed_ipairs.begin());
46  std::vector<LabelPair> typed_opairs(std::get<2>(*args).size());
47  std::copy(std::get<2>(*args).begin(), std::get<2>(*args).end(),
48  typed_opairs.begin());
49  Relabel(ofst, typed_ipairs, typed_opairs);
50 }
51 
52 void Relabel(MutableFstClass *ofst,
53  const SymbolTable *old_isymbols, const SymbolTable *new_isymbols,
54  const string &unknown_isymbol, bool attach_new_isymbols,
55  const SymbolTable *old_osymbols, const SymbolTable *new_osymbols,
56  const string &unknown_osymbol, bool attach_new_osymbols);
57 
58 void Relabel(MutableFstClass *ofst, const std::vector<LabelPair> &ipairs,
59  const std::vector<LabelPair> &opairs);
60 
61 } // namespace script
62 } // namespace fst
63 
64 #endif // FST_SCRIPT_RELABEL_H_
std::pair< int64, int64 > LabelPair
Definition: relabel.h:31
std::tuple< MutableFstClass *, const std::vector< LabelPair > &, const std::vector< LabelPair > & > RelabelArgs2
Definition: relabel.h:35
void Relabel(RelabelArgs1 *args)
Definition: relabel.h:24
std::tuple< MutableFstClass *, const SymbolTable *, const SymbolTable *, const string &, bool, const SymbolTable *, const SymbolTable *, const string &, bool > RelabelArgs1
Definition: relabel.h:21