26 int main(
int argc,
char *argv[]) {
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";
47 "Delta parameter for equivalence test");
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");
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();
78 if (!lattice_reader2.
HasKey(key)) {
79 KALDI_WARN <<
"No 2nd lattice present for utterance " << 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...
void PrintUsage(bool print_command_line=false)
Prints the usage documentation [provided in the constructor].
void Register(const std::string &name, bool *ptr, const std::string &doc)
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...
const T & Value(const std::string &key)
int main(int argc, char *argv[])
A templated class for reading objects sequentially from an archive or script file; see The Table conc...
fst::VectorFst< LatticeArc > Lattice
int Read(int argc, const char *const *argv)
Parses the command line options and fills the ParseOptions-registered variables.
std::string GetArg(int param) const
Returns one of the positional parameters; 1-based indexing for argc/argv compatibility.
bool HasKey(const std::string &key)
int Rand(struct RandomState *state)
int NumArgs() const
Number of positional parameters (c.f. argc-1).
#define KALDI_ASSERT(cond)