21 #ifndef FST_COMPOSE_FILTER_H_ 22 #define FST_COMPOSE_FILTER_H_ 95 template <
class M1,
class M2 >
104 using Arc =
typename FST1::Arc;
113 fst1_(matcher1_->GetFst()),
114 fst2_(matcher2_->GetFst()) {}
117 : matcher1_(filter.matcher1_->Copy(safe)),
118 matcher2_(filter.matcher2_->Copy(safe)),
119 fst1_(matcher1_->GetFst()),
120 fst2_(matcher2_->GetFst()) {}
141 std::unique_ptr<Matcher1> matcher1_;
142 std::unique_ptr<Matcher2> matcher2_;
157 template <
class M1,
class M2 >
166 using Arc =
typename FST1::Arc;
176 fst1_(matcher1_->GetFst()),
177 fst2_(matcher2_->GetFst()) {}
181 : matcher1_(filter.matcher1_->Copy(safe)),
182 matcher2_(filter.matcher2_->Copy(safe)),
183 fst1_(matcher1_->GetFst()),
184 fst2_(matcher2_->GetFst()) {}
201 std::unique_ptr<Matcher1> matcher1_;
202 std::unique_ptr<Matcher2> matcher2_;
208 template <
class M1,
class M2 >
217 using Arc =
typename FST1::Arc;
227 fst1_(matcher1_->GetFst()),
234 : matcher1_(filter.matcher1_->Copy(safe)),
235 matcher2_(filter.matcher2_->Copy(safe)),
236 fst1_(matcher1_->GetFst()),
244 if (s1_ == s1 && s2_ == s2 && fs == fs_)
return;
251 alleps1_ = na1 == ne1 && !fin1;
259 }
else if (arc2->ilabel ==
kNoLabel) {
275 std::unique_ptr<Matcher1> matcher1_;
276 std::unique_ptr<Matcher2> matcher2_;
286 template <
class M1,
class M2 >
295 using Arc =
typename FST1::Arc;
305 fst2_(matcher2_->GetFst()),
313 : matcher1_(filter.matcher1_->Copy(safe)),
314 matcher2_(filter.matcher2_->Copy(safe)),
315 fst2_(matcher2_->GetFst()),
323 if (s1_ == s1 && s2_ == s2 && fs == fs_)
return;
330 alleps2_ = na2 == ne2 && !fin2;
338 }
else if (arc1->olabel ==
kNoLabel) {
354 std::unique_ptr<Matcher1> matcher1_;
355 std::unique_ptr<Matcher2> matcher2_;
366 template <
class M1,
class M2 >
375 using Arc =
typename FST1::Arc;
384 fst1_(matcher1_->GetFst()),
385 fst2_(matcher2_->GetFst()),
392 : matcher1_(filter.matcher1_->Copy(safe)),
393 matcher2_(filter.matcher2_->Copy(safe)),
394 fst1_(matcher1_->GetFst()),
395 fst2_(matcher2_->GetFst()),
403 if (s1_ == s1 && s2_ == s2 && fs == fs_)
return;
410 alleps1_ = na1 == ne1 && !f1;
415 alleps2_ = na2 == ne2 && !f2;
427 }
else if (arc1->olabel ==
kNoLabel) {
434 }
else if (arc1->olabel == 0) {
450 std::unique_ptr<Matcher1> matcher1_;
451 std::unique_ptr<Matcher2> matcher2_;
474 template <
class M1,
class M2 >
483 using Arc =
typename FST1::Arc;
493 fst1_(matcher1_->GetFst()),
494 fst2_(matcher2_->GetFst()) {}
498 : matcher1_(filter.matcher1_->Copy(safe)),
499 matcher2_(filter.matcher2_->Copy(safe)),
500 fst1_(matcher1_->GetFst()),
501 fst2_(matcher2_->GetFst()) {}
508 return FilterState(arc1->olabel != 0 || arc2->ilabel != 0);
520 std::unique_ptr<Matcher1> matcher1_;
521 std::unique_ptr<Matcher2> matcher2_;
529 template <
class Filter>
534 using FST1 =
typename Filter::FST1;
535 using FST2 =
typename Filter::FST2;
538 using Arc =
typename Filter::Arc;
545 bool keep_multi_eps =
false)
546 : filter_(fst1, fst2, matcher1, matcher2),
547 keep_multi_eps_(keep_multi_eps) {}
550 : filter_(filter.filter_, safe),
551 keep_multi_eps_(filter.keep_multi_eps_) {}
556 return filter_.SetState(s1, s2, fs);
560 const auto fs = filter_.FilterArc(arc1, arc2);
561 if (keep_multi_eps_) {
562 if (arc1->olabel ==
kNoLabel) arc1->ilabel = arc2->ilabel;
563 if (arc2->ilabel ==
kNoLabel) arc2->olabel = arc1->olabel;
569 return filter_.FilterFinal(w1, w2);
577 const auto oprops = filter_.Properties(iprops);
583 bool keep_multi_eps_;
588 #endif // FST_COMPOSE_FILTER_H_
ssize_t NumOutputEpsilons(const ExpandedFst< Arc > &fst, typename Arc::StateId s)
void SetState(StateId s1, StateId s2, const FilterState &fs)
uint64_t Properties(uint64_t props) const
uint64_t Properties(uint64_t props) const
typename Arc::Label Label
typename Filter::Matcher2 Matcher2
typename Arc::StateId StateId
void FilterFinal(Weight *, Weight *) const
NoMatchComposeFilter(const FST1 &fst1, const FST2 &fst2, Matcher1 *matcher1=nullptr, Matcher2 *matcher2=nullptr)
TrivialComposeFilter(const TrivialComposeFilter< Matcher1, Matcher2 > &filter, bool safe=false)
typename Arc::Weight Weight
SequenceComposeFilter(const FST1 &fst1, const FST2 &fst2, Matcher1 *matcher1=nullptr, Matcher2 *matcher2=nullptr)
typename Arc::Label Label
void SetState(StateId s1, StateId s2, const FilterState &fs)
void SetState(StateId, StateId, const FilterState &)
MatchComposeFilter(const MatchComposeFilter< Matcher1, Matcher2 > &filter, bool safe=false)
void FilterFinal(Weight *w1, Weight *w2) const
typename Arc::StateId StateId
void SetState(StateId, StateId, const FilterState &)
void FilterFinal(Weight *, Weight *) const
void FilterFinal(Weight *, Weight *) const
Arc::Weight Final(const ExpandedFst< Arc > &fst, typename Arc::StateId s)
typename Arc::Label Label
uint64_t Properties(uint64_t props) const
void SetState(StateId s1, StateId s2, const FilterState &fs)
FilterState FilterArc(Arc *arc1, Arc *arc2) const
NoMatchComposeFilter(const NoMatchComposeFilter< Matcher1, Matcher2 > &filter, bool safe=false)
typename Filter::Matcher1 Matcher1
typename Arc::StateId StateId
void SetState(StateId s1, StateId s2, const FilterState &fs)
FilterState FilterArc(Arc *arc1, Arc *arc2) const
AltSequenceComposeFilter(const AltSequenceComposeFilter< Matcher1, Matcher2 > &filter, bool safe=false)
typename Arc::Label Label
ssize_t NumArcs(const ExpandedFst< Arc > &fst, typename Arc::StateId s)
TrivialFilterState FilterState
FilterState Start() const
void SetState(StateId, StateId, const FilterState &)
void FilterFinal(Weight *, Weight *) const
typename Arc::Weight Weight
TrivialComposeFilter(const FST1 &fst1, const FST2 &fst2, Matcher1 *matcher1=nullptr, Matcher2 *matcher2=nullptr)
typename Filter::FilterState FilterState
static const TrivialFilterState NoState()
IntegerFilterState< signed char > CharFilterState
typename Arc::Label Label
uint64_t Properties(uint64_t props) const
ssize_t NumInputEpsilons(const ExpandedFst< Arc > &fst, typename Arc::StateId s)
uint64_t Properties(uint64_t props) const
MultiEpsFilter(const FST1 &fst1, const FST2 &fst2, Matcher1 *matcher1=nullptr, Matcher2 *matcher2=nullptr, bool keep_multi_eps=false)
FilterState FilterArc(Arc *arc1, Arc *arc2) const
typename Arc::Weight Weight
FilterState Start() const
uint64_t Properties(uint64_t iprops) const
typename Arc::Weight Weight
FilterState FilterArc(Arc *, Arc *) const
constexpr uint64_t kOLabelInvariantProperties
void FilterFinal(Weight *, Weight *) const
typename Arc::Weight Weight
typename Filter::FST2 FST2
typename ParenMatcher< Fst< Arc > >::FST FST1
void FilterFinal(Weight *, Weight *) const
constexpr uint64_t kILabelInvariantProperties
typename Arc::StateId StateId
FilterState Start() const
NullComposeFilter(const FST1 &fst1, const FST2 &fst2, Matcher1 *matcher1=nullptr, Matcher2 *matcher2=nullptr)
typename Arc::Label Label
FilterState Start() const
uint64_t Properties(uint64_t props) const
FilterState Start() const
typename Arc::StateId StateId
typename Arc::Weight Weight
typename Arc::Weight Weight
typename Arc::StateId StateId
FilterState Start() const
NullComposeFilter(const NullComposeFilter &filter, bool safe=false)
AltSequenceComposeFilter(const FST1 &fst1, const FST2 &fst2, Matcher1 *matcher1=nullptr, Matcher2 *matcher2=nullptr)
FilterState FilterArc(Arc *arc1, Arc *arc2) const
typename ParenMatcher< Fst< Arc > >::FST FST1
typename Arc::Label Label
FilterState FilterArc(Arc *arc1, Arc *arc2) const
MatchComposeFilter(const FST1 &fst1, const FST2 &fst2, Matcher1 *matcher1=nullptr, Matcher2 *matcher2=nullptr)
typename Filter::FST1 FST1
typename Arc::StateId StateId
FilterState FilterArc(Arc *arc1, Arc *arc2) const
SequenceComposeFilter(const SequenceComposeFilter< Matcher1, Matcher2 > &filter, bool safe=false)
MultiEpsFilter(const MultiEpsFilter &filter, bool safe=false)
FilterState Start() const