lattice-union.cc File Reference
Include dependency graph for lattice-union.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-union.cc.

References fst::DeterminizeLattice(), SequentialTableReader< Holder >::Done(), SequentialTableReader< Holder >::FreeCurrent(), ParseOptions::GetArg(), RandomAccessTableReader< Holder >::HasKey(), KALDI_LOG, KALDI_WARN, SequentialTableReader< Holder >::Key(), SequentialTableReader< Holder >::Next(), ParseOptions::NumArgs(), ParseOptions::PrintUsage(), ParseOptions::Read(), RandomAccessTableReader< Holder >::Value(), 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  "Takes two archives of lattices (indexed by utterances) and computes "
37  "the union of the individual lattice pairs (one from each archive).\n"
38  "Usage: lattice-union [options] lattice-rspecifier1 lattice-rspecifier2"
39  " lattice-wspecifier\n"
40  " e.g.: lattice-union ark:den.lats ark:num.lats ark:union.lats\n";
41 
42  ParseOptions po(usage);
43  po.Read(argc, argv);
44 
45  if (po.NumArgs() != 3) {
46  po.PrintUsage();
47  exit(1);
48  }
49 
50  std::string lats_rspecifier1 = po.GetArg(1),
51  lats_rspecifier2 = po.GetArg(2),
52  lats_wspecifier = po.GetArg(3);
53 
54  SequentialLatticeReader lattice_reader1(lats_rspecifier1);
55  RandomAccessLatticeReader lattice_reader2(lats_rspecifier2);
56 
57  CompactLatticeWriter compact_lattice_writer(lats_wspecifier);
58 
59  int32 n_done = 0, n_union = 0, n_no_lat = 0;
60 
61  for (; !lattice_reader1.Done(); lattice_reader1.Next()) {
62  std::string key = lattice_reader1.Key();
63  Lattice lat1 = lattice_reader1.Value();
64  lattice_reader1.FreeCurrent();
65  if (lattice_reader2.HasKey(key)) {
66  const Lattice &lat2 = lattice_reader2.Value(key);
67  Union(&lat1, lat2);
68  n_union++;
69  } else {
70  KALDI_WARN << "No lattice found for utterance " << key << " in "
71  << lats_rspecifier2 << ". Result of union will be the "
72  << "lattice found in " << lats_rspecifier1;
73  n_no_lat++;
74  }
75 
76  Invert(&lat1); // so that word labels are on the input.
77  CompactLattice clat_out;
78  DeterminizeLattice(lat1, &clat_out);
79  // The determinization obviates the need to convert to conpact lattice
80  // format using ConvertLattice(lat1, &clat_out);
81  compact_lattice_writer.Write(key, clat_out);
82  n_done++;
83  }
84 
85  KALDI_LOG << "Total " << n_done << "lattices written. Computed union for "
86  << n_union << " pairs of lattices. Missing second lattice in "
87  << n_no_lat << " cases.";
88  KALDI_LOG << "Done " << n_done << " lattices.";
89  return (n_done != 0 ? 0 : 1);
90  } catch(const std::exception &e) {
91  std::cerr << e.what();
92  return -1;
93  }
94 }
This code computes Goodness of Pronunciation (GOP) and extracts phone-level pronunciation feature for...
Definition: chain.dox:20
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
Allows random access to a collection of objects in an archive or script file; see The Table concept...
Definition: kaldi-table.h:233
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
fst::VectorFst< LatticeArc > Lattice
Definition: kaldi-lattice.h:44
#define KALDI_WARN
Definition: kaldi-error.h:150
fst::VectorFst< CompactLatticeArc > CompactLattice
Definition: kaldi-lattice.h:46
bool DeterminizeLattice(const Fst< ArcTpl< Weight > > &ifst, MutableFst< ArcTpl< Weight > > *ofst, DeterminizeLatticeOptions opts, bool *debug_ptr)
This function implements the normal version of DeterminizeLattice, in which the output strings are re...
#define KALDI_LOG
Definition: kaldi-error.h:153