1 // map.h
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 // Copyright 2005-2010 Google, Inc.
16 // Author: riley@google.com (Michael Riley)
17 //
18 // \file
19 // Compatability file for old-style Map() functions and MapFst class
20 // that have been renamed to ArcMap (cf. StateMap).
21
22 #ifndef FST_LIB_MAP_H__
23 #define FST_LIB_MAP_H__
24
25
26 #include <fst/arc-map.h>
27
28
29 namespace fst {
30
31 template<class A, class C>
Map(MutableFst<A> * fst,C * mapper)32 void Map(MutableFst<A> *fst, C* mapper) {
33 ArcMap(fst, mapper);
34 }
35
36 template<class A, class C>
Map(MutableFst<A> * fst,C mapper)37 void Map(MutableFst<A> *fst, C mapper) {
38 ArcMap(fst, mapper);
39 }
40
41 template<class A, class B, class C>
Map(const Fst<A> & ifst,MutableFst<B> * ofst,C * mapper)42 void Map(const Fst<A> &ifst, MutableFst<B> *ofst, C* mapper) {
43 ArcMap(ifst, ofst, mapper);
44 }
45
46 template<class A, class B, class C>
Map(const Fst<A> & ifst,MutableFst<B> * ofst,C mapper)47 void Map(const Fst<A> &ifst, MutableFst<B> *ofst, C mapper) {
48 ArcMap(ifst, ofst, mapper);
49 }
50
51 typedef ArcMapFstOptions MapFstOptions;
52
53 template <class A, class B, class C>
54 class MapFst : public ArcMapFst<A, B, C> {
55 public:
56 typedef B Arc;
57 typedef typename B::Weight Weight;
58 typedef typename B::StateId StateId;
59 typedef CacheState<B> State;
60
MapFst(const Fst<A> & fst,const C & mapper,const MapFstOptions & opts)61 MapFst(const Fst<A> &fst, const C &mapper, const MapFstOptions& opts)
62 : ArcMapFst<A, B, C>(fst, mapper, opts) {}
63
MapFst(const Fst<A> & fst,C * mapper,const MapFstOptions & opts)64 MapFst(const Fst<A> &fst, C* mapper, const MapFstOptions& opts)
65 : ArcMapFst<A, B, C>(fst, mapper, opts) {}
66
MapFst(const Fst<A> & fst,const C & mapper)67 MapFst(const Fst<A> &fst, const C &mapper)
68 : ArcMapFst<A, B, C>(fst, mapper) {}
69
MapFst(const Fst<A> & fst,C * mapper)70 MapFst(const Fst<A> &fst, C* mapper) : ArcMapFst<A, B, C>(fst, mapper) {}
71
72 // See Fst<>::Copy() for doc.
73 MapFst(const ArcMapFst<A, B, C> &fst, bool safe = false)
74 : ArcMapFst<A, B, C>(fst, safe) {}
75
76 // Get a copy of this MapFst. See Fst<>::Copy() for further doc.
77 virtual MapFst<A, B, C> *Copy(bool safe = false) const {
78 return new MapFst(*this, safe);
79 }
80 };
81
82
83 // Specialization for MapFst.
84 template <class A, class B, class C>
85 class StateIterator< MapFst<A, B, C> >
86 : public StateIterator< ArcMapFst<A, B, C> > {
87 public:
StateIterator(const ArcMapFst<A,B,C> & fst)88 explicit StateIterator(const ArcMapFst<A, B, C> &fst)
89 : StateIterator< ArcMapFst<A, B, C> >(fst) {}
90 };
91
92
93 // Specialization for MapFst.
94 template <class A, class B, class C>
95 class ArcIterator< MapFst<A, B, C> >
96 : public ArcIterator< ArcMapFst<A, B, C> > {
97 public:
ArcIterator(const ArcMapFst<A,B,C> & fst,typename A::StateId s)98 ArcIterator(const ArcMapFst<A, B, C> &fst, typename A::StateId s)
99 : ArcIterator< ArcMapFst<A, B, C> >(fst, s) {}
100 };
101
102
103 template <class A>
104 struct IdentityMapper {
105 typedef A FromArc;
106 typedef A ToArc;
107
operatorIdentityMapper108 A operator()(const A &arc) const { return arc; }
109
FinalActionIdentityMapper110 MapFinalAction FinalAction() const { return MAP_NO_SUPERFINAL; }
111
InputSymbolsActionIdentityMapper112 MapSymbolsAction InputSymbolsAction() const { return MAP_COPY_SYMBOLS; }
113
OutputSymbolsActionIdentityMapper114 MapSymbolsAction OutputSymbolsAction() const { return MAP_COPY_SYMBOLS;}
115
PropertiesIdentityMapper116 uint64 Properties(uint64 props) const { return props; }
117 };
118
119 } // namespace fst
120
121 #endif // FST_LIB_MAP_H__
122