1 // farcreate.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 new dispatch 18 // 19 // \file 20 // Creates a finite-state archive from input FSTs. 21 // 22 23 #include <fst/extensions/far/farscript.h> 24 #include <fst/extensions/far/main.h> 25 #include <fst/extensions/far/far.h> 26 27 DEFINE_string(key_prefix, "", "Prefix to append to keys"); 28 DEFINE_string(key_suffix, "", "Suffix to append to keys"); 29 DEFINE_int32(generate_keys, 0, 30 "Generate N digit numeric keys (def: use file basenames)"); 31 DEFINE_string(far_type, "default", 32 "FAR file format type: one of: \"default\", " 33 "\"stlist\", \"sttable\""); 34 DEFINE_bool(file_list_input, false, 35 "Each input files contains a list of files to be processed"); 36 37 int main(int argc, char **argv) { 38 namespace s = fst::script; 39 40 string usage = "Creates a finite-state archive from input FSTs.\n\n Usage:"; 41 usage += argv[0]; 42 usage += " [in1.fst [[in2.fst ...] out.far]]\n"; 43 44 std::set_new_handler(FailedNewHandler); 45 SET_FLAGS(usage.c_str(), &argc, &argv, true); 46 47 vector<string> in_fnames; 48 for (unsigned i = 1; i < argc - 1; ++i) 49 in_fnames.push_back(strcmp(argv[i], "") != 0 ? argv[i] : ""); 50 if (in_fnames.empty()) 51 in_fnames.push_back(argc == 2 && strcmp(argv[1], "-") != 0 ? argv[1] : ""); 52 53 string out_fname = 54 argc > 2 && strcmp(argv[argc - 1], "-") != 0 ? argv[argc - 1] : ""; 55 56 string arc_type = fst::LoadArcTypeFromFst(in_fnames[0]); 57 fst::FarType far_type = fst::FarTypeFromString(FLAGS_far_type); 58 59 s::FarCreate(in_fnames, out_fname, arc_type, FLAGS_generate_keys, 60 FLAGS_file_list_input, far_type, FLAGS_key_prefix, 61 FLAGS_key_suffix); 62 } 63