FST  openfst-1.8.3
OpenFst Library
compose-filter.h
Go to the documentation of this file.
1 // Copyright 2005-2024 Google LLC
2 //
3 // Licensed under the Apache License, Version 2.0 (the 'License');
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 // http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an 'AS IS' BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14 //
15 // See www.openfst.org for extensive documentation on this weighted
16 // finite-state transducer library.
17 //
18 // Classes for filtering the composition matches, e.g. for correct epsilon
19 // handling.
20 
21 #ifndef FST_COMPOSE_FILTER_H_
22 #define FST_COMPOSE_FILTER_H_
23 
24 #include <cstddef>
25 #include <cstdint>
26 #include <memory>
27 
28 #include <fst/filter-state.h>
29 #include <fst/fst-decl.h> // For optional argument declarations
30 #include <fst/fst.h>
31 #include <fst/matcher.h>
32 #include <fst/properties.h>
33 
34 namespace fst {
35 
36 // Composition filters determine which matches are allowed to proceed. The
37 // filter's state is represeted by the type ComposeFilter::FilterState.
38 // The basic filters handle correct epsilon matching. Their interface is:
39 //
40 // template <class M1, class M2>
41 // class ComposeFilter {
42 // public:
43 // using Matcher1 = ...;
44 // using Matcher2 = ...;
45 // using FST1 = typename M1::FST;
46 // using FST2 = typename M2::FST;
47 // using FilterState = ...;
48 //
49 // using Arc = typename FST1::Arc;
50 // using StateId = typename Arc::StateId;
51 // using Weight = typename Arc::Weight;
52 //
53 // // Required constructor.
54 // ComposeFilter(const FST1 &fst1, const FST2 &fst2,
55 // M1 *matcher1 = nullptr, M2 *matcher2 = nullptr);
56 //
57 // // If safe=true, the copy is thread-safe. See Fst<>::Copy()
58 // // for further doc.
59 // ComposeFilter(const ComposeFilter<M1, M2> &filter,
60 // bool safe = false);
61 //
62 // // Return start state of filter.
63 // FilterState Start() const;
64 //
65 // // Specifies current composition state.
66 // void SetState(StateId s1, StateId s2, const FilterState &fs);
67 //
68 // // Apply filter at current composition state to these transitions. If an
69 // // arc label to be matched is kNolabel, then that side does not consume a
70 // // symbol. Returns the new filter state or, if disallowed,
71 // // FilterState::NoState(). The filter is permitted to modify its inputs
72 // // (e.g. for optimization reasons).
73 // FilterState FilterArc(Arc *arc1, Arc *arc2) const;
74 
75 // // Apply filter at current composition state to these final weights
76 // // (cf. superfinal transitions). The filter may modify its inputs
77 // // (e.g. for optimization reasons).
78 // void FilterFinal(Weight *w1, Weight *w2) const;
79 //
80 // // Return the respective matchers. Ownership stays with filter. These
81 // // methods allow the filter to access and possibly modify the compositio
82 // // matchers (useful, e.g., with lookahead).
83 //
84 // Matcher1 *GetMatcher1();
85 //
86 // Matcher2 *GetMatcher2();
87 //
88 // // This specifies how the filter affects the composition result properties.
89 // It takes as argument the properties that would apply with a trivial
90 // // composition filter.
91 // uint64_t Properties(uint64_t props) const;
92 // };
93 //
94 // This filter allows only exact matching of symbols from FST1 with on FST2;
95 // e.g., no special interpretation of epsilons.
96 template <class M1, class M2 /* = M1 */>
98  public:
99  using Matcher1 = M1;
100  using Matcher2 = M2;
101  using FST1 = typename M1::FST;
102  using FST2 = typename M2::FST;
104 
105  using Arc = typename FST1::Arc;
106  using Label = typename Arc::Label;
107  using StateId = typename Arc::StateId;
108  using Weight = typename Arc::Weight;
109 
110  NullComposeFilter(const FST1 &fst1, const FST2 &fst2,
111  Matcher1 *matcher1 = nullptr, Matcher2 *matcher2 = nullptr)
112  : matcher1_(matcher1 ? matcher1 : new Matcher1(fst1, MATCH_OUTPUT)),
113  matcher2_(matcher2 ? matcher2 : new Matcher2(fst2, MATCH_INPUT)),
114  fst1_(matcher1_->GetFst()),
115  fst2_(matcher2_->GetFst()) {}
116 
117  NullComposeFilter(const NullComposeFilter &filter, bool safe = false)
118  : matcher1_(filter.matcher1_->Copy(safe)),
119  matcher2_(filter.matcher2_->Copy(safe)),
120  fst1_(matcher1_->GetFst()),
121  fst2_(matcher2_->GetFst()) {}
122 
123  FilterState Start() const { return FilterState(true); }
124 
125  void SetState(StateId, StateId, const FilterState &) {}
126 
127  FilterState FilterArc(Arc *arc1, Arc *arc2) const {
128  return (arc1->olabel == kNoLabel || arc2->ilabel == kNoLabel)
130  : FilterState(true);
131  }
132 
133  void FilterFinal(Weight *, Weight *) const {}
134 
135  Matcher1 *GetMatcher1() { return matcher1_.get(); }
136 
137  Matcher2 *GetMatcher2() { return matcher2_.get(); }
138 
139  uint64_t Properties(uint64_t props) const { return props; }
140 
141  private:
142  std::unique_ptr<Matcher1> matcher1_;
143  std::unique_ptr<Matcher2> matcher2_;
144  const FST1 &fst1_;
145  const FST2 &fst2_;
146 };
147 
148 // This filter allows all epsilon matches, potentially resulting in redundant
149 // epsilon paths. The use of this filter gives correct results iff one of the
150 // following conditions hold:
151 //
152 // (1) The semiring is idempotent,
153 // (2) the first FST is output-epsilon free, or
154 // (3) the second FST is input-epsilon free.
155 //
156 // For (1), redundant epsilon paths may be created but won't hurt correctness.
157 // For (2) and (3), no redundant paths are created.
158 template <class M1, class M2 /* = M1 */>
160  public:
161  using Matcher1 = M1;
162  using Matcher2 = M2;
163  using FST1 = typename M1::FST;
164  using FST2 = typename M2::FST;
166 
167  using Arc = typename FST1::Arc;
168  using Label = typename Arc::Label;
169  using StateId = typename Arc::StateId;
170  using Weight = typename Arc::Weight;
171 
172  TrivialComposeFilter(const FST1 &fst1, const FST2 &fst2,
173  Matcher1 *matcher1 = nullptr,
174  Matcher2 *matcher2 = nullptr)
175  : matcher1_(matcher1 ? matcher1 : new Matcher1(fst1, MATCH_OUTPUT)),
176  matcher2_(matcher2 ? matcher2 : new Matcher2(fst2, MATCH_INPUT)),
177  fst1_(matcher1_->GetFst()),
178  fst2_(matcher2_->GetFst()) {}
179 
181  bool safe = false)
182  : matcher1_(filter.matcher1_->Copy(safe)),
183  matcher2_(filter.matcher2_->Copy(safe)),
184  fst1_(matcher1_->GetFst()),
185  fst2_(matcher2_->GetFst()) {}
186 
187  FilterState Start() const { return FilterState(true); }
188 
189  void SetState(StateId, StateId, const FilterState &) {}
190 
191  FilterState FilterArc(Arc *, Arc *) const { return FilterState(true); }
192 
193  void FilterFinal(Weight *, Weight *) const {}
194 
195  Matcher1 *GetMatcher1() { return matcher1_.get(); }
196 
197  Matcher2 *GetMatcher2() { return matcher2_.get(); }
198 
199  uint64_t Properties(uint64_t props) const { return props; }
200 
201  private:
202  std::unique_ptr<Matcher1> matcher1_;
203  std::unique_ptr<Matcher2> matcher2_;
204  const FST1 &fst1_;
205  const FST2 &fst2_;
206 };
207 
208 // This filter requires epsilons on FST1 to be read before epsilons on FST2.
209 template <class M1, class M2 /* = M1 */>
211  public:
212  using Matcher1 = M1;
213  using Matcher2 = M2;
214  using FST1 = typename M1::FST;
215  using FST2 = typename M2::FST;
217 
218  using Arc = typename FST1::Arc;
219  using Label = typename Arc::Label;
220  using StateId = typename Arc::StateId;
221  using Weight = typename Arc::Weight;
222 
223  SequenceComposeFilter(const FST1 &fst1, const FST2 &fst2,
224  Matcher1 *matcher1 = nullptr,
225  Matcher2 *matcher2 = nullptr)
226  : matcher1_(matcher1 ? matcher1 : new Matcher1(fst1, MATCH_OUTPUT)),
227  matcher2_(matcher2 ? matcher2 : new Matcher2(fst2, MATCH_INPUT)),
228  fst1_(matcher1_->GetFst()),
229  s1_(kNoStateId),
230  s2_(kNoStateId),
231  fs_(kNoStateId) {}
232 
234  bool safe = false)
235  : matcher1_(filter.matcher1_->Copy(safe)),
236  matcher2_(filter.matcher2_->Copy(safe)),
237  fst1_(matcher1_->GetFst()),
238  s1_(kNoStateId),
239  s2_(kNoStateId),
240  fs_(kNoStateId) {}
241 
242  FilterState Start() const { return FilterState(0); }
243 
244  void SetState(StateId s1, StateId s2, const FilterState &fs) {
245  if (s1_ == s1 && s2_ == s2 && fs == fs_) return;
246  s1_ = s1;
247  s2_ = s2;
248  fs_ = fs;
249  const auto na1 = internal::NumArcs(fst1_, s1);
250  const auto ne1 = internal::NumOutputEpsilons(fst1_, s1);
251  const bool fin1 = internal::Final(fst1_, s1) != Weight::Zero();
252  alleps1_ = na1 == ne1 && !fin1;
253  noeps1_ = ne1 == 0;
254  }
255 
256  FilterState FilterArc(Arc *arc1, Arc *arc2) const {
257  if (arc1->olabel == kNoLabel) {
258  return alleps1_ ? FilterState::NoState()
259  : noeps1_ ? FilterState(0)
260  : FilterState(1);
261  } else if (arc2->ilabel == kNoLabel) {
262  return fs_ != FilterState(0) ? FilterState::NoState() : FilterState(0);
263  } else {
264  return arc1->olabel == 0 ? FilterState::NoState() : FilterState(0);
265  }
266  }
267 
268  void FilterFinal(Weight *, Weight *) const {}
269 
270  Matcher1 *GetMatcher1() { return matcher1_.get(); }
271 
272  Matcher2 *GetMatcher2() { return matcher2_.get(); }
273 
274  uint64_t Properties(uint64_t props) const { return props; }
275 
276  private:
277  std::unique_ptr<Matcher1> matcher1_;
278  std::unique_ptr<Matcher2> matcher2_;
279  const FST1 &fst1_;
280  StateId s1_; // Current fst1_ state.
281  StateId s2_; // Current fst2_ state.
282  FilterState fs_; // Current filter state.
283  bool alleps1_; // Only epsilons (and non-final) leaving s1_?
284  bool noeps1_; // No epsilons leaving s1_?
285 };
286 
287 // This filter requires epsilons on FST2 to be read before epsilons on FST1.
288 template <class M1, class M2 /* = M1 */>
290  public:
291  using Matcher1 = M1;
292  using Matcher2 = M2;
293  using FST1 = typename M1::FST;
294  using FST2 = typename M2::FST;
296 
297  using Arc = typename FST1::Arc;
298  using Label = typename Arc::Label;
299  using StateId = typename Arc::StateId;
300  using Weight = typename Arc::Weight;
301 
302  AltSequenceComposeFilter(const FST1 &fst1, const FST2 &fst2,
303  Matcher1 *matcher1 = nullptr,
304  Matcher2 *matcher2 = nullptr)
305  : matcher1_(matcher1 ? matcher1 : new Matcher1(fst1, MATCH_OUTPUT)),
306  matcher2_(matcher2 ? matcher2 : new Matcher2(fst2, MATCH_INPUT)),
307  fst2_(matcher2_->GetFst()),
308  s1_(kNoStateId),
309  s2_(kNoStateId),
310  fs_(kNoStateId) {}
311 
314  bool safe = false)
315  : matcher1_(filter.matcher1_->Copy(safe)),
316  matcher2_(filter.matcher2_->Copy(safe)),
317  fst2_(matcher2_->GetFst()),
318  s1_(kNoStateId),
319  s2_(kNoStateId),
320  fs_(kNoStateId) {}
321 
322  FilterState Start() const { return FilterState(0); }
323 
324  void SetState(StateId s1, StateId s2, const FilterState &fs) {
325  if (s1_ == s1 && s2_ == s2 && fs == fs_) return;
326  s1_ = s1;
327  s2_ = s2;
328  fs_ = fs;
329  const auto na2 = internal::NumArcs(fst2_, s2);
330  const auto ne2 = internal::NumInputEpsilons(fst2_, s2);
331  const bool fin2 = internal::Final(fst2_, s2) != Weight::Zero();
332  alleps2_ = na2 == ne2 && !fin2;
333  noeps2_ = ne2 == 0;
334  }
335 
336  FilterState FilterArc(Arc *arc1, Arc *arc2) const {
337  if (arc2->ilabel == kNoLabel) {
338  return alleps2_ ? FilterState::NoState()
339  : noeps2_ ? FilterState(0)
340  : FilterState(1);
341  } else if (arc1->olabel == kNoLabel) {
342  return fs_ == FilterState(1) ? FilterState::NoState() : FilterState(0);
343  } else {
344  return arc1->olabel == 0 ? FilterState::NoState() : FilterState(0);
345  }
346  }
347 
348  void FilterFinal(Weight *, Weight *) const {}
349 
350  Matcher1 *GetMatcher1() { return matcher1_.get(); }
351 
352  Matcher2 *GetMatcher2() { return matcher2_.get(); }
353 
354  uint64_t Properties(uint64_t props) const { return props; }
355 
356  private:
357  std::unique_ptr<Matcher1> matcher1_;
358  std::unique_ptr<Matcher2> matcher2_;
359  const FST2 &fst2_;
360  StateId s1_; // Current fst1_ state.
361  StateId s2_; // Current fst2_ state.
362  FilterState fs_; // Current filter state.
363  bool alleps2_; // Only epsilons (and non-final) leaving s2_?
364  bool noeps2_; // No epsilons leaving s2_?
365 };
366 
367 // This filter requires epsilons on FST1 to be matched with epsilons on FST2
368 // whenever possible. (Template arg default declared in fst-decl.h.)
369 template <class M1, class M2 /* = M1 */>
371  public:
372  using Matcher1 = M1;
373  using Matcher2 = M2;
374  using FST1 = typename M1::FST;
375  using FST2 = typename M2::FST;
377 
378  using Arc = typename FST1::Arc;
379  using Label = typename Arc::Label;
380  using StateId = typename Arc::StateId;
381  using Weight = typename Arc::Weight;
382 
383  MatchComposeFilter(const FST1 &fst1, const FST2 &fst2,
384  Matcher1 *matcher1 = nullptr, Matcher2 *matcher2 = nullptr)
385  : matcher1_(matcher1 ? matcher1 : new Matcher1(fst1, MATCH_OUTPUT)),
386  matcher2_(matcher2 ? matcher2 : new Matcher2(fst2, MATCH_INPUT)),
387  fst1_(matcher1_->GetFst()),
388  fst2_(matcher2_->GetFst()),
389  s1_(kNoStateId),
390  s2_(kNoStateId),
391  fs_(kNoStateId) {}
392 
394  bool safe = false)
395  : matcher1_(filter.matcher1_->Copy(safe)),
396  matcher2_(filter.matcher2_->Copy(safe)),
397  fst1_(matcher1_->GetFst()),
398  fst2_(matcher2_->GetFst()),
399  s1_(kNoStateId),
400  s2_(kNoStateId),
401  fs_(kNoStateId) {}
402 
403  FilterState Start() const { return FilterState(0); }
404 
405  void SetState(StateId s1, StateId s2, const FilterState &fs) {
406  if (s1_ == s1 && s2_ == s2 && fs == fs_) return;
407  s1_ = s1;
408  s2_ = s2;
409  fs_ = fs;
410  size_t na1 = internal::NumArcs(fst1_, s1);
411  size_t ne1 = internal::NumOutputEpsilons(fst1_, s1);
412  bool f1 = internal::Final(fst1_, s1) != Weight::Zero();
413  alleps1_ = na1 == ne1 && !f1;
414  noeps1_ = ne1 == 0;
415  size_t na2 = internal::NumArcs(fst2_, s2);
416  size_t ne2 = internal::NumInputEpsilons(fst2_, s2);
417  bool f2 = internal::Final(fst2_, s2) != Weight::Zero();
418  alleps2_ = na2 == ne2 && !f2;
419  noeps2_ = ne2 == 0;
420  }
421 
422  FilterState FilterArc(Arc *arc1, Arc *arc2) const {
423  if (arc2->ilabel == kNoLabel) { // Epsilon in FST1.
424  return fs_ == FilterState(0)
425  ? (noeps2_
426  ? FilterState(0)
427  : (alleps2_ ? FilterState::NoState() : FilterState(1)))
428  : (fs_ == FilterState(1) ? FilterState(1)
430  } else if (arc1->olabel == kNoLabel) { // Epsilon in FST2.
431  return fs_ == FilterState(0)
432  ? (noeps1_
433  ? FilterState(0)
434  : (alleps1_ ? FilterState::NoState() : FilterState(2)))
435  : (fs_ == FilterState(2) ? FilterState(2)
437  } else if (arc1->olabel == 0) { // Epsilon in both.
438  return fs_ == FilterState(0) ? FilterState(0) : FilterState::NoState();
439  } else { // Both are non-epsilons.
440  return FilterState(0);
441  }
442  }
443 
444  void FilterFinal(Weight *, Weight *) const {}
445 
446  Matcher1 *GetMatcher1() { return matcher1_.get(); }
447 
448  Matcher2 *GetMatcher2() { return matcher2_.get(); }
449 
450  uint64_t Properties(uint64_t props) const { return props; }
451 
452  private:
453  std::unique_ptr<Matcher1> matcher1_;
454  std::unique_ptr<Matcher2> matcher2_;
455  const FST1 &fst1_;
456  const FST2 &fst2_;
457  StateId s1_; // Current fst1_ state.
458  StateId s2_; // Current fst2_ state.
459  FilterState fs_; // Current filter state ID.
460  bool alleps1_; // Only epsilson (and non-final) leaving s1?
461  bool alleps2_; // Only epsilons (and non-final) leaving s2?
462  bool noeps1_; // No epsilons leaving s1?
463  bool noeps2_; // No epsilons leaving s2?
464 };
465 
466 // This filter disallows matching epsilons on FST1 with epsilons on FST2,
467 // but allows all other matches, potentially resulting in redundant
468 // epsilon paths. The use of this filter gives correct results iff one of the
469 // following conditions hold:
470 //
471 // (1) The semiring is idempotent,
472 // (2) the first FST is output-epsilon free, or
473 // (3) the second FST is input-epsilon free.
474 //
475 // For (1), redundant epsilon paths may be created but won't hurt correctness.
476 // For (2) and (3), no redundant paths are created.
477 template <class M1, class M2 /* = M1 */>
479  public:
480  using Matcher1 = M1;
481  using Matcher2 = M2;
482  using FST1 = typename M1::FST;
483  using FST2 = typename M2::FST;
485 
486  using Arc = typename FST1::Arc;
487  using Label = typename Arc::Label;
488  using StateId = typename Arc::StateId;
489  using Weight = typename Arc::Weight;
490 
491  NoMatchComposeFilter(const FST1 &fst1, const FST2 &fst2,
492  Matcher1 *matcher1 = nullptr,
493  Matcher2 *matcher2 = nullptr)
494  : matcher1_(matcher1 ? matcher1 : new Matcher1(fst1, MATCH_OUTPUT)),
495  matcher2_(matcher2 ? matcher2 : new Matcher2(fst2, MATCH_INPUT)),
496  fst1_(matcher1_->GetFst()),
497  fst2_(matcher2_->GetFst()) {}
498 
500  bool safe = false)
501  : matcher1_(filter.matcher1_->Copy(safe)),
502  matcher2_(filter.matcher2_->Copy(safe)),
503  fst1_(matcher1_->GetFst()),
504  fst2_(matcher2_->GetFst()) {}
505 
506  FilterState Start() const { return FilterState(true); }
507 
508  void SetState(StateId, StateId, const FilterState &) {}
509 
510  FilterState FilterArc(Arc *arc1, Arc *arc2) const {
511  return FilterState(arc1->olabel != 0 || arc2->ilabel != 0);
512  }
513 
514  void FilterFinal(Weight *, Weight *) const {}
515 
516  Matcher1 *GetMatcher1() { return matcher1_.get(); }
517 
518  Matcher2 *GetMatcher2() { return matcher2_.get(); }
519 
520  uint64_t Properties(uint64_t props) const { return props; }
521 
522  private:
523  std::unique_ptr<Matcher1> matcher1_;
524  std::unique_ptr<Matcher2> matcher2_;
525  const FST1 &fst1_;
526  const FST2 &fst2_;
527 };
528 
529 // This filter works with the MultiEpsMatcher to determine if multi-epsilons are
530 // preserved in the composition output (rather than rewritten as 0) and
531 // ensures correct properties.
532 template <class Filter>
534  public:
535  using Matcher1 = typename Filter::Matcher1;
536  using Matcher2 = typename Filter::Matcher2;
537  using FST1 = typename Filter::FST1;
538  using FST2 = typename Filter::FST2;
539  using FilterState = typename Filter::FilterState;
540 
541  using Arc = typename Filter::Arc;
542  using Label = typename Arc::Label;
543  using StateId = typename Arc::StateId;
544  using Weight = typename Arc::Weight;
545 
546  MultiEpsFilter(const FST1 &fst1, const FST2 &fst2,
547  Matcher1 *matcher1 = nullptr, Matcher2 *matcher2 = nullptr,
548  bool keep_multi_eps = false)
549  : filter_(fst1, fst2, matcher1, matcher2),
550  keep_multi_eps_(keep_multi_eps) {}
551 
552  MultiEpsFilter(const MultiEpsFilter &filter, bool safe = false)
553  : filter_(filter.filter_, safe),
554  keep_multi_eps_(filter.keep_multi_eps_) {}
555 
556  FilterState Start() const { return filter_.Start(); }
557 
558  void SetState(StateId s1, StateId s2, const FilterState &fs) {
559  return filter_.SetState(s1, s2, fs);
560  }
561 
562  FilterState FilterArc(Arc *arc1, Arc *arc2) const {
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;
567  }
568  return fs;
569  }
570 
571  void FilterFinal(Weight *w1, Weight *w2) const {
572  return filter_.FilterFinal(w1, w2);
573  }
574 
575  Matcher1 *GetMatcher1() { return filter_.GetMatcher1(); }
576 
577  Matcher2 *GetMatcher2() { return filter_.GetMatcher2(); }
578 
579  uint64_t Properties(uint64_t iprops) const {
580  const auto oprops = filter_.Properties(iprops);
582  }
583 
584  private:
585  Filter filter_;
586  bool keep_multi_eps_;
587 };
588 
589 } // namespace fst
590 
591 #endif // FST_COMPOSE_FILTER_H_
typename FST1::Arc Arc
ssize_t NumOutputEpsilons(const ExpandedFst< Arc > &fst, typename Arc::StateId s)
Definition: expanded-fst.h:124
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
constexpr int kNoLabel
Definition: fst.h:195
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)
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
Matcher1 * GetMatcher1()
void FilterFinal(Weight *, Weight *) const
typename FST1::Arc Arc
Arc::Weight Final(const ExpandedFst< Arc > &fst, typename Arc::StateId s)
Definition: expanded-fst.h:107
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
typename Filter::Arc Arc
AltSequenceComposeFilter(const AltSequenceComposeFilter< Matcher1, Matcher2 > &filter, bool safe=false)
ssize_t NumArcs(const ExpandedFst< Arc > &fst, typename Arc::StateId s)
Definition: expanded-fst.h:113
TrivialFilterState FilterState
FilterState Start() const
void SetState(StateId, StateId, const FilterState &)
void FilterFinal(Weight *, Weight *) const
typename FST1::Arc Arc
constexpr int kNoStateId
Definition: fst.h:196
typename FST1::Arc Arc
TrivialComposeFilter(const FST1 &fst1, const FST2 &fst2, Matcher1 *matcher1=nullptr, Matcher2 *matcher2=nullptr)
Matcher2 * GetMatcher2()
typename Filter::FilterState FilterState
static const TrivialFilterState NoState()
Definition: filter-state.h:189
IntegerFilterState< signed char > CharFilterState
Definition: filter-state.h:87
typename Arc::Label Label
uint64_t Properties(uint64_t props) const
ssize_t NumInputEpsilons(const ExpandedFst< Arc > &fst, typename Arc::StateId s)
Definition: expanded-fst.h:118
typename M1::FST FST1
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
FilterState FilterArc(Arc *, Arc *) const
typename M1::FST FST1
constexpr uint64_t kOLabelInvariantProperties
Definition: properties.h:270
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
Definition: properties.h:261
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 M2::FST FST2
typename Arc::StateId StateId
typename M2::FST FST2
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