1 // fstdeterminize.cc 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 // Copyright 2005-2010 Google, Inc. 16 // Author: riley (at) google.com (Michael Riley) 17 // Modified: jpr (at) google.com (Jake Ratkiewicz) to use FstClass 18 // 19 // \file 20 // Determinizes an FST. 21 // 22 23 #include <fst/script/determinize.h> 24 25 DEFINE_double(delta, fst::kDelta, "Comparison/quantization delta"); 26 DEFINE_int64(nstate, fst::kNoStateId, "State number threshold"); 27 DEFINE_string(weight, "", "Weight threshold"); 28 DEFINE_int64(subsequential_label, 0, 29 "Input label of arc corresponding to residual final output when" 30 " producing a subsequential transducer"); 31 32 int main(int argc, char **argv) { 33 namespace s = fst::script; 34 using fst::script::FstClass; 35 using fst::script::MutableFstClass; 36 using fst::script::VectorFstClass; 37 using fst::script::WeightClass; 38 39 string usage = "Determinizes an FST.\n\n Usage: "; 40 usage += argv[0]; 41 usage += " [in.fst [out.fst]]\n"; 42 43 std::set_new_handler(FailedNewHandler); 44 SET_FLAGS(usage.c_str(), &argc, &argv, true); 45 if (argc > 3) { 46 ShowUsage(); 47 return 1; 48 } 49 50 string in_name = (argc > 1 && strcmp(argv[1], "-") != 0) ? argv[1] : ""; 51 string out_name = argc > 2 ? argv[2] : ""; 52 53 FstClass *ifst = FstClass::Read(in_name); 54 if (!ifst) return 1; 55 56 VectorFstClass ofst(ifst->ArcType()); 57 58 s::DeterminizeOptions opts( 59 FLAGS_delta, FLAGS_weight.empty() ? 60 WeightClass::Zero() : WeightClass(ifst->WeightType(), FLAGS_weight), 61 FLAGS_nstate, FLAGS_subsequential_label); 62 63 s::Determinize(*ifst, &ofst, opts); 64 65 ofst.Write(out_name); 66 67 return 0; 68 } 69