FST  openfst-1.7.2
OpenFst Library
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 // Compatibility file for old-style Map() functions and MapFst class that have
5 // been renamed to ArcMap (cf. StateMap).
6 
7 #ifndef FST_MAP_H_
8 #define FST_MAP_H_
9 
10 
11 #include <fst/arc-map.h>
12 
13 
14 namespace fst {
15 
16 template <class A, class C>
17 void Map(MutableFst<A> *fst, C *mapper) {
18  ArcMap(fst, mapper);
19 }
20 
21 template <class A, class C>
22 void Map(MutableFst<A> *fst, C mapper) {
23  ArcMap(fst, mapper);
24 }
25 
26 template <class A, class B, class C>
27 void Map(const Fst<A> &ifst, MutableFst<B> *ofst, C *mapper) {
28  ArcMap(ifst, ofst, mapper);
29 }
30 
31 template <class A, class B, class C>
32 void Map(const Fst<A> &ifst, MutableFst<B> *ofst, C mapper) {
33  ArcMap(ifst, ofst, mapper);
34 }
35 
37 
38 template <class A, class B, class C>
39 class MapFst : public ArcMapFst<A, B, C> {
40  public:
41  using FromArc = A;
42  using ToArc = B;
43 
44  using StateId = typename ToArc::StateId;
45  using Weight = typename ToArc::Weight;
46 
48 
49  MapFst(const Fst<A> &fst, const C &mapper, const MapFstOptions &opts)
50  : ArcMapFst<A, B, C>(fst, mapper, opts) {}
51 
52  MapFst(const Fst<A> &fst, C *mapper, const MapFstOptions &opts)
53  : ArcMapFst<A, B, C>(fst, mapper, opts) {}
54 
55  MapFst(const Fst<A> &fst, const C &mapper)
56  : ArcMapFst<A, B, C>(fst, mapper) {}
57 
58  MapFst(const Fst<A> &fst, C *mapper) : ArcMapFst<A, B, C>(fst, mapper) {}
59 
60  // See Fst<>::Copy() for doc.
61  MapFst(const MapFst<A, B, C> &fst, bool safe = false)
62  : ArcMapFst<A, B, C>(fst, safe) {}
63 
64  // Get a copy of this MapFst. See Fst<>::Copy() for further doc.
65  MapFst<A, B, C> *Copy(bool safe = false) const override {
66  return new MapFst(*this, safe);
67  }
68 };
69 
70 // Specialization for MapFst.
71 template <class A, class B, class C>
72 class StateIterator<MapFst<A, B, C>>
73  : public StateIterator<ArcMapFst<A, B, C>> {
74  public:
76  : StateIterator<ArcMapFst<A, B, C>>(fst) {}
77 };
78 
79 // Specialization for MapFst.
80 template <class A, class B, class C>
81 class ArcIterator<MapFst<A, B, C>> : public ArcIterator<ArcMapFst<A, B, C>> {
82  public:
83  ArcIterator(const ArcMapFst<A, B, C> &fst, typename A::StateId s)
84  : ArcIterator<ArcMapFst<A, B, C>>(fst, s) {}
85 };
86 
87 // For backwards compatibility only; use IdentityArcMapper otherwise.
88 template <class A>
90  using FromArc = A;
91  using ToArc = A;
92 
93  ToArc operator()(const FromArc &arc) const { return arc; }
94 
95  constexpr MapFinalAction FinalAction() const { return MAP_NO_SUPERFINAL; }
96 
98  return MAP_COPY_SYMBOLS;
99  }
100 
102  return MAP_COPY_SYMBOLS;
103  }
104 
105  uint64 Properties(uint64 props) const { return props; }
106 };
107 
108 } // namespace fst
109 
110 #endif // FST_MAP_H_
MapFst(const MapFst< A, B, C > &fst, bool safe=false)
Definition: map.h:61
MapSymbolsAction
Definition: arc-map.h:39
void ArcMap(MutableFst< A > *fst, C *mapper)
Definition: arc-map.h:94
MapFst(const Fst< A > &fst, C *mapper)
Definition: map.h:58
ToArc operator()(const FromArc &arc) const
Definition: map.h:93
typename Store::State State
Definition: arc-map.h:522
uint64_t uint64
Definition: types.h:32
MapFst(const Fst< A > &fst, const C &mapper)
Definition: map.h:55
constexpr MapSymbolsAction OutputSymbolsAction() const
Definition: map.h:101
MapFst(const Fst< A > &fst, C *mapper, const MapFstOptions &opts)
Definition: map.h:52
MapFst(const Fst< A > &fst, const C &mapper, const MapFstOptions &opts)
Definition: map.h:49
typename Arc::Weight Weight
Definition: arc-map.h:519
typename Arc::StateId StateId
Definition: arc-map.h:518
void Map(MutableFst< A > *fst, C *mapper)
Definition: map.h:17
MapFinalAction
Definition: arc-map.h:24
uint64 Properties(uint64 props) const
Definition: map.h:105
A FromArc
Definition: map.h:41
B ToArc
Definition: map.h:42
ArcIterator(const ArcMapFst< A, B, C > &fst, typename A::StateId s)
Definition: map.h:83
constexpr MapFinalAction FinalAction() const
Definition: map.h:95
StateIterator(const ArcMapFst< A, B, C > &fst)
Definition: map.h:75
constexpr MapSymbolsAction InputSymbolsAction() const
Definition: map.h:97
MapFst< A, B, C > * Copy(bool safe=false) const override
Definition: map.h:65