FST  openfst-1.7.1
OpenFst Library
pdtinfo.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 // Prints out various information about a PDT such as number of states, arcs,
5 // and parentheses.
6 
7 #include <cstring>
8 
9 #include <memory>
10 #include <string>
11 #include <vector>
12 
13 #include <fst/flags.h>
14 #include <fst/log.h>
15 
17 #include <fst/util.h>
18 
19 DEFINE_string(pdt_parentheses, "", "PDT parenthesis label pairs");
20 
21 int main(int argc, char **argv) {
22  namespace s = fst::script;
23  using fst::ReadLabelPairs;
25 
26  string usage = "Prints out information about a PDT.\n\n Usage: ";
27  usage += argv[0];
28  usage += " in.pdt\n";
29 
30  std::set_new_handler(FailedNewHandler);
31  SET_FLAGS(usage.c_str(), &argc, &argv, true);
32  if (argc > 2) {
33  ShowUsage();
34  return 1;
35  }
36 
37  const string in_name =
38  (argc > 1 && (strcmp(argv[1], "-") != 0)) ? argv[1] : "";
39 
40  std::unique_ptr<FstClass> ifst(FstClass::Read(in_name));
41  if (!ifst) return 1;
42 
43  if (FLAGS_pdt_parentheses.empty()) {
44  LOG(ERROR) << argv[0] << ": No PDT parenthesis label pairs provided";
45  return 1;
46  }
47 
48  std::vector<s::LabelPair> parens;
49  if (!ReadLabelPairs(FLAGS_pdt_parentheses, &parens, false)) return 1;
50 
51  s::PrintPdtInfo(*ifst, parens);
52 
53  return 0;
54 }
void ShowUsage(bool long_usage=true)
Definition: flags.cc:124
bool ReadLabelPairs(const string &filename, std::vector< std::pair< Label, Label >> *pairs, bool allow_negative=false)
Definition: util.h:331
#define LOG(type)
Definition: log.h:48
void FailedNewHandler()
Definition: compat.cc:25
#define SET_FLAGS(usage, argc, argv, rmflags)
Definition: flags.h:214
void PrintPdtInfo(const FstClass &ifst, const std::vector< LabelPair > &parens)
Definition: pdtscript.cc:83
int main(int argc, char **argv)
Definition: pdtinfo.cc:21
DEFINE_string(pdt_parentheses,"","PDT parenthesis label pairs")