28 Label nonterm_phones_offset,
29 const vector<int32>& phones,
30 const vector<int32>& disambig_syms):
31 nonterm_phones_offset_(nonterm_phones_offset),
33 disambig_syms_(disambig_syms) {
36 std::vector<int32> all_inputs(phones);
37 all_inputs.insert(all_inputs.end(), disambig_syms.begin(),
39 all_inputs.push_back(nonterm_phones_offset);
40 size_t size = all_inputs.size();
42 if (all_inputs.size() != size) {
43 KALDI_ERR <<
"There was overlap between disambig symbols, phones, " 44 "and/or --nonterm-phones-offset";
46 if (all_inputs.front() <= 0)
47 KALDI_ERR <<
"Symbols <= 0 were passed in as phones, disambig-syms, " 48 "or nonterm-phones-offset.";
49 if (all_inputs.back() != nonterm_phones_offset) {
53 int32 symbol = nonterm_phones_offset +
i;
60 if (std::binary_search(all_inputs.begin(), all_inputs.end(), symbol)) {
62 <<
" = --nonterm-phones-offset + " << i
63 <<
" was listed as a phone or disambig symbol.";
68 KALDI_WARN <<
"Context FST created but there are no phone symbols: probably " 69 "input FST was empty.";
74 vector<int32> empty_vec;
86 return Weight::Zero();
95 arc->weight = Weight::One();
101 std::vector<int32> context_window(2);
102 context_window[0] = s;
103 context_window[1] = ilabel;
105 arc->nextstate = ilabel;
113 std::vector<int32> this_ilabel_info(1);
114 this_ilabel_info[0] = -ilabel;
115 arc->olabel =
FindLabel(this_ilabel_info);
129 std::vector<int32> this_ilabel_info(2);
132 arc->olabel =
FindLabel(this_ilabel_info);
139 std::vector<int32> this_ilabel_info(2);
140 this_ilabel_info[0] = -ilabel;
142 arc->olabel =
FindLabel(this_ilabel_info);
152 std::vector<int32> this_ilabel_info(2);
154 this_ilabel_info[1] = ilabel;
156 arc->olabel =
FindLabel(this_ilabel_info);
165 std::vector<int32> this_ilabel_info(2);
167 this_ilabel_info[1] = ilabel;
169 arc->olabel =
FindLabel(this_ilabel_info);
176 KALDI_ERR <<
"Invalid state encountered";
184 VectorToLabelMap::const_iterator iter =
ilabel_map_.find(label_vec);
197 int32 nonterm_phones_offset,
198 const vector<int32> &disambig_syms_in,
199 const VectorFst<StdArc> &ifst,
200 VectorFst<StdArc> *ofst,
201 std::vector<std::vector<int32> > *ilabels) {
203 vector<int32> disambig_syms(disambig_syms_in);
204 std::sort(disambig_syms.begin(), disambig_syms.end());
206 vector<int32> all_syms;
208 std::sort(all_syms.begin(), all_syms.end());
209 vector<int32> phones;
210 for (
size_t i = 0;
i < all_syms.size();
i++)
211 if (!std::binary_search(disambig_syms.begin(),
212 disambig_syms.end(), all_syms[
i]) &&
213 all_syms[
i] < nonterm_phones_offset)
214 phones.push_back(all_syms[
i]);
218 phones, disambig_syms);
void SwapIlabelInfo(std::vector< std::vector< int32 > > *vec)
For an extended explanation of the framework of which grammar-fsts are a part, please see Support for...
void SortAndUniq(std::vector< T > *vec)
Sorts and uniq's (removes duplicates) from a vector.
void GetInputSymbols(const Fst< Arc > &fst, bool include_eps, std::vector< I > *symbols)
GetInputSymbols gets the list of symbols on the input of fst (including epsilon, if include_eps == tr...
InverseLeftBiphoneContextFst(Label nonterm_phones_offset, const std::vector< int32 > &phones, const std::vector< int32 > &disambig_syms)
Constructor.
virtual bool GetArc(StateId s, Label ilabel, Arc *arc)
Note: ilabel must not be epsilon.
void ComposeDeterministicOnDemandInverse(const Fst< Arc > &right, DeterministicOnDemandFst< Arc > *left, MutableFst< Arc > *fst_composed)
This function does '*fst_composed = Compose(Inverse(*fst2), fst1)' Note that the arguments are revers...
std::vector< std::vector< int32 > > ilabel_info_
VectorToLabelMap ilabel_map_
virtual Weight Final(StateId s)
void ComposeContextLeftBiphone(int32 nonterm_phones_offset, const vector< int32 > &disambig_syms_in, const VectorFst< StdArc > &ifst, VectorFst< StdArc > *ofst, std::vector< std::vector< int32 > > *ilabels)
This is a variant of the function ComposeContext() which is to be used with our "grammar FST" framewo...
#define KALDI_ASSERT(cond)
Label FindLabel(const std::vector< int32 > &label_info)
Finds the label index corresponding to this context-window of phones (likely of width context_width_)...
kaldi::ConstIntegerSet< Label > disambig_syms_
int32 GetPhoneSymbolFor(enum NonterminalValues n)
kaldi::ConstIntegerSet< Label > phone_syms_