21 #ifndef FST_COMPOSE_FILTER_H_ 22 #define FST_COMPOSE_FILTER_H_ 96 template <
class M1,
class M2 >
105 using Arc =
typename FST1::Arc;
114 fst1_(matcher1_->GetFst()),
115 fst2_(matcher2_->GetFst()) {}
118 : matcher1_(filter.matcher1_->Copy(safe)),
119 matcher2_(filter.matcher2_->Copy(safe)),
120 fst1_(matcher1_->GetFst()),
121 fst2_(matcher2_->GetFst()) {}
142 std::unique_ptr<Matcher1> matcher1_;
143 std::unique_ptr<Matcher2> matcher2_;
158 template <
class M1,
class M2 >
167 using Arc =
typename FST1::Arc;
177 fst1_(matcher1_->GetFst()),
178 fst2_(matcher2_->GetFst()) {}
182 : matcher1_(filter.matcher1_->Copy(safe)),
183 matcher2_(filter.matcher2_->Copy(safe)),
184 fst1_(matcher1_->GetFst()),
185 fst2_(matcher2_->GetFst()) {}
202 std::unique_ptr<Matcher1> matcher1_;
203 std::unique_ptr<Matcher2> matcher2_;
209 template <
class M1,
class M2 >
218 using Arc =
typename FST1::Arc;
228 fst1_(matcher1_->GetFst()),
235 : matcher1_(filter.matcher1_->Copy(safe)),
236 matcher2_(filter.matcher2_->Copy(safe)),
237 fst1_(matcher1_->GetFst()),
245 if (s1_ == s1 && s2_ == s2 && fs == fs_)
return;
252 alleps1_ = na1 == ne1 && !fin1;
261 }
else if (arc2->ilabel ==
kNoLabel) {
277 std::unique_ptr<Matcher1> matcher1_;
278 std::unique_ptr<Matcher2> matcher2_;
288 template <
class M1,
class M2 >
297 using Arc =
typename FST1::Arc;
307 fst2_(matcher2_->GetFst()),
315 : matcher1_(filter.matcher1_->Copy(safe)),
316 matcher2_(filter.matcher2_->Copy(safe)),
317 fst2_(matcher2_->GetFst()),
325 if (s1_ == s1 && s2_ == s2 && fs == fs_)
return;
332 alleps2_ = na2 == ne2 && !fin2;
341 }
else if (arc1->olabel ==
kNoLabel) {
357 std::unique_ptr<Matcher1> matcher1_;
358 std::unique_ptr<Matcher2> matcher2_;
369 template <
class M1,
class M2 >
378 using Arc =
typename FST1::Arc;
387 fst1_(matcher1_->GetFst()),
388 fst2_(matcher2_->GetFst()),
395 : matcher1_(filter.matcher1_->Copy(safe)),
396 matcher2_(filter.matcher2_->Copy(safe)),
397 fst1_(matcher1_->GetFst()),
398 fst2_(matcher2_->GetFst()),
406 if (s1_ == s1 && s2_ == s2 && fs == fs_)
return;
413 alleps1_ = na1 == ne1 && !f1;
418 alleps2_ = na2 == ne2 && !f2;
430 }
else if (arc1->olabel ==
kNoLabel) {
437 }
else if (arc1->olabel == 0) {
453 std::unique_ptr<Matcher1> matcher1_;
454 std::unique_ptr<Matcher2> matcher2_;
477 template <
class M1,
class M2 >
486 using Arc =
typename FST1::Arc;
496 fst1_(matcher1_->GetFst()),
497 fst2_(matcher2_->GetFst()) {}
501 : matcher1_(filter.matcher1_->Copy(safe)),
502 matcher2_(filter.matcher2_->Copy(safe)),
503 fst1_(matcher1_->GetFst()),
504 fst2_(matcher2_->GetFst()) {}
511 return FilterState(arc1->olabel != 0 || arc2->ilabel != 0);
523 std::unique_ptr<Matcher1> matcher1_;
524 std::unique_ptr<Matcher2> matcher2_;
532 template <
class Filter>
537 using FST1 =
typename Filter::FST1;
538 using FST2 =
typename Filter::FST2;
541 using Arc =
typename Filter::Arc;
548 bool keep_multi_eps =
false)
549 : filter_(fst1, fst2, matcher1, matcher2),
550 keep_multi_eps_(keep_multi_eps) {}
553 : filter_(filter.filter_, safe),
554 keep_multi_eps_(filter.keep_multi_eps_) {}
559 return filter_.SetState(s1, s2, fs);
563 const auto fs = filter_.FilterArc(arc1, arc2);
564 if (keep_multi_eps_) {
565 if (arc1->olabel ==
kNoLabel) arc1->ilabel = arc2->ilabel;
566 if (arc2->ilabel ==
kNoLabel) arc2->olabel = arc1->olabel;
572 return filter_.FilterFinal(w1, w2);
580 const auto oprops = filter_.Properties(iprops);
586 bool keep_multi_eps_;
591 #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