FST  openfst-1.7.2
OpenFst Library
farisomorphic.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 isomorphic (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 isomorphism.";
21  usage += "\n\n Usage:";
22  usage += argv[0];
23  usage += " in1.far in2.far\n";
24  usage += " Flags: begin_key end_key";
25 
26  std::set_new_handler(FailedNewHandler);
27  SET_FLAGS(usage.c_str(), &argc, &argv, true);
28  s::ExpandArgs(argc, argv, &argc, &argv);
29 
30  if (argc != 3) {
31  ShowUsage();
32  return 1;
33  }
34 
35  const auto arc_type = s::LoadArcTypeFromFar(argv[1]);
36  if (arc_type.empty()) return 1;
37 
38  bool result = s::FarIsomorphic(argv[1], argv[2], arc_type,
39  FLAGS_delta, FLAGS_begin_key, FLAGS_end_key);
40 
41  if (!result) VLOG(1) << "FARs are not isomorphic.";
42 
43  return result ? 0 : 2;
44 }
void ShowUsage(bool long_usage=true)
Definition: flags.cc:124
void ExpandArgs(int argc, char **argv, int *argcp, char ***argvp)
Definition: getters.cc:55
void FailedNewHandler()
Definition: compat.cc:25
#define SET_FLAGS(usage, argc, argv, rmflags)
Definition: flags.h:214
#define VLOG(level)
Definition: log.h:49
int main(int argc, char **argv)
DEFINE_double(delta, fst::kDelta,"Comparison/quantization delta")
bool FarIsomorphic(const string &filename1, const string &filename2, const string &arc_type, float delta, const string &begin_key, const string &end_key)
Definition: farscript.cc:70
DEFINE_string(begin_key,"","First key to extract (def: first key in archive)")
constexpr float kDelta
Definition: weight.h:109
string LoadArcTypeFromFar(const string &far_fname)
Definition: script-impl.cc:17