1 // farprintstrings.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: allauzen@google.com (Cyril Allauzen)
17 //
18 // \file
19 // Output as strings the string FSTs in a finite-state archive.
20 //
21
22 #include <fst/extensions/far/farscript.h>
23
24 DEFINE_string(filename_prefix, "", "Prefix to append to filenames");
25 DEFINE_string(filename_suffix, "", "Suffix to append to filenames");
26 DEFINE_int32(generate_filenames, 0,
27 "Generate N digit numeric filenames (def: use keys)");
28 DEFINE_string(begin_key, "",
29 "First key to extract (def: first key in archive)");
30 DEFINE_string(end_key, "",
31 "Last key to extract (def: last key in archive)");
32 // PrintStringsMain specific flag definitions.
33 DEFINE_bool(print_key, false, "Prefix each string by its key");
34 DEFINE_bool(print_weight, false, "Suffix each string by its weight");
35 DEFINE_string(entry_type, "line", "Entry type: one of : "
36 "\"file\" (one FST per file), \"line\" (one FST per line)");
37 DEFINE_string(token_type, "symbol", "Token type: one of : "
38 "\"symbol\", \"byte\", \"utf8\"");
39 DEFINE_string(symbols, "", "Label symbol table");
40 DEFINE_bool(initial_symbols, true,
41 "Uses symbol table from the first Fst in archive for all entries.");
42
43
main(int argc,char ** argv)44 int main(int argc, char **argv) {
45 namespace s = fst::script;
46
47 string usage = "Print as string the string FSTs in an archive.\n\n Usage:";
48 usage += argv[0];
49 usage += " [in1.far in2.far ...]\n";
50
51 std::set_new_handler(FailedNewHandler);
52 SET_FLAGS(usage.c_str(), &argc, &argv, true);
53
54 vector<string> ifilenames;
55 for (int i = 1; i < argc; ++i)
56 ifilenames.push_back(strcmp(argv[i], "") != 0 ? argv[i] : "");
57 if (ifilenames.empty()) ifilenames.push_back("");
58
59 string arc_type = fst::LoadArcTypeFromFar(ifilenames[0]);
60
61 s::FarPrintStrings(ifilenames, arc_type,
62 fst::StringToFarEntryType(FLAGS_entry_type),
63 fst::StringToFarTokenType(FLAGS_token_type),
64 FLAGS_begin_key, FLAGS_end_key,
65 FLAGS_print_key, FLAGS_print_weight,
66 FLAGS_symbols, FLAGS_initial_symbols,
67 FLAGS_generate_filenames,
68 FLAGS_filename_prefix, FLAGS_filename_suffix);
69
70 return 0;
71 }
72