Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[src] Remove the GetLinearSymbolSequences() function #1594

Merged
merged 1 commit into from
Apr 29, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
70 changes: 0 additions & 70 deletions src/fstext/fstext-utils-inl.h
Original file line number Diff line number Diff line change
Expand Up @@ -215,76 +215,6 @@ bool GetLinearSymbolSequence(const Fst<Arc> &fst,
}
}

// see fstext-utils.h for comment.
template<class Arc, class I>
bool GetLinearSymbolSequences(const Fst<Arc> &fst,
vector<vector<I> > *isymbols_out,
vector<vector<I> > *osymbols_out,
vector<typename Arc::Weight> *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<Fst<Arc> > 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<Fst<Arc> > 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<class Arc>
Expand Down
10 changes: 0 additions & 10 deletions src/fstext/fstext-utils-test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -53,16 +53,6 @@ void TestMakeLinearAcceptor() {

if (vec2.size() != 0 || vec3.size() != 0) { // This test might not work
// for empty sequences...
{
vector<vector<I> > vecs2;
vector<vector<I> > vecs3;
vector<Weight> ws;
GetLinearSymbolSequences(vfst, &vecs2, &vecs3, &ws);
assert(vecs2.size() == 1);
assert(vecs2[0] == vec2);
assert(vecs3[0] == vec3);
assert(ApproxEqual(ws[0], w));
}
{
vector<VectorFst<Arc> > fstvec;
NbestAsFsts(vfst, 1, &fstvec);
Expand Down
21 changes: 0 additions & 21 deletions src/fstext/fstext-utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -135,27 +135,6 @@ bool GetLinearSymbolSequence(const Fst<Arc> &fst,
vector<I> *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<class Arc, class I>
bool GetLinearSymbolSequences(const Fst<Arc> &fst,
vector<vector<I> > *isymbols_out,
vector<vector<I> > *osymbols_out,
vector<typename Arc::Weight> *tot_weight_out);


/// This function converts an FST with a special structure, which is
/// output by the OpenFst functions ShortestPath and RandGen, and converts
Expand Down