map.h revision f4c12fce1ee58e670f9c3fce46c40296ba9ee8a2
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 29namespace fst { 30 31template<class A, class C> 32void Map(MutableFst<A> *fst, C* mapper) { 33 ArcMap(fst, mapper); 34} 35 36template<class A, class C> 37void Map(MutableFst<A> *fst, C mapper) { 38 ArcMap(fst, mapper); 39} 40 41template<class A, class B, class C> 42void Map(const Fst<A> &ifst, MutableFst<B> *ofst, C* mapper) { 43 ArcMap(ifst, ofst, mapper); 44} 45 46template<class A, class B, class C> 47void Map(const Fst<A> &ifst, MutableFst<B> *ofst, C mapper) { 48 ArcMap(ifst, ofst, mapper); 49} 50 51typedef ArcMapFstOptions MapFstOptions; 52 53template <class A, class B, class C> 54class 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 61 MapFst(const Fst<A> &fst, const C &mapper, const MapFstOptions& opts) 62 : ArcMapFst<A, B, C>(fst, mapper, opts) {} 63 64 MapFst(const Fst<A> &fst, C* mapper, const MapFstOptions& opts) 65 : ArcMapFst<A, B, C>(fst, mapper, opts) {} 66 67 MapFst(const Fst<A> &fst, const C &mapper) 68 : ArcMapFst<A, B, C>(fst, mapper) {} 69 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. 77virtual MapFst<A, B, C> *Copy(bool safe = false) const { 78 return new MapFst(*this, safe); 79 } 80}; 81 82 83// Specialization for MapFst. 84template <class A, class B, class C> 85class StateIterator< MapFst<A, B, C> > 86 : public StateIterator< ArcMapFst<A, B, C> > { 87 public: 88 explicit StateIterator(const ArcMapFst<A, B, C> &fst) 89 : StateIterator< ArcMapFst<A, B, C> >(fst) {} 90}; 91 92 93// Specialization for MapFst. 94template <class A, class B, class C> 95class ArcIterator< MapFst<A, B, C> > 96 : public ArcIterator< ArcMapFst<A, B, C> > { 97 public: 98 ArcIterator(const ArcMapFst<A, B, C> &fst, typename A::StateId s) 99 : ArcIterator< ArcMapFst<A, B, C> >(fst, s) {} 100}; 101 102 103template <class A> 104struct IdentityMapper { 105 typedef A FromArc; 106 typedef A ToArc; 107 108 A operator()(const A &arc) const { return arc; } 109 110 MapFinalAction FinalAction() const { return MAP_NO_SUPERFINAL; } 111 112 MapSymbolsAction InputSymbolsAction() const { return MAP_COPY_SYMBOLS; } 113 114 MapSymbolsAction OutputSymbolsAction() const { return MAP_COPY_SYMBOLS;} 115 116 uint64 Properties(uint64 props) const { return props; } 117}; 118 119} // namespace fst 120 121#endif // FST_LIB_MAP_H__ 122