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_REWEIGHT_H_
18 #define FST_SCRIPT_REWEIGHT_H_
19 
20 #include <vector>
21 using std::vector;
22 
23 #include <fst/script/arg-packs.h>
24 #include <fst/script/fst-class.h>
25 #include <fst/script/weight-class.h>
26 #include <fst/reweight.h>
27 
28 namespace fst {
29 namespace script {
30 
31 typedef args::Package<MutableFstClass *, const vector<WeightClass> &,
32                       ReweightType> ReweightArgs;
33 
34 template<class Arc>
Reweight(ReweightArgs * args)35 void Reweight(ReweightArgs *args) {
36   MutableFst<Arc> *fst = args->arg1->GetMutableFst<Arc>();
37   typedef typename Arc::Weight Weight;
38   vector<Weight> potentials(args->arg2.size());
39 
40   for (unsigned i = 0; i < args->arg2.size(); ++i) {
41     potentials[i] = *(args->arg2[i].GetWeight<Weight>());
42   }
43 
44   Reweight(fst, potentials, args->arg3);
45 }
46 
47 void Reweight(MutableFstClass *fst, const vector<WeightClass> &potential,
48               ReweightType reweight_type);
49 
50 }  // namespace script
51 }  // namespace fst
52 
53 #endif  // FST_SCRIPT_REWEIGHT_H_
54