pre-determinize.h
Go to the documentation of this file.
1 // fstext/pre-determinize.h
2 
3 // Copyright 2009-2011 Microsoft Corporation
4 
5 // See ../../COPYING for clarification regarding multiple authors
6 //
7 // Licensed under the Apache License, Version 2.0 (the "License");
8 // you may not use this file except in compliance with the License.
9 // You may obtain a copy of the License at
10 //
11 // http://www.apache.org/licenses/LICENSE-2.0
12 //
13 // THIS CODE IS PROVIDED *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14 // KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY IMPLIED
15 // WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE,
16 // MERCHANTABLITY OR NON-INFRINGEMENT.
17 // See the Apache 2 License for the specific language governing permissions and
18 // limitations under the License.
19 
20 #ifndef KALDI_FSTEXT_PRE_DETERMINIZE_H_
21 #define KALDI_FSTEXT_PRE_DETERMINIZE_H_
22 #include <algorithm>
23 #include <map>
24 #include <set>
25 #include <vector>
26 #include <fst/fstlib.h>
27 #include <fst/fst-decl.h>
28 #include "base/kaldi-common.h"
29 
30 namespace fst {
31 
32 /* PreDeterminize inserts extra symbols on the input side of an FST as necessary to
33  ensure that, after epsilon removal, it will be compactly determinizable by the
34  determinize* algorithm. By compactly determinizable we mean that
35  no original FST state is represented in more than one determinized state).
36 
37  Caution: this code is now only used in testing.
38 
39  The new symbols start from the value "first_new_symbol", which should be
40  higher than the largest-numbered symbol currently in the FST. The new
41  symbols added are put in the array syms_out, which should be empty at start.
42 */
43 
44 template<class Arc, class Int>
45 void PreDeterminize(MutableFst<Arc> *fst,
46  typename Arc::Label first_new_symbol,
47  std::vector<Int> *syms_out);
48 
49 
50 /* CreateNewSymbols is a helper function used inside PreDeterminize, and is also useful
51  when you need to add a number of extra symbols to a different vocabulary from the one
52  modified by PreDeterminize. */
53 
54 template<class Label>
55 void CreateNewSymbols(SymbolTable *inputSymTable, int nSym,
56  std::string prefix, std::vector<Label> *syms_out);
57 
74 template<class Arc>
75 void AddSelfLoops(MutableFst<Arc> *fst, std::vector<typename Arc::Label> &isyms,
76  std::vector<typename Arc::Label> &osyms);
77 
78 
79 /* DeleteSymbols replaces any instances of symbols in the vector symsIn, appearing
80  on the input side, with epsilon. */
81 /* It returns the number of instances of symbols deleted. */
82 template<class Arc>
83 int64 DeleteISymbols(MutableFst<Arc> *fst, std::vector<typename Arc::Label> symsIn);
84 
85 /* CreateSuperFinal takes an FST, and creates an equivalent FST with a single final
86  state with no transitions out and unit final weight, by inserting epsilon transitions
87  as necessary. */
88 template<class Arc>
89 typename Arc::StateId CreateSuperFinal(MutableFst<Arc> *fst);
90 
91 
92 } // end namespace fst
93 
95 
96 #endif
fst::StdArc::StateId StateId
void PreDeterminize(MutableFst< Arc > *fst, typename Arc::Label first_new_sym, std::vector< Int > *symsOut)
For an extended explanation of the framework of which grammar-fsts are a part, please see Support for...
Definition: graph.dox:21
void CreateNewSymbols(SymbolTable *input_sym_table, int nSym, std::string prefix, std::vector< Label > *symsOut)
void AddSelfLoops(MutableFst< Arc > *fst, std::vector< typename Arc::Label > &isyms, std::vector< typename Arc::Label > &osyms)
AddSelfLoops is a function you will probably want to use alongside PreDeterminize, to add self-loops to any FSTs that you compose on the left hand side of the one modified by PreDeterminize.
Arc::StateId CreateSuperFinal(MutableFst< Arc > *fst)
fst::StdArc::Label Label
int64 DeleteISymbols(MutableFst< Arc > *fst, std::vector< typename Arc::Label > isyms)