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\", \"stlist\", \"sstable\", \"sttable\""); 33 DEFINE_bool(file_list_input, false, 34 "Each input files contains a list of files to be processed"); 35 36 int main(int argc, char **argv) { 37 namespace s = fst::script; 38 39 string usage = "Creates a finite-state archive from input FSTs.\n\n Usage:"; 40 usage += argv[0]; 41 usage += " in1.fst [in2.fst ...] out.far\n"; 42 43 std::set_new_handler(FailedNewHandler); 44 SetFlags(usage.c_str(), &argc, &argv, true); 45 46 if (argc < 3) { 47 ShowUsage(); 48 return 1; 49 } 50 51 vector<string> in_fnames; 52 for (int i = 1; i < argc - 1; ++i) 53 in_fnames.push_back(argv[i]); 54 55 string out_fname = argv[argc - 1]; 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