FST  openfst-1.7.3
OpenFst Library
fstequal-main.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 // Two FSTS are equal iff their exit status is zero.
5 
6 #include <cstring>
7 #include <memory>
8 #include <string>
9 
10 #include <fst/flags.h>
11 #include <fst/log.h>
12 #include <fst/script/equal.h>
13 
14 DECLARE_double(delta);
15 
16 int fstequal_main(int argc, char **argv) {
17  namespace s = fst::script;
19 
20  std::string usage =
21  "Two FSTs are equal iff the exit status is zero.\n\n Usage: ";
22  usage += argv[0];
23  usage += " in1.fst in2.fst\n";
24 
25  std::set_new_handler(FailedNewHandler);
26  SET_FLAGS(usage.c_str(), &argc, &argv, true);
27  if (argc != 3) {
28  ShowUsage();
29  return 1;
30  }
31 
32  const std::string in1_name = strcmp(argv[1], "-") == 0 ? "" : argv[1];
33  const std::string in2_name = strcmp(argv[2], "-") == 0 ? "" : argv[2];
34 
35  if (in1_name.empty() && in2_name.empty()) {
36  LOG(ERROR) << argv[0] << ": Can't take both inputs from standard input";
37  return 1;
38  }
39 
40  std::unique_ptr<FstClass> ifst1(FstClass::Read(in1_name));
41  if (!ifst1) return 1;
42 
43  std::unique_ptr<FstClass> ifst2(FstClass::Read(in2_name));
44  if (!ifst2) return 1;
45 
46  bool result = s::Equal(*ifst1, *ifst2, FLAGS_delta);
47  if (!result) VLOG(1) << "FSTs are not equal.";
48 
49  return result ? 0 : 2;
50 }
void ShowUsage(bool long_usage=true)
Definition: flags.cc:121
#define LOG(type)
Definition: log.h:46
int fstequal_main(int argc, char **argv)
void FailedNewHandler()
Definition: compat.cc:20
#define SET_FLAGS(usage, argc, argv, rmflags)
Definition: flags.h:209
#define VLOG(level)
Definition: log.h:47
DECLARE_double(delta)
bool Equal(const Fst< Arc > &fst1, const Fst< Arc > &fst2, WeightEqual weight_equal, uint32 etype=kEqualFsts)
Definition: equal.h:43