FST  openfst-1.7.2
OpenFst Library
state-map.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 // Class to map over/transform states e.g., sort transitions.
5 //
6 // Consider using when operation does not change the number of states.
7 
8 #ifndef FST_STATE_MAP_H_
9 #define FST_STATE_MAP_H_
10 
11 #include <algorithm>
12 #include <string>
13 #include <utility>
14 
15 #include <fst/log.h>
16 
17 #include <fst/arc-map.h>
18 #include <fst/cache.h>
19 #include <fst/mutable-fst.h>
20 
21 
22 namespace fst {
23 
24 // StateMapper Interface. The class determines how states are mapped; useful for
25 // implementing operations that do not change the number of states.
26 //
27 // class StateMapper {
28 // public:
29 // using FromArc = A;
30 // using ToArc = B;
31 //
32 // // Typical constructor.
33 // StateMapper(const Fst<A> &fst);
34 //
35 // // Required copy constructor that allows updating FST argument;
36 // // pass only if relevant and changed.
37 // StateMapper(const StateMapper &mapper, const Fst<A> *fst = 0);
38 //
39 // // Specifies initial state of result.
40 // B::StateId Start() const;
41 // // Specifies state's final weight in result.
42 // B::Weight Final(B::StateId state) const;
43 //
44 // // These methods iterate through a state's arcs in result.
45 //
46 // // Specifies state to iterate over.
47 // void SetState(B::StateId state);
48 //
49 // // End of arcs?
50 // bool Done() const;
51 //
52 // // Current arc.
53 // const B &Value() const;
54 //
55 // // Advances to next arc (when !Done)
56 // void Next();
57 //
58 // // Specifies input symbol table action the mapper requires (see above).
59 // MapSymbolsAction InputSymbolsAction() const;
60 //
61 // // Specifies output symbol table action the mapper requires (see above).
62 // MapSymbolsAction OutputSymbolsAction() const;
63 //
64 // // This specifies the known properties of an FST mapped by this
65 // // mapper. It takes as argument the input FST's known properties.
66 // uint64 Properties(uint64 props) const;
67 // };
68 //
69 // We include a various state map versions below. One dimension of variation is
70 // whether the mapping mutates its input, writes to a new result FST, or is an
71 // on-the-fly Fst. Another dimension is how we pass the mapper. We allow passing
72 // the mapper by pointer for cases that we need to change the state of the
73 // user's mapper. We also include map versions that pass the mapper by value or
74 // const reference when this suffices.
75 
76 // Maps an arc type A using a mapper function object C, passed by pointer. This
77 // version modifies the input FST.
78 template <class A, class C>
79 void StateMap(MutableFst<A> *fst, C *mapper) {
80  if (mapper->InputSymbolsAction() == MAP_CLEAR_SYMBOLS) {
81  fst->SetInputSymbols(nullptr);
82  }
83  if (mapper->OutputSymbolsAction() == MAP_CLEAR_SYMBOLS) {
84  fst->SetOutputSymbols(nullptr);
85  }
86  if (fst->Start() == kNoStateId) return;
87  const auto props = fst->Properties(kFstProperties, false);
88  fst->SetStart(mapper->Start());
89  for (StateIterator<Fst<A>> siter(*fst); !siter.Done(); siter.Next()) {
90  const auto state = siter.Value();
91  mapper->SetState(state);
92  fst->DeleteArcs(state);
93  for (; !mapper->Done(); mapper->Next()) {
94  fst->AddArc(state, mapper->Value());
95  }
96  fst->SetFinal(state, mapper->Final(state));
97  }
98  fst->SetProperties(mapper->Properties(props), kFstProperties);
99 }
100 
101 // Maps an arc type A using a mapper function object C, passed by value.
102 // This version modifies the input FST.
103 template <class A, class C>
104 void StateMap(MutableFst<A> *fst, C mapper) {
105  StateMap(fst, &mapper);
106 }
107 
108 // Maps an arc type A to an arc type B using mapper functor C, passed by
109 // pointer. This version writes to an output FST.
110 template <class A, class B, class C>
111 void StateMap(const Fst<A> &ifst, MutableFst<B> *ofst, C *mapper) {
112  ofst->DeleteStates();
113  if (mapper->InputSymbolsAction() == MAP_COPY_SYMBOLS) {
114  ofst->SetInputSymbols(ifst.InputSymbols());
115  } else if (mapper->InputSymbolsAction() == MAP_CLEAR_SYMBOLS) {
116  ofst->SetInputSymbols(nullptr);
117  }
118  if (mapper->OutputSymbolsAction() == MAP_COPY_SYMBOLS) {
119  ofst->SetOutputSymbols(ifst.OutputSymbols());
120  } else if (mapper->OutputSymbolsAction() == MAP_CLEAR_SYMBOLS) {
121  ofst->SetOutputSymbols(nullptr);
122  }
123  const auto iprops = ifst.Properties(kCopyProperties, false);
124  if (ifst.Start() == kNoStateId) {
125  if (iprops & kError) ofst->SetProperties(kError, kError);
126  return;
127  }
128  // Adds all states.
129  if (ifst.Properties(kExpanded, false)) ofst->ReserveStates(CountStates(ifst));
130  for (StateIterator<Fst<A>> siter(ifst); !siter.Done(); siter.Next()) {
131  ofst->AddState();
132  }
133  ofst->SetStart(mapper->Start());
134  for (StateIterator<Fst<A>> siter(ifst); !siter.Done(); siter.Next()) {
135  const auto state = siter.Value();
136  mapper->SetState(state);
137  for (; !mapper->Done(); mapper->Next()) {
138  ofst->AddArc(state, mapper->Value());
139  }
140  ofst->SetFinal(state, mapper->Final(state));
141  }
142  const auto oprops = ofst->Properties(kFstProperties, false);
143  ofst->SetProperties(mapper->Properties(iprops) | oprops, kFstProperties);
144 }
145 
146 // Maps an arc type A to an arc type B using mapper functor object C, passed by
147 // value. This version writes to an output FST.
148 template <class A, class B, class C>
149 void StateMap(const Fst<A> &ifst, MutableFst<B> *ofst, C mapper) {
150  StateMap(ifst, ofst, &mapper);
151 }
152 
154 
155 template <class A, class B, class C>
157 
158 // Facade around StateIteratorBase<A> inheriting from StateIteratorBase<B>.
159 template <class A, class B>
161  public:
162  using Arc = B;
163  using StateId = typename Arc::StateId;
164 
166  : base_(base) {}
167 
168  bool Done() const final { return base_->Done(); }
169 
170  StateId Value() const final { return base_->Value(); }
171 
172  void Next() final { base_->Next(); }
173 
174  void Reset() final { base_->Reset(); }
175 
176  private:
177  std::unique_ptr<StateIteratorBase<A>> base_;
178 
179  StateMapStateIteratorBase() = delete;
180 };
181 
182 namespace internal {
183 
184 // Implementation of delayed StateMapFst.
185 template <class A, class B, class C>
186 class StateMapFstImpl : public CacheImpl<B> {
187  public:
188  using Arc = B;
189  using StateId = typename Arc::StateId;
190  using Weight = typename Arc::Weight;
191 
192  using FstImpl<B>::SetType;
196 
197  using CacheImpl<B>::PushArc;
198  using CacheImpl<B>::HasArcs;
201  using CacheImpl<B>::SetArcs;
204 
205  friend class StateIterator<StateMapFst<A, B, C>>;
206 
207  StateMapFstImpl(const Fst<A> &fst, const C &mapper,
208  const StateMapFstOptions &opts)
209  : CacheImpl<B>(opts),
210  fst_(fst.Copy()),
211  mapper_(new C(mapper, fst_.get())),
212  own_mapper_(true) {
213  Init();
214  }
215 
216  StateMapFstImpl(const Fst<A> &fst, C *mapper, const StateMapFstOptions &opts)
217  : CacheImpl<B>(opts),
218  fst_(fst.Copy()),
219  mapper_(mapper),
220  own_mapper_(false) {
221  Init();
222  }
223 
225  : CacheImpl<B>(impl),
226  fst_(impl.fst_->Copy(true)),
227  mapper_(new C(*impl.mapper_, fst_.get())),
228  own_mapper_(true) {
229  Init();
230  }
231 
232  ~StateMapFstImpl() override {
233  if (own_mapper_) delete mapper_;
234  }
235 
237  if (!HasStart()) SetStart(mapper_->Start());
238  return CacheImpl<B>::Start();
239  }
240 
242  if (!HasFinal(state)) SetFinal(state, mapper_->Final(state));
243  return CacheImpl<B>::Final(state);
244  }
245 
246  size_t NumArcs(StateId state) {
247  if (!HasArcs(state)) Expand(state);
248  return CacheImpl<B>::NumArcs(state);
249  }
250 
251  size_t NumInputEpsilons(StateId state) {
252  if (!HasArcs(state)) Expand(state);
253  return CacheImpl<B>::NumInputEpsilons(state);
254  }
255 
256  size_t NumOutputEpsilons(StateId state) {
257  if (!HasArcs(state)) Expand(state);
258  return CacheImpl<B>::NumOutputEpsilons(state);
259  }
260 
263  fst_->InitStateIterator(&data);
264  datb->base = data.base ? new StateMapStateIteratorBase<A, B>(data.base)
265  : nullptr;
266  datb->nstates = data.nstates;
267  }
268 
270  if (!HasArcs(state)) Expand(state);
271  CacheImpl<B>::InitArcIterator(state, data);
272  }
273 
274  uint64 Properties() const override { return Properties(kFstProperties); }
275 
276  uint64 Properties(uint64 mask) const override {
277  if ((mask & kError) && (fst_->Properties(kError, false) ||
278  (mapper_->Properties(0) & kError))) {
279  SetProperties(kError, kError);
280  }
281  return FstImpl<Arc>::Properties(mask);
282  }
283 
284  void Expand(StateId state) {
285  // Adds exiting arcs.
286  for (mapper_->SetState(state); !mapper_->Done(); mapper_->Next()) {
287  PushArc(state, mapper_->Value());
288  }
289  SetArcs(state);
290  }
291 
292  const Fst<A> *GetFst() const { return fst_.get(); }
293 
294  private:
295  void Init() {
296  SetType("statemap");
297  if (mapper_->InputSymbolsAction() == MAP_COPY_SYMBOLS) {
298  SetInputSymbols(fst_->InputSymbols());
299  } else if (mapper_->InputSymbolsAction() == MAP_CLEAR_SYMBOLS) {
300  SetInputSymbols(nullptr);
301  }
302  if (mapper_->OutputSymbolsAction() == MAP_COPY_SYMBOLS) {
303  SetOutputSymbols(fst_->OutputSymbols());
304  } else if (mapper_->OutputSymbolsAction() == MAP_CLEAR_SYMBOLS) {
305  SetOutputSymbols(nullptr);
306  }
307  const auto props = fst_->Properties(kCopyProperties, false);
308  SetProperties(mapper_->Properties(props));
309  }
310 
311  std::unique_ptr<const Fst<A>> fst_;
312  C *mapper_;
313  bool own_mapper_;
314 };
315 
316 } // namespace internal
317 
318 // Maps an arc type A to an arc type B using Mapper function object
319 // C. This version is a delayed FST.
320 template <class A, class B, class C>
321 class StateMapFst : public ImplToFst<internal::StateMapFstImpl<A, B, C>> {
322  public:
323  friend class ArcIterator<StateMapFst<A, B, C>>;
324 
325  using Arc = B;
326  using StateId = typename Arc::StateId;
327  using Weight = typename Arc::Weight;
329  using State = typename Store::State;
331 
332  StateMapFst(const Fst<A> &fst, const C &mapper,
333  const StateMapFstOptions &opts)
334  : ImplToFst<Impl>(std::make_shared<Impl>(fst, mapper, opts)) {}
335 
336  StateMapFst(const Fst<A> &fst, C *mapper, const StateMapFstOptions &opts)
337  : ImplToFst<Impl>(std::make_shared<Impl>(fst, mapper, opts)) {}
338 
339  StateMapFst(const Fst<A> &fst, const C &mapper)
340  : ImplToFst<Impl>(
341  std::make_shared<Impl>(fst, mapper, StateMapFstOptions())) {}
342 
343  StateMapFst(const Fst<A> &fst, C *mapper)
344  : ImplToFst<Impl>(
345  std::make_shared<Impl>(fst, mapper, StateMapFstOptions())) {}
346 
347  // See Fst<>::Copy() for doc.
348  StateMapFst(const StateMapFst<A, B, C> &fst, bool safe = false)
349  : ImplToFst<Impl>(fst, safe) {}
350 
351  // Get a copy of this StateMapFst. See Fst<>::Copy() for further doc.
352  StateMapFst<A, B, C> *Copy(bool safe = false) const override {
353  return new StateMapFst<A, B, C>(*this, safe);
354  }
355 
356  void InitStateIterator(StateIteratorData<B> *data) const override {
357  GetImpl()->InitStateIterator(data);
358  }
359 
360  void InitArcIterator(StateId state, ArcIteratorData<B> *data) const override {
361  GetMutableImpl()->InitArcIterator(state, data);
362  }
363 
364  protected:
367 
368  private:
369  StateMapFst &operator=(const StateMapFst &) = delete;
370 };
371 
372 // Specialization for StateMapFst.
373 template <class A, class B, class C>
374 class ArcIterator<StateMapFst<A, B, C>>
375  : public CacheArcIterator<StateMapFst<A, B, C>> {
376  public:
377  using StateId = typename A::StateId;
378 
380  : CacheArcIterator<StateMapFst<A, B, C>>(fst.GetMutableImpl(), state) {
381  if (!fst.GetImpl()->HasArcs(state)) fst.GetMutableImpl()->Expand(state);
382  }
383 };
384 
385 // Utility mappers.
386 
387 // Mapper that returns its input.
388 template <class Arc>
390  public:
391  using FromArc = Arc;
392  using ToArc = Arc;
393 
394  using StateId = typename Arc::StateId;
395  using Weight = typename Arc::Weight;
396 
397  explicit IdentityStateMapper(const Fst<Arc> &fst) : fst_(fst) {}
398 
399  // Allows updating FST argument; pass only if changed.
401  const Fst<Arc> *fst = nullptr)
402  : fst_(fst ? *fst : mapper.fst_) {}
403 
404  StateId Start() const { return fst_.Start(); }
405 
406  Weight Final(StateId state) const { return fst_.Final(state); }
407 
408  void SetState(StateId state) {
409  aiter_.reset(new ArcIterator<Fst<Arc>>(fst_, state));
410  }
411 
412  bool Done() const { return aiter_->Done(); }
413 
414  const Arc &Value() const { return aiter_->Value(); }
415 
416  void Next() { aiter_->Next(); }
417 
419  return MAP_COPY_SYMBOLS;
420  }
421 
423  return MAP_COPY_SYMBOLS;
424  }
425 
426  uint64 Properties(uint64 props) const { return props; }
427 
428  private:
429  const Fst<Arc> &fst_;
430  std::unique_ptr<ArcIterator<Fst<Arc>>> aiter_;
431 };
432 
433 template <class Arc>
435  public:
436  using FromArc = Arc;
437  using ToArc = Arc;
438 
439  using StateId = typename Arc::StateId;
440  using Weight = typename Arc::Weight;
441 
442  explicit ArcSumMapper(const Fst<Arc> &fst) : fst_(fst), i_(0) {}
443 
444  // Allows updating FST argument; pass only if changed.
445  ArcSumMapper(const ArcSumMapper<Arc> &mapper, const Fst<Arc> *fst = nullptr)
446  : fst_(fst ? *fst : mapper.fst_), i_(0) {}
447 
448  StateId Start() const { return fst_.Start(); }
449 
450  Weight Final(StateId state) const { return fst_.Final(state); }
451 
452  void SetState(StateId state) {
453  i_ = 0;
454  arcs_.clear();
455  arcs_.reserve(fst_.NumArcs(state));
456  for (ArcIterator<Fst<Arc>> aiter(fst_, state); !aiter.Done();
457  aiter.Next()) {
458  arcs_.push_back(aiter.Value());
459  }
460  // First sorts the exiting arcs by input label, output label and destination
461  // state and then sums weights of arcs with the same input label, output
462  // label, and destination state.
463  std::sort(arcs_.begin(), arcs_.end(), comp_);
464  size_t narcs = 0;
465  for (const auto &arc : arcs_) {
466  if (narcs > 0 && equal_(arc, arcs_[narcs - 1])) {
467  arcs_[narcs - 1].weight = Plus(arcs_[narcs - 1].weight, arc.weight);
468  } else {
469  arcs_[narcs] = arc;
470  ++narcs;
471  }
472  }
473  arcs_.resize(narcs);
474  }
475 
476  bool Done() const { return i_ >= arcs_.size(); }
477 
478  const Arc &Value() const { return arcs_[i_]; }
479 
480  void Next() { ++i_; }
481 
483  return MAP_COPY_SYMBOLS;
484  }
485 
487  return MAP_COPY_SYMBOLS;
488  }
489 
490  uint64 Properties(uint64 props) const {
491  return props & kArcSortProperties & kDeleteArcsProperties &
493  }
494 
495  private:
496  struct Compare {
497  bool operator()(const Arc &x, const Arc &y) const {
498  if (x.ilabel < y.ilabel) return true;
499  if (x.ilabel > y.ilabel) return false;
500  if (x.olabel < y.olabel) return true;
501  if (x.olabel > y.olabel) return false;
502  if (x.nextstate < y.nextstate) return true;
503  if (x.nextstate > y.nextstate) return false;
504  return false;
505  }
506  };
507 
508  struct Equal {
509  bool operator()(const Arc &x, const Arc &y) const {
510  return (x.ilabel == y.ilabel && x.olabel == y.olabel &&
511  x.nextstate == y.nextstate);
512  }
513  };
514 
515  const Fst<Arc> &fst_;
516  Compare comp_;
517  Equal equal_;
518  std::vector<Arc> arcs_;
519  ssize_t i_; // Current arc position.
520 
521  ArcSumMapper &operator=(const ArcSumMapper &) = delete;
522 };
523 
524 template <class Arc>
526  public:
527  using FromArc = Arc;
528  using ToArc = Arc;
529 
530  using StateId = typename Arc::StateId;
531  using Weight = typename Arc::Weight;
532 
533  explicit ArcUniqueMapper(const Fst<Arc> &fst) : fst_(fst), i_(0) {}
534 
535  // Allows updating FST argument; pass only if changed.
537  const Fst<Arc> *fst = nullptr)
538  : fst_(fst ? *fst : mapper.fst_), i_(0) {}
539 
540  StateId Start() const { return fst_.Start(); }
541 
542  Weight Final(StateId state) const { return fst_.Final(state); }
543 
544  void SetState(StateId state) {
545  i_ = 0;
546  arcs_.clear();
547  arcs_.reserve(fst_.NumArcs(state));
548  for (ArcIterator<Fst<Arc>> aiter(fst_, state); !aiter.Done();
549  aiter.Next()) {
550  arcs_.push_back(aiter.Value());
551  }
552  // First sorts the exiting arcs by input label, output label and destination
553  // state and then uniques identical arcs.
554  std::sort(arcs_.begin(), arcs_.end(), comp_);
555  arcs_.erase(std::unique(arcs_.begin(), arcs_.end(), equal_), arcs_.end());
556  }
557 
558  bool Done() const { return i_ >= arcs_.size(); }
559 
560  const Arc &Value() const { return arcs_[i_]; }
561 
562  void Next() { ++i_; }
563 
565  return MAP_COPY_SYMBOLS;
566  }
567 
569  return MAP_COPY_SYMBOLS;
570  }
571 
572  uint64 Properties(uint64 props) const {
573  return props & kArcSortProperties & kDeleteArcsProperties;
574  }
575 
576  private:
577  struct Compare {
578  bool operator()(const Arc &x, const Arc &y) const {
579  if (x.ilabel < y.ilabel) return true;
580  if (x.ilabel > y.ilabel) return false;
581  if (x.olabel < y.olabel) return true;
582  if (x.olabel > y.olabel) return false;
583  if (x.nextstate < y.nextstate) return true;
584  if (x.nextstate > y.nextstate) return false;
585  return false;
586  }
587  };
588 
589  struct Equal {
590  bool operator()(const Arc &x, const Arc &y) const {
591  return (x.ilabel == y.ilabel && x.olabel == y.olabel &&
592  x.nextstate == y.nextstate && x.weight == y.weight);
593  }
594  };
595 
596  const Fst<Arc> &fst_;
597  Compare comp_;
598  Equal equal_;
599  std::vector<Arc> arcs_;
600  size_t i_; // Current arc position.
601 
602  ArcUniqueMapper &operator=(const ArcUniqueMapper &) = delete;
603 };
604 
605 // Useful aliases when using StdArc.
606 
608 
610 
611 } // namespace fst
612 
613 #endif // FST_STATE_MAP_H_
constexpr MapSymbolsAction InputSymbolsAction() const
Definition: state-map.h:564
MapSymbolsAction
Definition: arc-map.h:39
ssize_t NumOutputEpsilons(const ExpandedFst< Arc > &fst, typename Arc::StateId s)
Definition: expanded-fst.h:99
constexpr MapSymbolsAction OutputSymbolsAction() const
Definition: state-map.h:422
typename Arc::StateId StateId
Definition: state-map.h:530
constexpr MapSymbolsAction OutputSymbolsAction() const
Definition: state-map.h:486
void InitArcIterator(StateId state, ArcIteratorData< B > *data) const override
Definition: state-map.h:360
typename Arc::StateId StateId
Definition: state-map.h:394
typename Arc::Weight Weight
Definition: state-map.h:190
uint64_t uint64
Definition: types.h:32
ArcSumMapper(const Fst< Arc > &fst)
Definition: state-map.h:442
bool Done() const
Definition: state-map.h:412
void InitArcIterator(StateId state, ArcIteratorData< B > *data)
Definition: state-map.h:269
constexpr MapSymbolsAction InputSymbolsAction() const
Definition: state-map.h:418
ArcIterator(const StateMapFst< A, B, C > &fst, StateId state)
Definition: state-map.h:379
ArcUniqueMapper(const ArcUniqueMapper< Arc > &mapper, const Fst< Arc > *fst=nullptr)
Definition: state-map.h:536
typename Arc::Weight Weight
Definition: state-map.h:395
const Arc & Value() const
Definition: state-map.h:560
Arc::Weight Final(const ExpandedFst< Arc > &fst, typename Arc::StateId s)
Definition: expanded-fst.h:82
virtual void AddArc(StateId, const Arc &arc)=0
IdentityStateMapper(const Fst< Arc > &fst)
Definition: state-map.h:397
uint64 Properties(uint64 props) const
Definition: state-map.h:490
virtual void SetInputSymbols(const SymbolTable *isyms)=0
StateId Start() const
Definition: state-map.h:540
SetType
Definition: set-weight.h:37
virtual void SetStart(StateId)=0
void SetState(StateId state)
Definition: state-map.h:452
ssize_t NumArcs(const ExpandedFst< Arc > &fst, typename Arc::StateId s)
Definition: expanded-fst.h:88
typename Arc::StateId StateId
Definition: state-map.h:189
constexpr uint64 kFstProperties
Definition: properties.h:301
StateMapFst(const Fst< A > &fst, C *mapper)
Definition: state-map.h:343
typename Arc::StateId StateId
Definition: state-map.h:163
constexpr uint64 kCopyProperties
Definition: properties.h:138
constexpr int kNoStateId
Definition: fst.h:180
void SetState(StateId state)
Definition: state-map.h:544
constexpr uint64 kExpanded
Definition: properties.h:27
StateId Start() const
Definition: state-map.h:448
virtual uint64 Properties(uint64 mask, bool test) const =0
StateMapFst(const Fst< A > &fst, C *mapper, const StateMapFstOptions &opts)
Definition: state-map.h:336
IdentityStateMapper(const IdentityStateMapper< Arc > &mapper, const Fst< Arc > *fst=nullptr)
Definition: state-map.h:400
ArcSumMapper(const ArcSumMapper< Arc > &mapper, const Fst< Arc > *fst=nullptr)
Definition: state-map.h:445
StateMapFst< A, B, C > * Copy(bool safe=false) const override
Definition: state-map.h:352
Weight Final(StateId state)
Definition: state-map.h:241
StateIteratorBase< Arc > * base
Definition: fst.h:351
virtual void SetFinal(StateId, Weight)=0
ssize_t NumInputEpsilons(const ExpandedFst< Arc > &fst, typename Arc::StateId s)
Definition: expanded-fst.h:93
constexpr uint64 kArcSortProperties
Definition: properties.h:226
ArcUniqueMapper(const Fst< Arc > &fst)
Definition: state-map.h:533
bool Done() const
Definition: state-map.h:558
typename FirstCacheStore< VectorCacheStore< CacheState< Arc > > >::State State
Definition: cache.h:648
uint64 Properties(uint64 props) const
Definition: state-map.h:572
StateId nstates
Definition: fst.h:353
constexpr uint64 kDeleteArcsProperties
Definition: properties.h:209
typename Arc::Weight Weight
Definition: state-map.h:440
size_t NumOutputEpsilons(StateId state)
Definition: state-map.h:256
ExpectationWeight< X1, X2 > Plus(const ExpectationWeight< X1, X2 > &w1, const ExpectationWeight< X1, X2 > &w2)
virtual StateId Start() const =0
StateMapFstImpl(const StateMapFstImpl< A, B, C > &impl)
Definition: state-map.h:224
StateMapFst(const Fst< A > &fst, const C &mapper)
Definition: state-map.h:339
virtual void DeleteArcs(StateId, size_t n)=0
size_t NumArcs(StateId state)
Definition: state-map.h:246
const Arc & Value() const
Definition: state-map.h:478
constexpr MapSymbolsAction InputSymbolsAction() const
Definition: state-map.h:482
const Fst< A > * GetFst() const
Definition: state-map.h:292
void StateMap(MutableFst< A > *fst, C *mapper)
Definition: state-map.h:79
StateId Value() const final
Definition: state-map.h:170
StateId Start() const
Definition: state-map.h:404
typename Arc::StateId StateId
Definition: state-map.h:439
void Expand(StateId state)
Definition: state-map.h:284
virtual void ReserveStates(StateId n)
Definition: mutable-fst.h:76
Weight Final(StateId state) const
Definition: state-map.h:406
bool Done() const final
Definition: state-map.h:168
bool Done() const
Definition: state-map.h:476
constexpr uint64 kWeightInvariantProperties
Definition: properties.h:255
typename internal::StateMapFstImpl< Arc, Arc, ArcSortMapper< Arc, Compare > >::Arc Arc
Definition: fst.h:188
StateMapFstImpl(const Fst< A > &fst, const C &mapper, const StateMapFstOptions &opts)
Definition: state-map.h:207
StateMapFst(const StateMapFst< A, B, C > &fst, bool safe=false)
Definition: state-map.h:348
virtual const SymbolTable * InputSymbols() const =0
Arc::StateId CountStates(const Fst< Arc > &fst)
Definition: expanded-fst.h:154
size_t NumInputEpsilons(StateId state)
Definition: state-map.h:251
const Arc & Value() const
Definition: state-map.h:414
constexpr uint64 kError
Definition: properties.h:33
virtual StateId AddState()=0
void InitStateIterator(StateIteratorData< B > *data) const override
Definition: state-map.h:356
Weight Final(StateId state) const
Definition: state-map.h:450
bool Equal(const Fst< Arc > &fst1, const Fst< Arc > &fst2, WeightEqual weight_equal, uint32 etype=kEqualFsts)
Definition: equal.h:43
uint64 Properties(uint64 mask) const override
Definition: state-map.h:276
virtual void DeleteStates(const std::vector< StateId > &)=0
typename Arc::Weight Weight
Definition: state-map.h:531
uint64 Properties() const override
Definition: state-map.h:274
void InitStateIterator(StateIteratorData< B > *datb) const
Definition: state-map.h:261
virtual void SetOutputSymbols(const SymbolTable *osyms)=0
void Expand(const Fst< Arc > &ifst, const std::vector< std::pair< typename Arc::Label, typename Arc::Label >> &parens, const std::vector< typename Arc::Label > &assignments, MutableFst< Arc > *ofst, const MPdtExpandOptions &opts)
Definition: expand.h:302
internal::StateMapFstImpl< A, B, C > * GetMutableImpl() const
Definition: fst.h:947
StateMapFstImpl(const Fst< A > &fst, C *mapper, const StateMapFstOptions &opts)
Definition: state-map.h:216
constexpr MapSymbolsAction OutputSymbolsAction() const
Definition: state-map.h:568
uint64 Properties(uint64 props) const
Definition: state-map.h:426
StateMapStateIteratorBase(StateIteratorBase< A > *base)
Definition: state-map.h:165
StateMapFst(const Fst< A > &fst, const C &mapper, const StateMapFstOptions &opts)
Definition: state-map.h:332
Weight Final(StateId state) const
Definition: state-map.h:542
const internal::StateMapFstImpl< A, B, C > * GetImpl() const
Definition: fst.h:945
virtual void SetProperties(uint64 props, uint64 mask)=0
void SetState(StateId state)
Definition: state-map.h:408
virtual const SymbolTable * OutputSymbols() const =0