19 #include <fst/arc-map.h> 22 #include <fst/isomorphic.h> 23 #include <fst/properties.h> 26 #ifndef NLP_GRM2_SFST_EQUAL_H_ 27 #define NLP_GRM2_SFST_EQUAL_H_ 37 using Label =
typename Arc::Label;
45 return Arc(arc.ilabel, arc.olabel,
46 arc.ilabel == phi_label_ ? Weight::One() : arc.weight,
51 return fst::MAP_NO_SUPERFINAL;
55 return fst::MAP_COPY_SYMBOLS;
59 return fst::MAP_COPY_SYMBOLS;
63 return (props & fst::kWeightInvariantProperties) | fst::kUnweighted;
77 bool Equal(
const fst::Fst<Arc> &fst1,
const fst::Fst<Arc> &fst2,
78 typename Arc::Label phi_label,
float delta = fst::kDelta,
79 uint32_t etype = fst::kEqualFsts) {
84 FSTERROR() <<
"Equal: Input FST1 is not normalized";
88 FSTERROR() <<
"Equal: Input FST2 is not normalized";
92 if (phi_label == f::kNoLabel) {
93 return f::Equal(fst1, fst2, delta, etype);
96 Mapper mapper(phi_label);
97 f::ArcMapFst mfst1(fst1, mapper);
98 f::ArcMapFst mfst2(fst2, mapper);
99 return f::Equal(mfst1, mfst2, delta, etype);
108 bool Isomorphic(
const fst::Fst<Arc> &fst1,
const fst::Fst<Arc> &fst2,
109 typename Arc::Label phi_label,
float delta = fst::kDelta) {
114 FSTERROR() <<
"Isomorphic: Input FST1 is not normalized";
118 FSTERROR() <<
"Isomorphic: Input FST2 is not normalized";
122 if (phi_label == f::kNoLabel) {
126 Mapper mapper(phi_label);
127 f::ArcMapFst mfst1(fst1, mapper);
128 f::ArcMapFst mfst2(fst2, mapper);
135 #endif // NLP_GRM2_SFST_EQUAL_H_
RmPhiWeightMapper(Label phi_label)
typename Arc::Label Label
constexpr fst::MapSymbolsAction InputSymbolsAction() const
bool Isomorphic(const fst::Fst< Arc > &fst1, const fst::Fst< Arc > &fst2, typename Arc::Label phi_label, float delta=fst::kDelta)
uint64_t Properties(uint64_t props) const
typename Arc::Weight Weight
bool Equal(const fst::Fst< Arc > &fst1, const fst::Fst< Arc > &fst2, typename Arc::Label phi_label, float delta=fst::kDelta, uint32_t etype=fst::kEqualFsts)
bool IsNormalized(const fst::Fst< Arc > &fst, typename Arc::Label phi_label=fst::kNoLabel, float delta=fst::kDelta)
constexpr fst::MapSymbolsAction OutputSymbolsAction() const
Arc operator()(const Arc &arc) const
constexpr fst::MapFinalAction FinalAction() const