1
2 // Licensed under the Apache License, Version 2.0 (the "License");
3 // you may not use this file except in compliance with the License.
4 // You may obtain a copy of the License at
5 //
6 // http://www.apache.org/licenses/LICENSE-2.0
7 //
8 // Unless required by applicable law or agreed to in writing, software
9 // distributed under the License is distributed on an "AS IS" BASIS,
10 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11 // See the License for the specific language governing permissions and
12 // limitations under the License.
13 //
14 // Copyright 2005-2010 Google, Inc.
15 // Author: jpr@google.com (Jake Ratkiewicz)
16
17 #ifndef FST_SCRIPT_RELABEL_H_
18 #define FST_SCRIPT_RELABEL_H_
19
20 #include <utility>
21 using std::pair; using std::make_pair;
22 #include <algorithm>
23 #include <vector>
24 using std::vector;
25
26 #include <fst/script/arg-packs.h>
27 #include <fst/script/fst-class.h>
28 #include <fst/relabel.h>
29
30 namespace fst {
31 namespace script {
32
33 // 1
34 typedef args::Package<MutableFstClass *,
35 const SymbolTable *, const SymbolTable *, bool,
36 const SymbolTable *, const SymbolTable *,
37 bool> RelabelArgs1;
38
39 template<class Arc>
Relabel(RelabelArgs1 * args)40 void Relabel(RelabelArgs1 *args) {
41 MutableFst<Arc> *ofst = args->arg1->GetMutableFst<Arc>();
42
43 Relabel(ofst, args->arg2, args->arg3, args->arg4,
44 args->arg5, args->arg6, args->arg7);
45 }
46
47 // 2
48 typedef args::Package<MutableFstClass*,
49 const vector<pair<int64, int64> > &,
50 const vector<pair<int64, int64> > > RelabelArgs2;
51
52 template<class Arc>
Relabel(RelabelArgs2 * args)53 void Relabel(RelabelArgs2 *args) {
54 MutableFst<Arc> *ofst = args->arg1->GetMutableFst<Arc>();
55
56 // In case int64 is not the same as Arc::Label,
57 // copy the reassignments
58 typedef typename Arc::Label Label;
59
60 vector<pair<Label, Label> > converted_ipairs(args->arg2.size());
61 copy(args->arg2.begin(), args->arg2.end(), converted_ipairs.begin());
62
63 vector<pair<Label, Label> > converted_opairs(args->arg3.size());
64 copy(args->arg3.begin(), args->arg3.end(), converted_opairs.begin());
65
66 Relabel(ofst, converted_ipairs, converted_opairs);
67 }
68
69 // 3
70 typedef args::Package<MutableFstClass*, const SymbolTable*,
71 const SymbolTable*> RelabelArgs3;
72 template<class Arc>
Relabel(args::Package<MutableFstClass *,const SymbolTable *,const SymbolTable * > * args)73 void Relabel(args::Package<MutableFstClass*, const SymbolTable*,
74 const SymbolTable*> *args) {
75 MutableFst<Arc> *fst = args->arg1->GetMutableFst<Arc>();
76 Relabel(fst, args->arg2, args->arg3);
77 }
78
79
80 // 1
81 void Relabel(MutableFstClass *ofst,
82 const SymbolTable *old_isyms, const SymbolTable *relabel_isyms,
83 bool attach_new_isyms,
84 const SymbolTable *old_osyms, const SymbolTable *relabel_osyms,
85 bool attch_new_osyms);
86
87 // 2
88 void Relabel(MutableFstClass *ofst,
89 const vector<pair<int64, int64> > &ipairs,
90 const vector<pair<int64, int64> > &opairs);
91
92
93 // 3
94 void Relabel(MutableFstClass *fst,
95 const SymbolTable *new_isymbols,
96 const SymbolTable *new_osymbols);
97
98
99 } // namespace script
100 } // namespace fst
101
102 #endif // FST_SCRIPT_RELABEL_H_
103