FST  openfst-1.8.3
OpenFst Library
fstequal-main.cc
Go to the documentation of this file.
1 // Copyright 2005-2024 Google LLC
2 //
3 // Licensed under the Apache License, Version 2.0 (the 'License');
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 // http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an 'AS IS' BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14 //
15 // See www.openfst.org for extensive documentation on this weighted
16 // finite-state transducer library.
17 //
18 // Two FSTS are equal iff their exit status is zero.
19 
20 #include <cstring>
21 #include <memory>
22 #include <string>
23 
24 #include <fst/flags.h>
25 #include <fst/log.h>
26 #include <fst/script/equal.h>
27 #include <fst/script/fst-class.h>
28 
29 DECLARE_double(delta);
30 
31 int fstequal_main(int argc, char **argv) {
32  namespace s = fst::script;
34 
35  std::string usage =
36  "Two FSTs are equal iff the exit status is zero.\n\n Usage: ";
37  usage += argv[0];
38  usage += " in1.fst in2.fst\n";
39 
40  SET_FLAGS(usage.c_str(), &argc, &argv, true);
41  if (argc != 3) {
42  ShowUsage();
43  return 1;
44  }
45 
46  const std::string in1_name = strcmp(argv[1], "-") == 0 ? "" : argv[1];
47  const std::string in2_name = strcmp(argv[2], "-") == 0 ? "" : argv[2];
48 
49  if (in1_name.empty() && in2_name.empty()) {
50  LOG(ERROR) << argv[0] << ": Can't take both inputs from standard input";
51  return 1;
52  }
53 
54  std::unique_ptr<FstClass> ifst1(FstClass::Read(in1_name));
55  if (!ifst1) return 1;
56 
57  std::unique_ptr<FstClass> ifst2(FstClass::Read(in2_name));
58  if (!ifst2) return 1;
59 
60  const bool result = s::Equal(*ifst1, *ifst2, FST_FLAGS_delta);
61  if (!result) VLOG(1) << "FSTs are not equal";
62 
63  return result ? 0 : 2;
64 }
void ShowUsage(bool long_usage=true)
Definition: flags.cc:138
bool Equal(FarReaderClass &reader1, FarReaderClass &reader2, float delta, std::string_view begin_key, std::string_view end_key)
Definition: farscript.cc:112
#define LOG(type)
Definition: log.h:53
int fstequal_main(int argc, char **argv)
#define SET_FLAGS(usage, argc, argv, rmflags)
Definition: flags.h:226
#define VLOG(level)
Definition: log.h:54
DECLARE_double(delta)