FST  openfst-1.7.1
OpenFst Library
mpdtinfo.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 an MPDT 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 
18 #include <fst/util.h>
19 
20 DEFINE_string(mpdt_parentheses, "",
21  "MPDT parenthesis label pairs with assignments");
22 
23 int main(int argc, char **argv) {
24  namespace s = fst::script;
27 
28  string usage = "Prints out information about an MPDT.\n\n Usage: ";
29  usage += argv[0];
30  usage += " in.pdt\n";
31 
32  std::set_new_handler(FailedNewHandler);
33  SET_FLAGS(usage.c_str(), &argc, &argv, true);
34  if (argc > 2) {
35  ShowUsage();
36  return 1;
37  }
38 
39  const string in_name =
40  (argc > 1 && (strcmp(argv[1], "-") != 0)) ? argv[1] : "";
41 
42  std::unique_ptr<FstClass> ifst(FstClass::Read(in_name));
43  if (!ifst) return 1;
44 
45  if (FLAGS_mpdt_parentheses.empty()) {
46  LOG(ERROR) << argv[0] << ": No MPDT parenthesis label pairs provided";
47  return 1;
48  }
49 
50  std::vector<s::LabelPair> parens;
51  std::vector<int64> assignments;
52  if (!ReadLabelTriples(FLAGS_mpdt_parentheses, &parens, &assignments, false))
53  return 1;
54 
55  s::PrintMPdtInfo(*ifst, parens, assignments);
56 
57  return 0;
58 }
void ShowUsage(bool long_usage=true)
Definition: flags.cc:124
DEFINE_string(mpdt_parentheses,"","MPDT parenthesis label pairs with assignments")
int main(int argc, char **argv)
Definition: mpdtinfo.cc:23
#define LOG(type)
Definition: log.h:48
void FailedNewHandler()
Definition: compat.cc:25
bool ReadLabelTriples(const string &filename, std::vector< std::pair< Label, Label >> *pairs, std::vector< Label > *assignments, bool allow_negative=false)
#define SET_FLAGS(usage, argc, argv, rmflags)
Definition: flags.h:214
void PrintMPdtInfo(const FstClass &ifst, const std::vector< LabelPair > &parens, const std::vector< int64 > &assignments)
Definition: mpdtscript.cc:52