lattice-copy.cc File Reference
Include dependency graph for lattice-copy.cc:

Go to the source code of this file.

Namespaces

 kaldi
 This code computes Goodness of Pronunciation (GOP) and extracts phone-level pronunciation feature for mispronunciations detection tasks, the reference:
 

Functions

int32 CopySubsetLattices (std::string filename, SequentialLatticeReader *lattice_reader, LatticeWriter *lattice_writer, bool include=true, bool ignore_missing=false, bool sorted=false)
 
int32 CopySubsetLattices (std::string filename, SequentialCompactLatticeReader *lattice_reader, CompactLatticeWriter *lattice_writer, bool include=true, bool ignore_missing=false, bool sorted=false)
 
int main (int argc, char *argv[])
 

Function Documentation

◆ main()

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

Definition at line 131 of file lattice-copy.cc.

References kaldi::ClassifyRspecifier(), kaldi::CopySubsetLattices(), SequentialTableReader< Holder >::Done(), ParseOptions::GetArg(), KALDI_ERR, KALDI_LOG, SequentialTableReader< Holder >::Key(), SequentialTableReader< Holder >::Next(), ParseOptions::NumArgs(), ParseOptions::PrintUsage(), ParseOptions::Read(), ParseOptions::Register(), RspecifierOptions::sorted, SequentialTableReader< Holder >::Value(), and TableWriter< Holder >::Write().

131  {
132  try {
133  using namespace kaldi;
134  typedef kaldi::int32 int32;
135  typedef kaldi::int64 int64;
136  using fst::SymbolTable;
137  using fst::VectorFst;
138  using fst::StdArc;
139 
140  const char *usage =
141  "Copy lattices (e.g. useful for changing to text mode or changing\n"
142  "format to standard from compact lattice.)\n"
143  "The --include and --exclude options can be used to copy only a subset "
144  "of lattices, where are the --include option specifies the "
145  "whitelisted utterances that would be copied and --exclude option "
146  "specifies the blacklisted utterances that would not be copied.\n"
147  "Only one of --include and --exclude can be supplied.\n"
148  "Usage: lattice-copy [options] lattice-rspecifier lattice-wspecifier\n"
149  " e.g.: lattice-copy --write-compact=false ark:1.lats ark,t:text.lats\n"
150  "See also: lattice-scale, lattice-to-fst, and\n"
151  " the script egs/wsj/s5/utils/convert_slf.pl\n";
152 
153  ParseOptions po(usage);
154  bool write_compact = true, ignore_missing = false;
155  std::string include_rxfilename;
156  std::string exclude_rxfilename;
157 
158  po.Register("write-compact", &write_compact, "If true, write in normal (compact) form.");
159  po.Register("include", &include_rxfilename,
160  "Text file, the first field of each "
161  "line being interpreted as the "
162  "utterance-id whose lattices will be included");
163  po.Register("exclude", &exclude_rxfilename,
164  "Text file, the first field of each "
165  "line being interpreted as an utterance-id "
166  "whose lattices will be excluded");
167  po.Register("ignore-missing", &ignore_missing,
168  "Exit with status 0 even if no lattices are copied");
169 
170  po.Read(argc, argv);
171 
172  if (po.NumArgs() != 2) {
173  po.PrintUsage();
174  exit(1);
175  }
176 
177  std::string lats_rspecifier = po.GetArg(1),
178  lats_wspecifier = po.GetArg(2);
179 
180  RspecifierOptions opts;
181  ClassifyRspecifier(lats_rspecifier, NULL, &opts);
182  bool sorted = opts.sorted;
183 
184  int32 n_done = 0;
185 
186  if (write_compact) {
187  SequentialCompactLatticeReader lattice_reader(lats_rspecifier);
188  CompactLatticeWriter lattice_writer(lats_wspecifier);
189 
190  if (include_rxfilename != "") {
191  if (exclude_rxfilename != "") {
192  KALDI_ERR << "should not have both --exclude and --include option!";
193  }
194  return CopySubsetLattices(include_rxfilename,
195  &lattice_reader, &lattice_writer,
196  true, ignore_missing, sorted);
197  } else if (exclude_rxfilename != "") {
198  return CopySubsetLattices(exclude_rxfilename,
199  &lattice_reader, &lattice_writer,
200  false, ignore_missing);
201  }
202 
203  for (; !lattice_reader.Done(); lattice_reader.Next(), n_done++)
204  lattice_writer.Write(lattice_reader.Key(), lattice_reader.Value());
205  } else {
206  SequentialLatticeReader lattice_reader(lats_rspecifier);
207  LatticeWriter lattice_writer(lats_wspecifier);
208 
209  if (include_rxfilename != "") {
210  if (exclude_rxfilename != "") {
211  KALDI_ERR << "should not have both --exclude and --include option!";
212  }
213  return CopySubsetLattices(include_rxfilename,
214  &lattice_reader, &lattice_writer,
215  true, ignore_missing, sorted);
216  } else if (exclude_rxfilename != "") {
217  return CopySubsetLattices(exclude_rxfilename,
218  &lattice_reader, &lattice_writer,
219  true, ignore_missing);
220  }
221 
222  for (; !lattice_reader.Done(); lattice_reader.Next(), n_done++)
223  lattice_writer.Write(lattice_reader.Key(), lattice_reader.Value());
224  }
225  KALDI_LOG << "Done copying " << n_done << " lattices.";
226 
227  if (ignore_missing) return 0;
228 
229  return (n_done != 0 ? 0 : 1);
230  } catch(const std::exception &e) {
231  std::cerr << e.what();
232  return -1;
233  }
234 }
This code computes Goodness of Pronunciation (GOP) and extracts phone-level pronunciation feature for...
Definition: chain.dox:20
int32 CopySubsetLattices(std::string filename, SequentialLatticeReader *lattice_reader, LatticeWriter *lattice_writer, bool include=true, bool ignore_missing=false, bool sorted=false)
Definition: lattice-copy.cc:28
fst::StdArc StdArc
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
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
#define KALDI_ERR
Definition: kaldi-error.h:147
#define KALDI_LOG
Definition: kaldi-error.h:153