28 using namespace kaldi;
30 typedef kaldi::int64 int64;
31 using fst::SymbolTable;
36 "Test whether sets of lattices are equivalent (return with status 0 if\n" 37 "all were equivalent, 1 otherwise, -1 on error)\n" 38 "Usage: lattice-equivalent [options] lattice-rspecifier1 lattice-rspecifier2\n" 39 " e.g.: lattice-equivalent ark:1.lats ark:2.lats\n";
46 po.Register(
"delta", &delta,
47 "Delta parameter for equivalence test");
48 po.Register(
"num-paths", &num_paths,
49 "Number of paths per lattice for testing randomized equivalence");
50 po.Register(
"max-error-proportion", &max_error_proportion,
51 "Maximum proportion of missing 2nd lattices, or inequivalent " 52 "lattices, we allow before returning nonzero status");
56 if (po.NumArgs() != 2) {
61 KALDI_ASSERT(max_error_proportion >= 0.0 && max_error_proportion <= 1.0);
63 std::string lats_rspecifier1 = po.GetArg(1),
64 lats_rspecifier2 = po.GetArg(2);
73 int32 n_equivalent = 0, n_inequivalent = 0, n_no2nd = 0;
75 for (; !lattice_reader1.Done(); lattice_reader1.Next()) {
76 std::string key = lattice_reader1.Key();
77 const Lattice &lat1 = lattice_reader1.Value();
78 if (!lattice_reader2.HasKey(key)) {
79 KALDI_WARN <<
"No 2nd lattice present for utterance " << key;
83 const Lattice &lat2 = lattice_reader2.Value(key);
84 if (fst::RandEquivalent(lat1, lat2, num_paths, delta,
Rand())) {
86 KALDI_LOG <<
"Lattices were equivalent for utterance " << key;
89 KALDI_LOG <<
"Lattices were inequivalent for utterance " << key;
92 KALDI_LOG <<
"Done " << (n_equivalent + n_inequivalent) <<
" lattices, " 93 << n_equivalent <<
" were equivalent, " << n_inequivalent
94 <<
" were not; for " << n_no2nd <<
", could not find 2nd lattice.";
96 int32 num_inputs = n_equivalent + n_inequivalent + n_no2nd;
97 int32 max_bad = max_error_proportion * num_inputs;
99 if (n_no2nd > max_bad)
return -1;
100 else return (n_inequivalent > max_bad ? 1 : 0);
101 }
catch(
const std::exception &e) {
102 std::cerr << e.what();
This code computes Goodness of Pronunciation (GOP) and extracts phone-level pronunciation feature for...
Allows random access to a collection of objects in an archive or script file; see The Table concept...
The class ParseOptions is for parsing command-line options; see Parsing command-line options for more...
A templated class for reading objects sequentially from an archive or script file; see The Table conc...
fst::VectorFst< LatticeArc > Lattice
int Rand(struct RandomState *state)
#define KALDI_ASSERT(cond)