20 #ifndef FST_EXTENSIONS_PDT_INFO_H_ 21 #define FST_EXTENSIONS_PDT_INFO_H_ 33 #include <unordered_map> 34 #include <unordered_set> 42 using Label =
typename Arc::Label;
47 const std::vector<std::pair<Label, Label>> &parents);
49 const std::string &
FstType()
const {
return fst_type_; }
51 const std::string &
ArcType()
const {
return Arc::Type(); }
55 int64_t
NumArcs()
const {
return narcs_; }
72 std::string fst_type_;
75 int64_t nopen_parens_;
76 int64_t nclose_parens_;
77 int64_t nuniq_open_parens_;
78 int64_t nuniq_close_parens_;
79 int64_t nopen_paren_states_;
80 int64_t nclose_paren_states_;
86 const std::vector<std::pair<typename Arc::Label, typename Arc::Label>> & parens)
87 : fst_type_(fst.Type()),
92 nuniq_open_parens_(0),
93 nuniq_close_parens_(0),
94 nopen_paren_states_(0),
95 nclose_paren_states_(0) {
96 std::unordered_map<Label, size_t> paren_map;
97 std::unordered_set<Label> paren_set;
98 std::unordered_set<StateId> open_paren_state_set;
99 std::unordered_set<StateId> close_paren_state_set;
100 for (
size_t i = 0; i < parens.size(); ++i) {
101 const auto &pair = parens[i];
102 paren_map[pair.first] = i;
103 paren_map[pair.second] = i;
107 const auto s = siter.Value();
109 const auto &arc = aiter.Value();
111 const auto it = paren_map.find(arc.ilabel);
112 if (it != paren_map.end()) {
113 const auto open_paren = parens[it->second].first;
114 const auto close_paren = parens[it->second].second;
115 if (arc.ilabel == open_paren) {
117 if (paren_set.insert(open_paren).second) {
118 ++nuniq_open_parens_;
120 if (open_paren_state_set.insert(arc.nextstate).second) {
121 ++nopen_paren_states_;
125 if (paren_set.insert(close_paren).second) {
126 ++nuniq_close_parens_;
128 if (close_paren_state_set.insert(s).second) {
129 ++nclose_paren_states_;
139 const auto old = std::cout.setf(std::ios::left);
141 std::cout <<
"fst type" <<
FstType() << std::endl;
143 std::cout <<
"arc type" <<
ArcType() << std::endl;
145 std::cout <<
"# of states" <<
NumStates() << std::endl;
147 std::cout <<
"# of arcs" <<
NumArcs() << std::endl;
149 std::cout <<
"# of open parentheses" <<
NumOpenParens() << std::endl;
151 std::cout <<
"# of close parentheses" <<
NumCloseParens() << std::endl;
169 #endif // FST_EXTENSIONS_PDT_INFO_H_
int64_t NumOpenParenStates() const
typename Arc::StateId StateId
int64_t NumCloseParens() const
int64_t NumStates() const
int64_t NumUniqueOpenParens() const
typename Arc::Weight Weight
const std::string & ArcType() const
typename Arc::Label Label
int64_t NumCloseParenStates() const
int64_t NumOpenParens() const
const std::string & FstType() const
PdtInfo(const Fst< Arc > &fst, const std::vector< std::pair< Label, Label >> &parents)
int64_t NumUniqueCloseParens() const