20 #ifndef FST_EXTENSIONS_PDT_INFO_H_ 21 #define FST_EXTENSIONS_PDT_INFO_H_ 29 #include <unordered_map> 30 #include <unordered_set> 38 using Label =
typename Arc::Label;
43 const std::vector<std::pair<Label, Label>> &parents);
45 const std::string &
FstType()
const {
return fst_type_; }
47 const std::string &
ArcType()
const {
return Arc::Type(); }
51 int64_t
NumArcs()
const {
return narcs_; }
68 std::string fst_type_;
71 int64_t nopen_parens_;
72 int64_t nclose_parens_;
73 int64_t nuniq_open_parens_;
74 int64_t nuniq_close_parens_;
75 int64_t nopen_paren_states_;
76 int64_t nclose_paren_states_;
82 const std::vector<std::pair<typename Arc::Label, typename Arc::Label>>
84 : fst_type_(fst.Type()),
89 nuniq_open_parens_(0),
90 nuniq_close_parens_(0),
91 nopen_paren_states_(0),
92 nclose_paren_states_(0) {
93 std::unordered_map<Label, size_t> paren_map;
94 std::unordered_set<Label> paren_set;
95 std::unordered_set<StateId> open_paren_state_set;
96 std::unordered_set<StateId> close_paren_state_set;
97 for (
size_t i = 0; i < parens.size(); ++i) {
98 const auto &pair = parens[i];
99 paren_map[pair.first] = i;
100 paren_map[pair.second] = i;
104 const auto s = siter.Value();
106 const auto &arc = aiter.Value();
108 const auto it = paren_map.find(arc.ilabel);
109 if (it != paren_map.end()) {
110 const auto open_paren = parens[it->second].first;
111 const auto close_paren = parens[it->second].second;
112 if (arc.ilabel == open_paren) {
114 if (paren_set.insert(open_paren).second) {
115 ++nuniq_open_parens_;
117 if (open_paren_state_set.insert(arc.nextstate).second) {
118 ++nopen_paren_states_;
122 if (paren_set.insert(close_paren).second) {
123 ++nuniq_close_parens_;
125 if (close_paren_state_set.insert(s).second) {
126 ++nclose_paren_states_;
136 const auto old = std::cout.setf(std::ios::left);
138 std::cout <<
"fst type" <<
FstType() << std::endl;
140 std::cout <<
"arc type" <<
ArcType() << std::endl;
142 std::cout <<
"# of states" <<
NumStates() << std::endl;
144 std::cout <<
"# of arcs" <<
NumArcs() << std::endl;
146 std::cout <<
"# of open parentheses" <<
NumOpenParens() << std::endl;
148 std::cout <<
"# of close parentheses" <<
NumCloseParens() << std::endl;
166 #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