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

Go to the source code of this file.

Functions

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

Function Documentation

◆ main()

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

Definition at line 26 of file lattice-project.cc.

References fst::ConvertLattice(), SequentialTableReader< Holder >::Done(), SequentialTableReader< Holder >::FreeCurrent(), ParseOptions::GetArg(), KALDI_LOG, SequentialTableReader< Holder >::Key(), SequentialTableReader< Holder >::Next(), ParseOptions::NumArgs(), ParseOptions::PrintUsage(), ParseOptions::Read(), ParseOptions::Register(), fst::RemoveAlignmentsFromCompactLattice(), SequentialTableReader< Holder >::Value(), and TableWriter< Holder >::Write().

26  {
27  try {
28  using namespace kaldi;
29  typedef kaldi::int32 int32;
30  typedef kaldi::int64 int64;
31  using fst::SymbolTable;
32  using fst::VectorFst;
33  using fst::StdArc;
34 
35  const char *usage =
36  "Project lattices (in their transducer form); by default makes them\n"
37  "word->word transducers (set --project-output=false for tid->tid).\n"
38  "Usage: lattice-project [options] lattice-rspecifier lattice-wspecifier\n"
39  " e.g.: lattice-project ark:1.lats ark:word2word.lats\n"
40  "or: lattice-project --project-output=false ark:1.lats ark:tid2tid.lats";
41 
42  ParseOptions po(usage);
43  bool project_output = true;
44 
45  po.Register("project-output", &project_output, "If true, project on output "
46  "(words), else input (transition-ids)");
47 
48  po.Read(argc, argv);
49 
50  if (po.NumArgs() != 2) {
51  po.PrintUsage();
52  exit(1);
53  }
54 
55  std::string lats_rspecifier = po.GetArg(1),
56  lats_wspecifier = po.GetArg(2);
57 
58  LatticeWriter lattice_writer(lats_wspecifier);
59  int32 n_done = 0; // there is no failure mode, barring a crash.
60 
61  if (project_output) {
62  SequentialCompactLatticeReader clat_reader(lats_rspecifier);
63  for (; !clat_reader.Done(); clat_reader.Next()) {
64  CompactLattice clat = clat_reader.Value();
65  std::string key = clat_reader.Key();
66  clat_reader.FreeCurrent();
68  Lattice lat;
69  ConvertLattice(clat, &lat);
70  fst::Project(&lat, fst::PROJECT_OUTPUT); // project on words.
71  lattice_writer.Write(key, lat);
72  n_done++;
73  }
74  } else {
75  // Read and write as regular lattice.
76  SequentialLatticeReader lattice_reader(lats_rspecifier);
77  for (; !lattice_reader.Done(); lattice_reader.Next()) {
78  std::string key = lattice_reader.Key();
79  Lattice lat = lattice_reader.Value();
80  lattice_reader.FreeCurrent();
81  fst::Project(&lat, fst::PROJECT_INPUT);
82  lattice_writer.Write(key, lat);
83  n_done++;
84  }
85  }
86  KALDI_LOG << "Done projecting " << n_done << " lattices.";
87  return (n_done != 0 ? 0 : 1);
88  } catch(const std::exception &e) {
89  std::cerr << e.what();
90  return -1;
91  }
92 }
This code computes Goodness of Pronunciation (GOP) and extracts phone-level pronunciation feature for...
Definition: chain.dox:20
void RemoveAlignmentsFromCompactLattice(MutableFst< ArcTpl< CompactLatticeWeightTpl< Weight, Int > > > *fst)
Removes state-level alignments (the strings that are part of the weights).
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
The class ParseOptions is for parsing command-line options; see Parsing command-line options for more...
Definition: parse-options.h:36
void ConvertLattice(const ExpandedFst< ArcTpl< Weight > > &ifst, MutableFst< ArcTpl< CompactLatticeWeightTpl< Weight, Int > > > *ofst, bool invert)
Convert lattice from a normal FST to a CompactLattice FST.
A templated class for reading objects sequentially from an archive or script file; see The Table conc...
Definition: kaldi-table.h:287
fst::VectorFst< LatticeArc > Lattice
Definition: kaldi-lattice.h:44
fst::VectorFst< CompactLatticeArc > CompactLattice
Definition: kaldi-lattice.h:46
#define KALDI_LOG
Definition: kaldi-error.h:153