From 2c793f19a4310037bbc362aaf8f43da2e998f385 Mon Sep 17 00:00:00 2001 From: Vassil Panayotov Date: Sat, 29 Apr 2017 10:16:24 +0300 Subject: [PATCH] [src] Remove the GetLinearSymbolSequences() function This function is not currently needed, and the implementation was buggy --- src/fstext/fstext-utils-inl.h | 70 --------------------------------- src/fstext/fstext-utils-test.cc | 10 ----- src/fstext/fstext-utils.h | 21 ---------- 3 files changed, 101 deletions(-) diff --git a/src/fstext/fstext-utils-inl.h b/src/fstext/fstext-utils-inl.h index f3b0b68b502..b28dd2b698f 100644 --- a/src/fstext/fstext-utils-inl.h +++ b/src/fstext/fstext-utils-inl.h @@ -215,76 +215,6 @@ bool GetLinearSymbolSequence(const Fst &fst, } } -// see fstext-utils.h for comment. -template -bool GetLinearSymbolSequences(const Fst &fst, - vector > *isymbols_out, - vector > *osymbols_out, - vector *weights_out) { - typedef typename Arc::StateId StateId; - typedef typename Arc::Weight Weight; - - if (isymbols_out) isymbols_out->clear(); - if (osymbols_out) osymbols_out->clear(); - if (weights_out) weights_out->clear(); - - StateId start_state = fst.Start(); - if (start_state == kNoStateId) { // no paths. - return true; // empty FST counts as having this structure. - } - - if (fst.Final(start_state) != Weight::Zero()) - return false; // We don't allow final-prob on the start state. - - size_t N = fst.NumArcs(start_state), n = 0; - if (isymbols_out) isymbols_out->resize(N); - if (osymbols_out) osymbols_out->resize(N); - if (weights_out) weights_out->resize(N); - - bool error = false; - - for (ArcIterator > aiter(fst, start_state); - !aiter.Done(); - aiter.Next(), n++) { - StateId cur_state = start_state; - if (isymbols_out) (*isymbols_out)[n].clear(); - if (osymbols_out) (*osymbols_out)[n].clear(); - if (weights_out) (*weights_out)[n] = Weight::One(); - - while (1) { - if (fst.Final(cur_state) != Weight::Zero()) { - (*weights_out)[n] = Times((*weights_out)[n], - fst.Final(cur_state)); - if (fst.NumArcs(cur_state) != 0) - error = true; - break; - } else { - if (fst.NumArcs(cur_state) != 1) { - error = true; - break; - } - ArcIterator > aiter(fst, cur_state); - const Arc &arc = aiter.Value(); - if (isymbols_out && arc.ilabel != 0) - (*isymbols_out)[n].push_back(arc.ilabel); - if (osymbols_out && arc.ilabel != 0) - (*osymbols_out)[n].push_back(arc.olabel); - if (weights_out) - (*weights_out)[n] = Times((*weights_out)[n], arc.weight); - cur_state = arc.nextstate; - } - } - if (error) break; - } - if (error) { - if (isymbols_out) isymbols_out->clear(); - if (osymbols_out) osymbols_out->clear(); - if (weights_out) weights_out->clear(); - return false; - } else { - return true; - } -} // see fstext-utils.sh for comment. template diff --git a/src/fstext/fstext-utils-test.cc b/src/fstext/fstext-utils-test.cc index b016b53691f..96ccf67366e 100644 --- a/src/fstext/fstext-utils-test.cc +++ b/src/fstext/fstext-utils-test.cc @@ -53,16 +53,6 @@ void TestMakeLinearAcceptor() { if (vec2.size() != 0 || vec3.size() != 0) { // This test might not work // for empty sequences... - { - vector > vecs2; - vector > vecs3; - vector ws; - GetLinearSymbolSequences(vfst, &vecs2, &vecs3, &ws); - assert(vecs2.size() == 1); - assert(vecs2[0] == vec2); - assert(vecs3[0] == vec3); - assert(ApproxEqual(ws[0], w)); - } { vector > fstvec; NbestAsFsts(vfst, 1, &fstvec); diff --git a/src/fstext/fstext-utils.h b/src/fstext/fstext-utils.h index a9038858eda..5caf4f58cb4 100644 --- a/src/fstext/fstext-utils.h +++ b/src/fstext/fstext-utils.h @@ -135,27 +135,6 @@ bool GetLinearSymbolSequence(const Fst &fst, vector *osymbols_out, typename Arc::Weight *tot_weight_out); -/// GetLinearSymbolSequence gets the symbol sequences and weights -/// from an FST as output by the ShortestPath algorithm (called with -/// some parameter n), which has up to n arcs out from the start state, -/// and if you follow one of the arcs you enter a linear sequence of -/// states. This function outputs the info in a more N-best-list-like -/// format. It returns true if the FST had the expected structure, -/// and false otherwise (note: an empty FST counts as having this -/// structure). We don't accept an FST that has a final-prob on the start -/// state, as it wouldn't be clear whether to put it as the first or -/// last path (this function is used in an N-best context where the -/// paths' ordering is somewhat meaningful.) -/// This function will set the output vectors to the appropriate -/// size, and for each path will output the input and output symbols as -/// vectors (not including epsilons). It outputs the total weight -/// for each path. -template -bool GetLinearSymbolSequences(const Fst &fst, - vector > *isymbols_out, - vector > *osymbols_out, - vector *tot_weight_out); - /// This function converts an FST with a special structure, which is /// output by the OpenFst functions ShortestPath and RandGen, and converts