FST  openfst-1.7.1
OpenFst Library
farequal.cc
Go to the documentation of this file.
1 // See www.openfst.org for extensive documentation on this weighted
2 // finite-state transducer library.
3 //
4 // Tests if two Far files contains the same (key,fst) pairs.
5 
6 #include <string>
7 
8 #include <fst/flags.h>
11 
12 DEFINE_string(begin_key, "",
13  "First key to extract (def: first key in archive)");
14 DEFINE_string(end_key, "", "Last key to extract (def: last key in archive)");
15 DEFINE_double(delta, fst::kDelta, "Comparison/quantization delta");
16 
17 int main(int argc, char **argv) {
18  namespace s = fst::script;
19 
20  string usage = "Compares the FSTs in two FST archives for equality.";
21  usage += "\n\n Usage:";
22  usage += argv[0];
23  usage += " in1.far in2.far";
24 
25  std::set_new_handler(FailedNewHandler);
26  SET_FLAGS(usage.c_str(), &argc, &argv, true);
27  s::ExpandArgs(argc, argv, &argc, &argv);
28  if (argc != 3) {
29  ShowUsage();
30  return 1;
31  }
32 
33  const auto arc_type = s::LoadArcTypeFromFar(argv[1]);
34  if (arc_type.empty()) return 1;
35 
36  bool result = s::FarEqual(argv[1], argv[2], arc_type, FLAGS_delta,
37  FLAGS_begin_key, FLAGS_end_key);
38 
39  if (!result) VLOG(1) << "FARs are not equal.";
40 
41  return result ? 0 : 2;
42 }
void ShowUsage(bool long_usage=true)
Definition: flags.cc:124
void ExpandArgs(int argc, char **argv, int *argcp, char ***argvp)
Definition: getters.cc:55
DEFINE_string(begin_key,"","First key to extract (def: first key in archive)")
int main(int argc, char **argv)
Definition: farequal.cc:17
void FailedNewHandler()
Definition: compat.cc:25
#define SET_FLAGS(usage, argc, argv, rmflags)
Definition: flags.h:214
bool FarEqual(const string &filename1, const string &filename2, const string &arc_type, float delta, const string &begin_key, const string &end_key)
Definition: farscript.cc:38
#define VLOG(level)
Definition: log.h:49
DEFINE_double(delta, fst::kDelta,"Comparison/quantization delta")
constexpr float kDelta
Definition: weight.h:109
string LoadArcTypeFromFar(const string &far_fname)
Definition: script-impl.cc:17