Home | History | Annotate | Download | only in far
      1 // farextract.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 arc dispatch
     18 //
     19 // \file
     20 // Extracts component FSTs from an finite-state archive.
     21 //
     22 
     23 #include <fst/extensions/far/main.h>
     24 #include <fst/extensions/far/farscript.h>
     25 
     26 DEFINE_string(filename_prefix, "", "Prefix to append to filenames");
     27 DEFINE_string(filename_suffix, "", "Suffix to append to filenames");
     28 DEFINE_int32(generate_filenames, 0,
     29              "Generate N digit numeric filenames (def: use keys)");
     30 DEFINE_string(keys, "",
     31               "Extract set of keys separated by comma (default) "
     32               "including ranges delimited by dash (default)" );
     33 DEFINE_string(key_separator, ",", "Separator for individual keys");
     34 DEFINE_string(range_delimiter, "-", "Delimiter for ranges of keys");
     35 
     36 int main(int argc, char **argv) {
     37   namespace s = fst::script;
     38 
     39   string usage = "Extracts FSTs from a finite-state archive.\n\n Usage:";
     40   usage += argv[0];
     41   usage += " [in1.far in2.far...]\n";
     42 
     43   std::set_new_handler(FailedNewHandler);
     44   SET_FLAGS(usage.c_str(), &argc, &argv, true);
     45 
     46   vector<string> ifilenames;
     47   for (int i = 1; i < argc; ++i)
     48     ifilenames.push_back(strcmp(argv[i], "") != 0 ? argv[i] : "");
     49   if (ifilenames.empty()) ifilenames.push_back("");
     50 
     51   const string &arc_type = fst::LoadArcTypeFromFar(ifilenames[0]);
     52 
     53   s::FarExtract(ifilenames, arc_type, FLAGS_generate_filenames,
     54                 FLAGS_keys, FLAGS_key_separator, FLAGS_range_delimiter,
     55                 FLAGS_filename_prefix, FLAGS_filename_suffix);
     56 
     57   return 0;
     58 }
     59