FST  openfst-1.7.1
OpenFst Library
info-impl.cc
Go to the documentation of this file.
1 #include <fst/script/info-impl.h>
2 
3 namespace fst {
4 
5 void PrintFstInfoImpl(const FstInfo &fstinfo, bool pipe) {
6  std::ostream &ostrm = pipe ? std::cerr : std::cout;
7  const auto old = ostrm.setf(std::ios::left);
8  ostrm.width(50);
9  ostrm << "fst type" << fstinfo.FstType() << std::endl;
10  ostrm.width(50);
11  ostrm << "arc type" << fstinfo.ArcType() << std::endl;
12  ostrm.width(50);
13  ostrm << "input symbol table" << fstinfo.InputSymbols() << std::endl;
14  ostrm.width(50);
15  ostrm << "output symbol table" << fstinfo.OutputSymbols() << std::endl;
16  if (!fstinfo.LongInfo()) {
17  ostrm.setf(old);
18  return;
19  }
20  ostrm.width(50);
21  ostrm << "# of states" << fstinfo.NumStates() << std::endl;
22  ostrm.width(50);
23  ostrm << "# of arcs" << fstinfo.NumArcs() << std::endl;
24  ostrm.width(50);
25  ostrm << "initial state" << fstinfo.Start() << std::endl;
26  ostrm.width(50);
27  ostrm << "# of final states" << fstinfo.NumFinal() << std::endl;
28  ostrm.width(50);
29  ostrm << "# of input/output epsilons" << fstinfo.NumEpsilons() << std::endl;
30  ostrm.width(50);
31  ostrm << "# of input epsilons" << fstinfo.NumInputEpsilons() << std::endl;
32  ostrm.width(50);
33  ostrm << "# of output epsilons" << fstinfo.NumOutputEpsilons() << std::endl;
34  ostrm.width(50);
35  ostrm << "input label multiplicity" << fstinfo.InputLabelMultiplicity()
36  << std::endl;
37  ostrm.width(50);
38  ostrm << "output label multiplicity" << fstinfo.OutputLabelMultiplicity()
39  << std::endl;
40  ostrm.width(50);
41  string arc_type = "";
42  if (fstinfo.ArcFilterType() == "epsilon")
43  arc_type = "epsilon ";
44  else if (fstinfo.ArcFilterType() == "iepsilon")
45  arc_type = "input-epsilon ";
46  else if (fstinfo.ArcFilterType() == "oepsilon")
47  arc_type = "output-epsilon ";
48  const auto accessible_label = "# of " + arc_type + "accessible states";
49  ostrm.width(50);
50  ostrm << accessible_label << fstinfo.NumAccessible() << std::endl;
51  const auto coaccessible_label = "# of " + arc_type + "coaccessible states";
52  ostrm.width(50);
53  ostrm << coaccessible_label << fstinfo.NumCoAccessible() << std::endl;
54  const auto connected_label = "# of " + arc_type + "connected states";
55  ostrm.width(50);
56  ostrm << connected_label << fstinfo.NumConnected() << std::endl;
57  const auto numcc_label = "# of " + arc_type + "connected components";
58  ostrm.width(50);
59  ostrm << numcc_label << fstinfo.NumCc() << std::endl;
60  const auto numscc_label = "# of " + arc_type + "strongly conn components";
61  ostrm.width(50);
62  ostrm << numscc_label << fstinfo.NumScc() << std::endl;
63  ostrm.width(50);
64  ostrm << "input matcher"
65  << (fstinfo.InputMatchType() == MATCH_INPUT
66  ? 'y'
67  : fstinfo.InputMatchType() == MATCH_NONE ? 'n' : '?')
68  << std::endl;
69  ostrm.width(50);
70  ostrm << "output matcher"
71  << (fstinfo.OutputMatchType() == MATCH_OUTPUT
72  ? 'y'
73  : fstinfo.OutputMatchType() == MATCH_NONE ? 'n' : '?')
74  << std::endl;
75  ostrm.width(50);
76  ostrm << "input lookahead" << (fstinfo.InputLookAhead() ? 'y' : 'n')
77  << std::endl;
78  ostrm.width(50);
79  ostrm << "output lookahead" << (fstinfo.OutputLookAhead() ? 'y' : 'n')
80  << std::endl;
81  uint64 prop = 1;
82  for (auto i = 0; i < 64; ++i, prop <<= 1) {
83  if (prop & kBinaryProperties) {
84  char value = 'n';
85  if (fstinfo.Properties() & prop) value = 'y';
86  ostrm.width(50);
87  ostrm << PropertyNames[i] << value << std::endl;
88  } else if (prop & kPosTrinaryProperties) {
89  char value = '?';
90  if (fstinfo.Properties() & prop)
91  value = 'y';
92  else if (fstinfo.Properties() & prop << 1)
93  value = 'n';
94  ostrm.width(50);
95  ostrm << PropertyNames[i] << value << std::endl;
96  }
97  }
98  ostrm.setf(old);
99 }
100 
101 } // namespace fst
const string & InputSymbols() const
Definition: info-impl.h:172
const string & FstType() const
Definition: info-impl.h:168
const string & ArcFilterType() const
Definition: info-impl.h:178
uint64_t uint64
Definition: types.h:32
MatchType InputMatchType() const
Definition: info-impl.h:182
size_t NumFinal() const
Definition: info-impl.h:217
size_t NumConnected() const
Definition: info-impl.h:257
bool InputLookAhead() const
Definition: info-impl.h:192
size_t NumCc() const
Definition: info-impl.h:262
bool LongInfo() const
Definition: info-impl.h:176
size_t NumScc() const
Definition: info-impl.h:267
double OutputLabelMultiplicity() const
Definition: info-impl.h:242
const char * PropertyNames[]
Definition: properties.cc:405
size_t NumOutputEpsilons() const
Definition: info-impl.h:232
size_t NumInputEpsilons() const
Definition: info-impl.h:227
void PrintFstInfoImpl(const FstInfo &fstinfo, bool pipe=false)
Definition: info-impl.cc:5
size_t NumAccessible() const
Definition: info-impl.h:247
double InputLabelMultiplicity() const
Definition: info-impl.h:237
size_t NumEpsilons() const
Definition: info-impl.h:222
const string & OutputSymbols() const
Definition: info-impl.h:174
size_t NumCoAccessible() const
Definition: info-impl.h:252
constexpr uint64 kPosTrinaryProperties
Definition: properties.h:293
const string & ArcType() const
Definition: info-impl.h:170
uint64 Properties() const
Definition: info-impl.h:272
bool OutputLookAhead() const
Definition: info-impl.h:197
constexpr uint64 kBinaryProperties
Definition: properties.h:285
int64 Start() const
Definition: info-impl.h:212
MatchType OutputMatchType() const
Definition: info-impl.h:187
size_t NumArcs() const
Definition: info-impl.h:207
int64 NumStates() const
Definition: info-impl.h:202