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 (at) google.com (Jake Ratkiewicz) 16 17 #ifndef FST_SCRIPT_REPLACE_H_ 18 #define FST_SCRIPT_REPLACE_H_ 19 20 #include <utility> 21 using std::pair; using std::make_pair; 22 #include <vector> 23 using std::vector; 24 25 #include <fst/script/arg-packs.h> 26 #include <fst/script/fst-class.h> 27 #include <fst/replace.h> 28 29 namespace fst { 30 namespace script { 31 32 typedef args::Package<const vector<pair<int64, const FstClass *> > &, 33 MutableFstClass *, const int64, bool> ReplaceArgs; 34 35 template<class Arc> 36 void Replace(ReplaceArgs *args) { 37 // Now that we know the arc type, we construct a vector of 38 // pair<real label, real fst> that the real Replace will use 39 const vector<pair<int64, const FstClass *> >& untyped_tuples = 40 args->arg1; 41 42 vector<pair<typename Arc::Label, const Fst<Arc> *> > fst_tuples( 43 untyped_tuples.size()); 44 45 for (unsigned i = 0; i < untyped_tuples.size(); ++i) { 46 fst_tuples[i].first = untyped_tuples[i].first; // convert label 47 fst_tuples[i].second = untyped_tuples[i].second->GetFst<Arc>(); 48 } 49 50 MutableFst<Arc> *ofst = args->arg2->GetMutableFst<Arc>(); 51 52 Replace(fst_tuples, ofst, args->arg3, args->arg4); 53 } 54 55 void Replace(const vector<pair<int64, const FstClass *> > &tuples, 56 MutableFstClass *ofst, const int64 &root, 57 bool epsilon_on_replace = false); 58 59 } // namespace script 60 } // namespace fst 61 62 #endif // FST_SCRIPT_REPLACE_H_ 63