FST  openfst-1.7.2
OpenFst Library
epsnormalize.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 // Function that implements epsilon-normalization.
5 
6 #ifndef FST_EPSNORMALIZE_H_
7 #define FST_EPSNORMALIZE_H_
8 
9 
10 #include <fst/arc-map.h>
11 #include <fst/factor-weight.h>
12 #include <fst/invert.h>
13 #include <fst/rmepsilon.h>
14 
15 
16 namespace fst {
17 
19 
20 // Returns an equivalent FST that is epsilon-normalized. An acceptor is
21 // epsilon-normalized if it is epsilon-removed. A transducer is input
22 // epsilon-normalized if additionally if on each path any epsilon input
23 // label follows all non-epsilon input labels. Output epsilon-normalized
24 // is defined similarly.
25 //
26 // For more information, see:
27 //
28 // Mohri, M. 2002. Generic epsilon-removal and input epsilon-normalization
29 // algorithms for weighted transducers. International Journal of Computer
30 // Science, 13(1): 129-143, 2002.
31 template <class Arc>
32 void EpsNormalize(const Fst<Arc> &ifst, MutableFst<Arc> *ofst,
34  EpsNormalize<Arc, GALLIC>(ifst, ofst, type);
35 }
36 
37 // Same as above, except allows specifying explicitly the gallic weight type.
38 template <class Arc, GallicType G>
39 void EpsNormalize(const Fst<Arc> &ifst, MutableFst<Arc> *ofst,
40  EpsNormalizeType type) {
42  std::unique_ptr<SymbolTable> symbols;
43  if (type == EPS_NORM_INPUT) {
44  ArcMap(ifst, &gfst, ToGallicMapper<Arc, G>());
45  if (ifst.OutputSymbols()) symbols.reset(ifst.OutputSymbols()->Copy());
46  } else { // type == EPS_NORM_OUTPUT
48  if (ifst.InputSymbols()) symbols.reset(ifst.InputSymbols()->Copy());
49  }
50  RmEpsilon(&gfst);
53  fwfst(gfst);
54  ArcMap(fwfst, ofst, FromGallicMapper<Arc, G>());
55  ofst->SetOutputSymbols(symbols.get());
56  if (type == EPS_NORM_OUTPUT) Invert(ofst);
57 }
58 
59 } // namespace fst
60 
61 #endif // FST_EPSNORMALIZE_H_
void ArcMap(MutableFst< A > *fst, C *mapper)
Definition: arc-map.h:94
void RmEpsilon(MutableFst< Arc > *fst, std::vector< typename Arc::Weight > *distance, const RmEpsilonOptions< Arc, Queue > &opts)
Definition: rmepsilon.h:192
void Invert(const Fst< Arc > &ifst, MutableFst< Arc > *ofst)
Definition: invert.h:54
virtual SymbolTable * Copy() const
Definition: symbol-table.h:266
EpsNormalizeType
Definition: epsnormalize.h:18
void EpsNormalize(const Fst< Arc > &ifst, MutableFst< Arc > *ofst, EpsNormalizeType type=EPS_NORM_INPUT)
Definition: epsnormalize.h:32
virtual const SymbolTable * InputSymbols() const =0
virtual void SetOutputSymbols(const SymbolTable *osyms)=0
virtual const SymbolTable * OutputSymbols() const =0