18 #ifndef FST_EXTENSIONS_SPECIAL_PHI_FST_H_ 19 #define FST_EXTENSIONS_SPECIAL_PHI_FST_H_ 42 template <
class Label>
46 Label phi_label = FST_FLAGS_phi_fst_phi_label,
47 bool phi_loop = FST_FLAGS_phi_fst_phi_loop,
50 : phi_label_(phi_label),
52 rewrite_mode_(rewrite_mode) {}
55 : phi_label_(data.phi_label_),
56 phi_loop_(data.phi_loop_),
57 rewrite_mode_(data.rewrite_mode_) {}
61 auto data = std::make_unique<PhiFstMatcherData<Label>>();
67 return data.release();
73 WriteType(ostrm, static_cast<int32_t>(rewrite_mode_));
74 return !ostrm ?
false :
true;
79 bool PhiLoop()
const {
return phi_loop_; }
88 LOG(WARNING) <<
"PhiFst: Unknown rewrite mode: " << mode <<
". " 89 <<
"Defaulting to auto.";
105 template <
class M, u
int8_t flags = kPhiFstMatchInput | kPhiFstMatchOutput>
109 using Arc =
typename M::Arc;
115 static constexpr uint8_t kFlags = flags;
120 std::shared_ptr<MatcherData> data = std::make_shared<MatcherData>())
131 std::shared_ptr<MatcherData> data = std::make_shared<MatcherData>())
141 :
PhiMatcher<M>(matcher, safe), data_(matcher.data_) {}
153 if (match_type ==
MATCH_INPUT && flags & kPhiFstMatchInput)
return label;
154 if (match_type ==
MATCH_OUTPUT && flags & kPhiFstMatchOutput)
return label;
158 std::shared_ptr<MatcherData> data_;
175 PhiFstMatcher<SortedMatcher<ConstFst<Arc>>, kPhiFstMatchInput>,
183 PhiFstMatcher<SortedMatcher<ConstFst<Arc>>, kPhiFstMatchOutput>,
184 output_phi_fst_type>;
190 #endif // FST_EXTENSIONS_SPECIAL_PHI_FST_H_
DECLARE_int64(phi_fst_phi_label)
PhiFstMatcher< M, flags > * Copy(bool safe=false) const override
PhiFstMatcherData(Label phi_label=FST_FLAGS_phi_fst_phi_label, bool phi_loop=FST_FLAGS_phi_fst_phi_loop, MatcherRewriteMode rewrite_mode=RewriteMode(FST_FLAGS_phi_fst_rewrite_mode))
MatcherRewriteMode RewriteMode() const
typename Arc::StateId StateId
bool Write(std::ostream &ostrm, const FstWriteOptions &opts) const
constexpr uint8_t kPhiFstMatchInput
std::ostream & WriteType(std::ostream &strm, const T t)
std::shared_ptr< MatcherData > GetSharedData() const
PhiFstMatcherData(const PhiFstMatcherData &data)
constexpr char output_phi_fst_type[]
PhiFstMatcher(const PhiFstMatcher< M, flags > &matcher, bool safe=false)
const MatcherData * GetData() const
DECLARE_bool(phi_fst_phi_loop)
static PhiFstMatcherData< Label > * Read(std::istream &istrm, const FstReadOptions &read)
PhiFstMatcher(const FST &fst, MatchType match_type, std::shared_ptr< MatcherData > data=std::make_shared< MatcherData >())
DECLARE_string(phi_fst_rewrite_mode)
std::istream & ReadType(std::istream &strm, T *t)
constexpr char phi_fst_type[]
typename Arc::Weight Weight
typename Arc::Label Label
constexpr char input_phi_fst_type[]
constexpr uint8_t kPhiFstMatchOutput
PhiFstMatcher(const FST *fst, MatchType match_type, std::shared_ptr< MatcherData > data=std::make_shared< MatcherData >())