FST  openfst-1.7.2
OpenFst Library
farextract.cc
Go to the documentation of this file.
1 // See www.openfst.org for extensive documentation on this weighted
2 // finite-state transducer library.
3 //
4 // Extracts component FSTs from an finite-state archive.
5 
6 #include <string>
7 #include <vector>
8 
9 #include <fst/flags.h>
12 
13 DEFINE_string(filename_prefix, "", "Prefix to append to filenames");
14 DEFINE_string(filename_suffix, "", "Suffix to append to filenames");
15 DEFINE_int32(generate_filenames, 0,
16  "Generate N digit numeric filenames (def: use keys)");
17 DEFINE_string(keys, "",
18  "Extract set of keys separated by comma (default) "
19  "including ranges delimited by dash (default)");
20 DEFINE_string(key_separator, ",", "Separator for individual keys");
21 DEFINE_string(range_delimiter, "-", "Delimiter for ranges of keys");
22 
23 int main(int argc, char **argv) {
24  namespace s = fst::script;
25 
26  string usage = "Extracts FSTs from a finite-state archive.\n\n Usage:";
27  usage += argv[0];
28  usage += " [in1.far in2.far...]\n";
29 
30  std::set_new_handler(FailedNewHandler);
31  SET_FLAGS(usage.c_str(), &argc, &argv, true);
32  s::ExpandArgs(argc, argv, &argc, &argv);
33 
34  std::vector<string> in_fnames;
35  for (int i = 1; i < argc; ++i) in_fnames.push_back(argv[i]);
36  if (in_fnames.empty()) in_fnames.push_back("");
37 
38  const auto arc_type = s::LoadArcTypeFromFar(in_fnames[0]);
39  if (arc_type.empty()) return 1;
40 
41  s::FarExtract(in_fnames, arc_type, FLAGS_generate_filenames, FLAGS_keys,
42  FLAGS_key_separator, FLAGS_range_delimiter,
43  FLAGS_filename_prefix, FLAGS_filename_suffix);
44 
45  return 0;
46 }
void ExpandArgs(int argc, char **argv, int *argcp, char ***argvp)
Definition: getters.cc:55
void FailedNewHandler()
Definition: compat.cc:25
#define SET_FLAGS(usage, argc, argv, rmflags)
Definition: flags.h:214
void FarExtract(const std::vector< string > &ifilenames, const string &arc_type, int32 generate_filenames, const string &keys, const string &key_separator, const string &range_delimiter, const string &filename_prefix, const string &filename_suffix)
Definition: farscript.cc:47
DEFINE_string(filename_prefix,"","Prefix to append to filenames")
int main(int argc, char **argv)
Definition: farextract.cc:23
DEFINE_int32(generate_filenames, 0,"Generate N digit numeric filenames (def: use keys)")
string LoadArcTypeFromFar(const string &far_fname)
Definition: script-impl.cc:17