FST  openfst-1.7.2
OpenFst Library
lookahead-filter.h
Go to the documentation of this file.
1 // See www.openfst.org for extensive documentation on this weighted
2 // finite-state transducer library.
3 //
4 // Composition filters to support lookahead matchers, useful for improving
5 // composition efficiency with certain inputs.
6 
7 #ifndef FST_LOOKAHEAD_FILTER_H_
8 #define FST_LOOKAHEAD_FILTER_H_
9 
10 #include <vector>
11 
12 #include <fst/log.h>
13 
14 #include <fst/filter-state.h>
15 #include <fst/fst.h>
16 #include <fst/lookahead-matcher.h>
17 
18 
19 namespace fst {
20 
21 // Identifies and verifies the capabilities of the matcher to be used for
22 // lookahead with the composition filters below. This version is passed two
23 // matchers.
24 template <class Matcher1, class Matcher2>
25 MatchType LookAheadMatchType(const Matcher1 &m1, const Matcher2 &m2) {
26  const auto type1 = m1.Type(false);
27  const auto type2 = m2.Type(false);
28  if (type1 == MATCH_OUTPUT && m1.Flags() & kOutputLookAheadMatcher) {
29  return MATCH_OUTPUT;
30  } else if (type2 == MATCH_INPUT && m2.Flags() & kInputLookAheadMatcher) {
31  return MATCH_INPUT;
32  } else if (m1.Flags() & kOutputLookAheadMatcher &&
33  m1.Type(true) == MATCH_OUTPUT) {
34  return MATCH_OUTPUT;
35  } else if (m2.Flags() & kInputLookAheadMatcher &&
36  m2.Type(true) == MATCH_INPUT) {
37  return MATCH_INPUT;
38  } else {
39  return MATCH_NONE;
40  }
41 }
42 
43 // Identifies and verifies the capabilities of the matcher to be used for
44 // lookahead with the composition filters below. This version uses the FST's
45 // default matchers.
46 template <class Arc>
47 MatchType LookAheadMatchType(const Fst<Arc> &fst1, const Fst<Arc> &fst2) {
48  LookAheadMatcher<Fst<Arc>> matcher1(fst1, MATCH_OUTPUT);
49  LookAheadMatcher<Fst<Arc>> matcher2(fst2, MATCH_INPUT);
50  return LookAheadMatchType(matcher1, matcher2);
51 }
52 
53 // LookAheadSelector is a helper class for selecting among possibly distinct
54 // FST and matcher types without using a common base class. This lets us avoid
55 // virtual function calls. It stores and returns the appropriate FSTs and
56 // matcher for lookahead. It is templated on the matcher types. General case
57 // has no methods.
58 template <class Matcher1, class Matcher2, MatchType MT>
60 
61 // Stores and returns the appropriate FST and matcher for lookahead. Specialized
62 // for two matchers of same type with the (match) type argument determining
63 // which is used for lookahead.
64 template <class Matcher, MatchType MT>
66  public:
67  using FST = typename Matcher::FST;
68 
69  LookAheadSelector(Matcher *lmatcher1, Matcher *lmatcher2, MatchType type)
70  : lmatcher1_(lmatcher1->Copy()),
71  lmatcher2_(lmatcher2->Copy()),
72  type_(type) {}
73 
75  : lmatcher1_(selector.lmatcher1_->Copy()),
76  lmatcher2_(selector.lmatcher2_->Copy()),
77  type_(selector.type_) {}
78 
79  const FST &GetFst() const {
80  return type_ == MATCH_OUTPUT ? lmatcher2_->GetFst() : lmatcher1_->GetFst();
81  }
82 
83  Matcher *GetMatcher() const {
84  return type_ == MATCH_OUTPUT ? lmatcher1_.get() : lmatcher2_.get();
85  }
86 
87  private:
88  std::unique_ptr<Matcher> lmatcher1_;
89  std::unique_ptr<Matcher> lmatcher2_;
90  MatchType type_;
91 };
92 
93 // Stores and returns the appropriate FST and matcher for lookahead.
94 // Specialized for lookahead on input labels.
95 template <class Matcher1, class Matcher2>
96 class LookAheadSelector<Matcher1, Matcher2, MATCH_INPUT> {
97  public:
98  using FST1 = typename Matcher1::FST;
99 
100  LookAheadSelector(Matcher1 *lmatcher1, Matcher2 *lmatcher2, MatchType)
101  : fst_(lmatcher1->GetFst().Copy()), lmatcher_(lmatcher2->Copy()) {}
102 
105  : fst_(selector.fst_->Copy()), lmatcher_(selector.lmatcher_->Copy()) {}
106 
107  const FST1 &GetFst() const { return *fst_; }
108 
109  Matcher2 *GetMatcher() const { return lmatcher_.get(); }
110 
111  private:
112  std::unique_ptr<const FST1> fst_;
113  std::unique_ptr<Matcher2> lmatcher_;
114 };
115 
116 // Stores and returns the appropriate FST and matcher for lookahead.
117 // Specialized for lookahead on output labels.
118 template <class Matcher1, class Matcher2>
119 class LookAheadSelector<Matcher1, Matcher2, MATCH_OUTPUT> {
120  public:
121  using FST2 = typename Matcher2::FST;
122 
123  LookAheadSelector(Matcher1 *lmatcher1, Matcher2 *lmatcher2, MatchType)
124  : fst_(lmatcher2->GetFst().Copy()), lmatcher_(lmatcher1->Copy()) {}
125 
128  : fst_(selector.fst_->Copy()), lmatcher_(selector.lmatcher_->Copy()) {}
129 
130  const FST2 &GetFst() const { return *fst_; }
131 
132  Matcher1 *GetMatcher() const { return lmatcher_.get(); }
133 
134  private:
135  std::unique_ptr<const FST2> fst_;
136  std::unique_ptr<Matcher1> lmatcher_;
137 };
138 
139 // This filter uses a lookahead matcher in FilterArc(arc1, arc2) to examine the
140 // future of the composition state (arc1.nextstate, arc2.nextstate), blocking
141 // moving forward when its determined to be
142 // non-coaccessible. It is templated on an underlying filter, typically the
143 // epsilon filter. Which matcher is the lookahead matcher is determined by the
144 // template argument MT unless it is MATCH_BOTH. In that case, both matcher
145 // arguments must be lookahead matchers of the same type and one will be
146 // selected by LookAheadMatchType() based on their capability.
147 template <class Filter, class M1 = LookAheadMatcher<typename Filter::FST1>,
148  class M2 = M1, MatchType MT = MATCH_BOTH>
150  public:
151  using Arc = typename Filter::Arc;
152  using StateId = typename Arc::StateId;
153  using Weight = typename Arc::Weight;
154 
155  using FST1 = typename Filter::FST1;
156  using FST2 = typename Filter::FST2;
157  using Matcher1 = typename Filter::Matcher1;
158  using Matcher2 = typename Filter::Matcher2;
159  using FilterState = typename Filter::FilterState;
160 
161  LookAheadComposeFilter(const FST1 &fst1, const FST2 &fst2, M1 *matcher1,
162  M2 *matcher2)
163  : filter_(fst1, fst2, matcher1, matcher2),
164  lookahead_type_(MT == MATCH_BOTH
165  ? LookAheadMatchType(*filter_.GetMatcher1(),
166  *filter_.GetMatcher2())
167  : MT),
168  selector_(filter_.GetMatcher1(), filter_.GetMatcher2(),
169  lookahead_type_),
170  flags_(lookahead_type_ == MATCH_OUTPUT
171  ? filter_.GetMatcher1()->Flags()
172  : filter_.GetMatcher2()->Flags()) {
173  if (lookahead_type_ == MATCH_NONE) {
174  FSTERROR() << "LookAheadComposeFilter: 1st argument cannot "
175  << "match/look-ahead on output labels and 2nd argument "
176  << "cannot match/look-ahead on input labels";
177  }
178  selector_.GetMatcher()->InitLookAheadFst(selector_.GetFst());
179  }
180 
183  bool safe = false)
184  : filter_(filter.filter_, safe),
185  lookahead_type_(filter.lookahead_type_),
186  selector_(filter_.GetMatcher1(), filter_.GetMatcher2(),
187  lookahead_type_),
188  flags_(filter.flags_) {
189  selector_.GetMatcher()->InitLookAheadFst(selector_.GetFst(), true);
190  }
191 
192  FilterState Start() const { return filter_.Start(); }
193 
194  void SetState(StateId s1, StateId s2, const FilterState &fs) {
195  filter_.SetState(s1, s2, fs);
196  }
197 
198  FilterState FilterArc(Arc *arc1, Arc *arc2) const {
199  lookahead_arc_ = false;
200  const FilterState &fs = filter_.FilterArc(arc1, arc2);
201  if (fs == FilterState::NoState()) return FilterState::NoState();
202  return LookAheadOutput() ? LookAheadFilterArc(arc1, arc2, fs)
203  : LookAheadFilterArc(arc2, arc1, fs);
204  }
205 
206  void FilterFinal(Weight *weight1, Weight *weight2) const {
207  filter_.FilterFinal(weight1, weight2);
208  }
209 
210  // Returns matchers; ownership stays with filter.
211 
212  Matcher1 *GetMatcher1() { return filter_.GetMatcher1(); }
213 
214  Matcher2 *GetMatcher2() { return filter_.GetMatcher2(); }
215 
217  return selector_;
218  }
219 
220  uint64 Properties(uint64 inprops) const {
221  auto outprops = filter_.Properties(inprops);
222  if (lookahead_type_ == MATCH_NONE) outprops |= kError;
223  return outprops;
224  }
225 
226  uint32 LookAheadFlags() const { return flags_; }
227 
228  bool LookAheadArc() const { return lookahead_arc_; }
229 
230  bool LookAheadOutput() const {
231  if (MT == MATCH_OUTPUT) {
232  return true;
233  } else if (MT == MATCH_INPUT) {
234  return false;
235  } else if (lookahead_type_ == MATCH_OUTPUT) {
236  return true;
237  } else {
238  return false;
239  }
240  }
241 
242  private:
243  FilterState LookAheadFilterArc(Arc *arca, Arc *arcb,
244  const FilterState &fs) const {
245  auto &labela = LookAheadOutput() ? arca->olabel : arca->ilabel;
246  if (labela != 0 && !(flags_ & kLookAheadNonEpsilons)) return fs;
247  if (labela == 0 && !(flags_ & kLookAheadEpsilons)) return fs;
248  lookahead_arc_ = true;
249  selector_.GetMatcher()->SetState(arca->nextstate);
250  return selector_.GetMatcher()->LookAheadFst(selector_.GetFst(),
251  arcb->nextstate)
252  ? fs
253  : FilterState::NoState();
254  }
255 
256  Filter filter_; // Underlying filter.
257  MatchType lookahead_type_; // Lookahead match type.
259  uint32 flags_; // Lookahead flags.
260  mutable bool lookahead_arc_; // Look-ahead performed at last FilterArc()?
261 
262  LookAheadComposeFilter &operator=(const LookAheadComposeFilter &) = delete;
263 };
264 
265 // This filter adds weight-pushing to a lookahead composition filter using the
266 // LookAheadWeight() method of matcher argument. It is templated on an
267 // underlying lookahead filter, typically the basic lookahead filter.
268 // Weight-pushing in composition brings weights forward as much as possible
269 // based on the lookahead information.
270 template <class Filter, class M1 = LookAheadMatcher<typename Filter::FST1>,
271  class M2 = M1, MatchType MT = MATCH_BOTH>
273  public:
274  using Arc = typename Filter::Arc;
275  using StateId = typename Filter::StateId;
276  using Weight = typename Filter::Weight;
277 
278  using FST1 = typename Filter::FST1;
279  using FST2 = typename Filter::FST2;
280  using Matcher1 = typename Filter::Matcher1;
281  using Matcher2 = typename Filter::Matcher2;
282 
283  using FilterState1 = typename Filter::FilterState;
286 
287  PushWeightsComposeFilter(const FST1 &fst1, const FST2 &fst2, M1 *matcher1,
288  M2 *matcher2)
289  : filter_(fst1, fst2, matcher1, matcher2), fs_(FilterState::NoState()) {}
290 
293  bool safe = false)
294  : filter_(filter.filter_, safe), fs_(FilterState::NoState()) {}
295 
296  FilterState Start() const {
297  return FilterState(filter_.Start(), FilterState2(Weight::One()));
298  }
299 
300  void SetState(StateId s1, StateId s2, const FilterState &fs) {
301  fs_ = fs;
302  filter_.SetState(s1, s2, fs.GetState1());
303  }
304 
305  FilterState FilterArc(Arc *arc1, Arc *arc2) const {
306  const auto &fs1 = filter_.FilterArc(arc1, arc2);
307  if (fs1 == FilterState1::NoState()) return FilterState::NoState();
308  if (!(LookAheadFlags() & kLookAheadWeight)) {
309  return FilterState(fs1, FilterState2(Weight::One()));
310  }
311  const auto &lweight = filter_.LookAheadArc()
312  ? Selector().GetMatcher()->LookAheadWeight()
313  : Weight::One();
314  const auto &fs2 = fs_.GetState2();
315  const auto &fweight = fs2.GetWeight();
316  // Disallows Zero() weight futures.
317  if (lweight == Weight::Zero()) return FilterState::NoState();
318  arc2->weight = Divide(Times(arc2->weight, lweight), fweight);
319  return FilterState(fs1, FilterState2(lweight.Quantize()));
320  }
321 
322  void FilterFinal(Weight *weight1, Weight *weight2) const {
323  filter_.FilterFinal(weight1, weight2);
324  if (!(LookAheadFlags() & kLookAheadWeight) || *weight1 == Weight::Zero()) {
325  return;
326  }
327  const auto &fs2 = fs_.GetState2();
328  const auto &fweight = fs2.GetWeight();
329  *weight1 = Divide(*weight1, fweight);
330  }
331 
332  // Returns matchers; ownership states with filter.
333 
334  Matcher1 *GetMatcher1() { return filter_.GetMatcher1(); }
335 
336  Matcher2 *GetMatcher2() { return filter_.GetMatcher2(); }
337 
339  return filter_.Selector();
340  }
341 
342  uint32 LookAheadFlags() const { return filter_.LookAheadFlags(); }
343 
344  bool LookAheadArc() const { return filter_.LookAheadArc(); }
345 
346  bool LookAheadOutput() const { return filter_.LookAheadOutput(); }
347 
348  uint64 Properties(uint64 props) const {
349  return filter_.Properties(props) & kWeightInvariantProperties;
350  }
351 
352  private:
353  Filter filter_; // Underlying filter.
354  FilterState fs_; // Current filter state.
355 
357  delete;
358 };
359 
360 // This filter adds label-pushing to a lookahead composition filter using the
361 // LookAheadPrefix() method of the matcher argument. It is templated on an
362 // underlying filter, typically the basic lookahead or weight-pushing lookahead
363 // filter. Label-pushing in composition matches labels as early as possible
364 // based on the lookahead information.
365 template <class Filter, class M1 = LookAheadMatcher<typename Filter::FST1>,
366  class M2 = M1, MatchType MT = MATCH_BOTH>
368  public:
369  using Arc = typename Filter::Arc;
370  using Label = typename Arc::Label;
371  using StateId = typename Arc::StateId;
372  using Weight = typename Arc::Weight;
373 
374  using FST1 = typename Filter::FST1;
375  using FST2 = typename Filter::FST2;
378  using FilterState1 = typename Filter::FilterState;
381 
382  PushLabelsComposeFilter(const FST1 &fst1, const FST2 &fst2, M1 *matcher1,
383  M2 *matcher2)
384  : filter_(fst1, fst2, matcher1, matcher2),
385  fs_(FilterState::NoState()),
386  fst1_(filter_.GetMatcher1()->GetFst()),
387  fst2_(filter_.GetMatcher2()->GetFst()),
388  matcher1_(fst1_, MATCH_OUTPUT,
389  filter_.LookAheadOutput() ? kMultiEpsList : kMultiEpsLoop,
390  filter_.GetMatcher1(), false),
391  matcher2_(fst2_, MATCH_INPUT,
392  filter_.LookAheadOutput() ? kMultiEpsLoop : kMultiEpsList,
393  filter_.GetMatcher2(), false) {}
394 
397  bool safe = false)
398  : filter_(filter.filter_, safe),
399  fs_(FilterState::NoState()),
400  fst1_(filter_.GetMatcher1()->GetFst()),
401  fst2_(filter_.GetMatcher2()->GetFst()),
402  matcher1_(fst1_, MATCH_OUTPUT,
403  filter_.LookAheadOutput() ? kMultiEpsList : kMultiEpsLoop,
404  filter_.GetMatcher1(), false),
405  matcher2_(fst2_, MATCH_INPUT,
406  filter_.LookAheadOutput() ? kMultiEpsLoop : kMultiEpsList,
407  filter_.GetMatcher2(), false) {}
408 
409  FilterState Start() const {
410  return FilterState(filter_.Start(), FilterState2(kNoLabel));
411  }
412 
413  void SetState(StateId s1, StateId s2, const FilterState &fs) {
414  fs_ = fs;
415  filter_.SetState(s1, s2, fs.GetState1());
416  if (!(LookAheadFlags() & kLookAheadPrefix)) return;
417  narcsa_ = LookAheadOutput() ? internal::NumArcs(fst1_, s1)
418  : internal::NumArcs(fst2_, s2);
419  const auto &fs2 = fs_.GetState2();
420  const auto &flabel = fs2.GetState();
421  GetMatcher1()->ClearMultiEpsLabels();
422  GetMatcher2()->ClearMultiEpsLabels();
423  if (flabel != kNoLabel) { // Have a lookahead label?
424  GetMatcher1()->AddMultiEpsLabel(flabel); // Yes, make it a multi-epsilon
425  GetMatcher2()->AddMultiEpsLabel(flabel); // label so that it matches the
426  } // implicit epsilon arc to be
427  } // modified below when pushing.
428 
429  FilterState FilterArc(Arc *arc1, Arc *arc2) const {
430  if (!(LookAheadFlags() & kLookAheadPrefix)) {
431  return FilterState(filter_.FilterArc(arc1, arc2), FilterState2(kNoLabel));
432  }
433  const auto &fs2 = fs_.GetState2();
434  const auto &flabel = fs2.GetState();
435  if (flabel != kNoLabel) { // Have a lookahead label?
436  return LookAheadOutput() ? PushedLabelFilterArc(arc1, arc2, flabel)
437  : PushedLabelFilterArc(arc2, arc1, flabel);
438  }
439  const auto &fs1 = filter_.FilterArc(arc1, arc2);
440  if (fs1 == FilterState1::NoState()) return FilterState::NoState();
441  if (!filter_.LookAheadArc())
442  return FilterState(fs1, FilterState2(kNoLabel));
443  return LookAheadOutput() ? PushLabelFilterArc(arc1, arc2, fs1)
444  : PushLabelFilterArc(arc2, arc1, fs1);
445  }
446 
447  void FilterFinal(Weight *weight1, Weight *weight2) const {
448  filter_.FilterFinal(weight1, weight2);
449  if (!(LookAheadFlags() & kLookAheadPrefix) || *weight1 == Weight::Zero()) {
450  return;
451  }
452  const auto &fs2 = fs_.GetState2();
453  const auto &flabel = fs2.GetState();
454  if (flabel != kNoLabel) *weight1 = Weight::Zero();
455  }
456 
457  // Returns matchers; ownership states with filter.
458 
459  Matcher1 *GetMatcher1() { return &matcher1_; }
460 
461  Matcher2 *GetMatcher2() { return &matcher2_; }
462 
463  uint64 Properties(uint64 iprops) const {
464  const auto oprops = filter_.Properties(iprops);
465  if (LookAheadOutput()) {
466  return oprops & kOLabelInvariantProperties;
467  } else {
468  return oprops & kILabelInvariantProperties;
469  }
470  }
471 
472  private:
473  const LookAheadSelector<typename Filter::Matcher1, typename Filter::Matcher2,
474  MT>
475  &Selector() const {
476  return filter_.Selector();
477  }
478 
479  // Consumes an already pushed label.
480  FilterState PushedLabelFilterArc(Arc *arca, Arc *arcb, Label flabel) const {
481  auto &labela = LookAheadOutput() ? arca->olabel : arca->ilabel;
482  const auto &labelb = LookAheadOutput() ? arcb->ilabel : arcb->olabel;
483  if (labelb != kNoLabel) {
484  return FilterState::NoState(); // Blocks non-(multi-)epsilon label
485  } else if (labela == flabel) {
486  labela = 0; // Converts match to multi-epsilon to epsilon.
487  return Start();
488  } else if (labela == 0) {
489  if (narcsa_ == 1) return fs_; // Takes epsilon, keeping state with label.
490  Selector().GetMatcher()->SetState(arca->nextstate);
491  if (Selector().GetMatcher()->LookAheadLabel(flabel)) {
492  return fs_; // Takes epsilon, keeping state with label.
493  } else {
494  return FilterState::NoState(); // Blocks non-coaccessible path.
495  }
496  } else {
497  return FilterState::NoState(); // Blocks mismatch to multi-epsilon label.
498  }
499  }
500 
501  // Pushes a label forward when possible.
502  FilterState PushLabelFilterArc(Arc *arca, Arc *arcb,
503  const FilterState1 &fs1) const {
504  auto &labela = LookAheadOutput() ? arca->olabel : arca->ilabel;
505  const auto &labelb = LookAheadOutput() ? arcb->olabel : arcb->ilabel;
506  if (labelb != 0) { // No place to push.
507  return FilterState(fs1, FilterState2(kNoLabel));
508  }
509  if (labela != 0 && // Wrong lookahead prefix type?
510  LookAheadFlags() & kLookAheadNonEpsilonPrefix) {
511  return FilterState(fs1, FilterState2(kNoLabel));
512  }
513  Arc larc(kNoLabel, kNoLabel, Weight::Zero(), kNoStateId);
514  if (Selector().GetMatcher()->LookAheadPrefix(&larc)) { // Have prefix arc?
515  labela = LookAheadOutput() ? larc.ilabel : larc.olabel;
516  arcb->ilabel = larc.ilabel; // Goes forward on that arc,
517  arcb->olabel = larc.olabel; // thus pushing the label.
518  arcb->weight = Times(arcb->weight, larc.weight);
519  arcb->nextstate = larc.nextstate;
520  return FilterState(fs1, FilterState2(labela));
521  } else {
522  return FilterState(fs1, FilterState2(kNoLabel));
523  }
524  }
525 
526  uint32 LookAheadFlags() const { return filter_.LookAheadFlags(); }
527 
528  bool LookAheadArc() const { return filter_.LookAheadArc(); }
529 
530  bool LookAheadOutput() const { return filter_.LookAheadOutput(); }
531 
532  Filter filter_; // Underlying filter.
533  FilterState fs_; // Current filter state.
534  const FST1 &fst1_;
535  const FST2 &fst2_;
536  Matcher1 matcher1_; // Multi-epsilon matcher for fst1_.
537  Matcher2 matcher2_; // Multi-epsilon matcher for fst2_.
538  ssize_t narcsa_; // Number of arcs leaving look-ahead match FST.
539 
540  PushLabelsComposeFilter &operator=(const PushLabelsComposeFilter &) = delete;
541 };
542 
543 // Convenience class for setting up composition with a default lookahead matcher
544 // and filter.
545 template <class Arc, MatchType type>
547  public:
548  using M = Matcher<Fst<Arc>>;
550  using FstMatcher = M;
551 };
552 
553 // Specializes for MATCH_INPUT to allow lookahead.
554 template <class Arc>
556  public:
560  using FstMatcher = M;
561 };
562 
563 // Specializes for MATCH_OUTPUT to allow lookahead.
564 template <class Arc>
566  public:
570  using FstMatcher = M;
571 };
572 
573 // Specializes for StdArc to allow weight and label pushing.
574 template <>
576  public:
582  using FstMatcher = M;
583 };
584 
585 // Specializes for StdArc to allow weight and label pushing.
586 template <>
588  public:
594  using FstMatcher = M;
595 };
596 
597 // Specializes for LogArc to allow weight and label pushing.
598 template <>
600  public:
606  using FstMatcher = M;
607 };
608 
609 // Specializes for LogArc to allow weight and label pushing.
610 template <>
612  public:
618  using FstMatcher = M;
619 };
620 
621 } // namespace fst
622 
623 #endif // FST_LOOKAHEAD_FILTER_H_
PushWeightsComposeFilter(const FST1 &fst1, const FST2 &fst2, M1 *matcher1, M2 *matcher2)
constexpr uint32 kLookAheadEpsilons
constexpr uint32 kLookAheadNonEpsilonPrefix
typename Arc::Weight Weight
typename Filter::StateId StateId
const uint32 kMultiEpsLoop
Definition: matcher.h:1227
void FilterFinal(Weight *weight1, Weight *weight2) const
ExpectationWeight< X1, X2 > Divide(const ExpectationWeight< X1, X2 > &w1, const ExpectationWeight< X1, X2 > &w2, DivideType typ=DIVIDE_ANY)
LookAheadComposeFilter(const FST1 &fst1, const FST2 &fst2, M1 *matcher1, M2 *matcher2)
constexpr int kNoLabel
Definition: fst.h:179
typename Filter::FST1 FST1
uint64_t uint64
Definition: types.h:32
void FilterFinal(Weight *weight1, Weight *weight2) const
FilterState Start() const
const LookAheadSelector< Matcher1, Matcher2, MT > & Selector() const
typename Filter::FilterState FilterState
typename Filter::FST2 FST2
LookAheadSelector(Matcher1 *lmatcher1, Matcher2 *lmatcher2, MatchType)
MatchType LookAheadMatchType(const Matcher1 &m1, const Matcher2 &m2)
LookAheadSelector(Matcher1 *lmatcher1, Matcher2 *lmatcher2, MatchType)
uint64 Properties(uint64 iprops) const
MatchType
Definition: fst.h:171
LookAheadSelector(const LookAheadSelector< Matcher1, Matcher2, MATCH_OUTPUT > &selector)
typename Filter::Arc Arc
ExpectationWeight< X1, X2 > Times(const ExpectationWeight< X1, X2 > &w1, const ExpectationWeight< X1, X2 > &w2)
FilterState FilterArc(Arc *arc1, Arc *arc2) const
typename Arc::StateId StateId
const LookAheadSelector< Matcher1, Matcher2, MT > & Selector() const
ssize_t NumArcs(const ExpandedFst< Arc > &fst, typename Arc::StateId s)
Definition: expanded-fst.h:88
FilterState FilterArc(Arc *arc1, Arc *arc2) const
const uint32 kMultiEpsList
Definition: matcher.h:1224
uint64 Properties(uint64 props) const
constexpr uint32 kLookAheadWeight
constexpr int kNoStateId
Definition: fst.h:180
void FilterFinal(Weight *weight1, Weight *weight2) const
#define FSTERROR()
Definition: util.h:35
const FS2 & GetState2() const
Definition: filter-state.h:164
FilterState Start() const
LookAheadSelector(Matcher *lmatcher1, Matcher *lmatcher2, MatchType type)
void SetState(StateId s1, StateId s2, const FilterState &fs)
constexpr uint32 kLookAheadNonEpsilons
typename Filter::Matcher1 Matcher1
void SetState(StateId s1, StateId s2, const FilterState &fs)
constexpr uint32 kInputLookAheadMatcher
typename Filter::Weight Weight
constexpr uint32 kOutputLookAheadMatcher
void SetState(const FS1 &fs1, const FS2 &fs2)
Definition: filter-state.h:166
typename Filter::FST1 FST1
PushLabelsComposeFilter(const PushLabelsComposeFilter< Filter, M1, M2, MT > &filter, bool safe=false)
typename Filter::FilterState FilterState1
LookAheadComposeFilter(const LookAheadComposeFilter< Filter, M1, M2, MT > &filter, bool safe=false)
constexpr uint64 kOLabelInvariantProperties
Definition: properties.h:245
typename Filter::Matcher2 Matcher2
uint32_t uint32
Definition: types.h:31
constexpr uint64 kWeightInvariantProperties
Definition: properties.h:255
typename Filter::FST2 FST2
typename Filter::FST2 FST2
typename Arc::Weight Weight
typename Filter::Matcher1 Matcher1
constexpr uint64 kError
Definition: properties.h:33
PushLabelsComposeFilter(const FST1 &fst1, const FST2 &fst2, M1 *matcher1, M2 *matcher2)
void SetState(StateId s1, StateId s2, const FilterState &fs)
PushWeightsComposeFilter(const PushWeightsComposeFilter< Filter, M1, M2, MT > &filter, bool safe=false)
typename Filter::FST1 FST1
constexpr uint32 kLookAheadPrefix
typename Filter::FilterState FilterState1
LookAheadSelector(const LookAheadSelector< Matcher1, Matcher2, MATCH_INPUT > &selector)
typename Filter::Matcher2 Matcher2
uint64 Properties(uint64 inprops) const
constexpr uint64 kILabelInvariantProperties
Definition: properties.h:236
const FS1 & GetState1() const
Definition: filter-state.h:162
LookAheadSelector(const LookAheadSelector< Matcher, Matcher, MT > &selector)
FilterState FilterArc(Arc *arc1, Arc *arc2) const
typename Arc::StateId StateId