fstdeterminizestar.cc File Reference
#include "base/kaldi-common.h"
#include "util/common-utils.h"
#include "fst/fstlib.h"
#include "fstext/determinize-star.h"
#include "fstext/fstext-utils.h"
#include "fstext/kaldi-fst-io.h"
#include <signal.h>
Include dependency graph for fstdeterminizestar.cc:

Go to the source code of this file.

Functions

void signal_handler (int)
 
int main (int argc, char *argv[])
 

Variables

bool debug_location = false
 

Function Documentation

◆ main()

int main ( int  argc,
char *  argv[] 
)

Definition at line 64 of file fstdeterminizestar.cc.

References kaldi::ClassifyRspecifier(), fst::DeterminizeStar(), fst::DeterminizeStarInLog(), SequentialTableReader< Holder >::Done(), SequentialTableReader< Holder >::FreeCurrent(), ParseOptions::GetOptArg(), KALDI_WARN, SequentialTableReader< Holder >::Key(), kaldi::kNoRspecifier, SequentialTableReader< Holder >::Next(), ParseOptions::NumArgs(), ParseOptions::PrintUsage(), ParseOptions::Read(), fst::ReadFstKaldi(), ParseOptions::Register(), signal_handler(), SequentialTableReader< Holder >::Value(), TableWriter< Holder >::Write(), and fst::WriteFstKaldi().

64  {
65  try {
66  using namespace kaldi;
67  using namespace fst;
68  using kaldi::int32;
69 
70  const char *usage =
71  "Removes epsilons and determinizes in one step\n"
72  "\n"
73  "Usage: fstdeterminizestar [in.fst [out.fst] ]\n"
74  "\n"
75  "See also: fstdeterminizelog, lattice-determinize\n";
76 
77  float delta = kDelta;
78  int max_states = -1;
79  bool use_log = false;
80  ParseOptions po(usage);
81  po.Register("use-log", &use_log, "Determinize in log semiring.");
82  po.Register("delta", &delta, "Delta value used to determine equivalence of weights.");
83  po.Register("max-states", &max_states, "Maximum number of states in determinized FST before it will abort.");
84  po.Read(argc, argv);
85 
86  if (po.NumArgs() > 2) {
87  po.PrintUsage();
88  exit(1);
89  }
90 
91  std::string fst_in_str = po.GetOptArg(1),
92  fst_out_str = po.GetOptArg(2);
93 
94  // This enables us to get traceback info from determinization that is
95  // not seeming to terminate.
96 #if !defined(_MSC_VER) && !defined(__APPLE__)
97  signal(SIGUSR1, signal_handler);
98 #endif
99  if (ClassifyRspecifier(fst_in_str, NULL, NULL) == kNoRspecifier) {
100  // Normal case: just files.
101  VectorFst<StdArc> *fst = ReadFstKaldi(fst_in_str);
102 
103  ArcSort(fst, ILabelCompare<StdArc>()); // improves speed.
104  if (use_log) {
105  DeterminizeStarInLog(fst, delta, &debug_location, max_states);
106  } else {
107  VectorFst<StdArc> det_fst;
108  DeterminizeStar(*fst, &det_fst, delta, &debug_location, max_states);
109  *fst = det_fst; // will do shallow copy and then det_fst goes
110  // out of scope anyway.
111  }
112  WriteFstKaldi(*fst, fst_out_str);
113  delete fst;
114  } else { // Dealing with archives.
115  SequentialTableReader<VectorFstHolder> fst_reader(fst_in_str);
116  TableWriter<VectorFstHolder> fst_writer(fst_out_str);
117  for (; !fst_reader.Done(); fst_reader.Next()) {
118  std::string key = fst_reader.Key();
119  VectorFst<StdArc> fst(fst_reader.Value());
120  fst_reader.FreeCurrent();
121  ArcSort(&fst, ILabelCompare<StdArc>()); // improves speed.
122  try {
123  if (use_log) {
124  DeterminizeStarInLog(&fst, delta, &debug_location, max_states);
125  } else {
126  VectorFst<StdArc> det_fst;
127  DeterminizeStar(fst, &det_fst, delta, &debug_location, max_states);
128  fst = det_fst; // will do shallow copy and then det_fst goes out
129  // of scope anyway.
130  }
131  fst_writer.Write(key, fst);
132  } catch (const std::runtime_error &e) {
133  KALDI_WARN << "Error during determinization for key " << key;
134  }
135  }
136  }
137  return 0;
138  } catch(const std::exception &e) {
139  std::cerr << e.what();
140  return -1;
141  }
142 }
This code computes Goodness of Pronunciation (GOP) and extracts phone-level pronunciation feature for...
Definition: chain.dox:20
For an extended explanation of the framework of which grammar-fsts are a part, please see Support for...
Definition: graph.dox:21
A templated class for writing objects to an archive or script file; see The Table concept...
Definition: kaldi-table.h:368
kaldi::int32 int32
RspecifierType ClassifyRspecifier(const std::string &rspecifier, std::string *rxfilename, RspecifierOptions *opts)
Definition: kaldi-table.cc:225
void DeterminizeStarInLog(VectorFst< StdArc > *fst, float delta, bool *debug_ptr, int max_states)
The class ParseOptions is for parsing command-line options; see Parsing command-line options for more...
Definition: parse-options.h:36
A templated class for reading objects sequentially from an archive or script file; see The Table conc...
Definition: kaldi-table.h:287
void signal_handler(int)
#define KALDI_WARN
Definition: kaldi-error.h:150
bool debug_location
void WriteFstKaldi(std::ostream &os, bool binary, const VectorFst< Arc > &t)
void ReadFstKaldi(std::istream &is, bool binary, VectorFst< Arc > *fst)
bool DeterminizeStar(F &ifst, MutableFst< typename F::Arc > *ofst, float delta, bool *debug_ptr, int max_states, bool allow_partial)
This function implements the normal version of DeterminizeStar, in which the output strings are repre...

◆ signal_handler()

void signal_handler ( int  )

Definition at line 58 of file fstdeterminizestar.cc.

Referenced by main().

58  {
59  debug_location = true;
60 }
bool debug_location

Variable Documentation

◆ debug_location

bool debug_location = false

Definition at line 57 of file fstdeterminizestar.cc.