Skip to content

Commit

Permalink
[src] Hopefully make it possible to use empty FST in grammar-fst (#3523)
Browse files Browse the repository at this point in the history
  • Loading branch information
danpovey authored Aug 19, 2019
1 parent 3f95ed9 commit 6cdc495
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 4 deletions.
13 changes: 10 additions & 3 deletions src/decoder/grammar-fst.cc
Original file line number Diff line number Diff line change
Expand Up @@ -110,12 +110,15 @@ void GrammarFst::InitNonterminalMap() {
}


void GrammarFst::InitEntryArcs(int32 i) {
bool GrammarFst::InitEntryArcs(int32 i) {
KALDI_ASSERT(static_cast<size_t>(i) < ifsts_.size());
const ConstFst<StdArc> &fst = *(ifsts_[i].second);
if (fst.NumStates() == 0)
return false; /* this was the empty FST. */
InitEntryOrReentryArcs(fst, fst.Start(),
GetPhoneSymbolFor(kNontermBegin),
&(entry_arcs_[i]));
return true;
}

void GrammarFst::InitInstances() {
Expand Down Expand Up @@ -345,8 +348,12 @@ GrammarFst::ExpandedState *GrammarFst::ExpandStateUserDefined(
const ConstFst<StdArc> &child_fst = *(child_instance.fst);
int32 child_ifst_index = child_instance.ifst_index;
std::unordered_map<int32, int32> &entry_arcs = entry_arcs_[child_ifst_index];
if (entry_arcs.empty())
InitEntryArcs(child_ifst_index);
if (entry_arcs.empty()) {
if (!InitEntryArcs(child_ifst_index)) {
// This child-FST was the empty FST. There are no arcs to expand.
continue;
}
}
// for explanation of cost_correction, see documentation for CombineArcs().
float num_entry_arcs = entry_arcs.size(),
cost_correction = -log(num_entry_arcs);
Expand Down
5 changes: 4 additions & 1 deletion src/decoder/grammar-fst.h
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,10 @@ class GrammarFst {
// too much work when it is initialized. Each call to this function only
// takes time O(number of left-context phones), which is quite small, but we'd
// like to avoid that if possible.
void InitEntryArcs(int32 i);
//
// This function returns true if it successfully initialized the
// entry_arcs_[i]; and false if it left it empty because
bool InitEntryArcs(int32 i);

// sets up instances_ with the top-level instance.
void InitInstances();
Expand Down

0 comments on commit 6cdc495

Please sign in to comment.