1// farequal.cc
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// Copyright 2005-2010 Google, Inc.
16// Author: allauzen@google.com (Cyril Allauzen)
17//
18// \file
19// Tests if two Far files contains the same (key,fst) pairs.
20
21#include <fst/extensions/far/main.h>
22#include <fst/extensions/far/farscript.h>
23
24DEFINE_string(begin_key, "",
25              "First key to extract (def: first key in archive)");
26DEFINE_string(end_key, "",
27              "Last key to extract (def: last key in archive)");
28DEFINE_double(delta, fst::kDelta, "Comparison/quantization delta");
29
30int main(int argc, char **argv) {
31  namespace s = fst::script;
32
33  string usage = "Compares the FSTs in two FST archives for equality.";
34  usage += "\n\n Usage:";
35  usage += argv[0];
36  usage += " in1.far in2.far\n";
37  usage += "  Flags: begin_key end_key";
38
39  std::set_new_handler(FailedNewHandler);
40  SET_FLAGS(usage.c_str(), &argc, &argv, true);
41
42  if (argc != 3) {
43    ShowUsage();
44    return 1;
45  }
46
47  string filename1(argv[1]), filename2(argv[2]);
48
49  bool result = s::FarEqual(
50      filename1, filename2, fst::LoadArcTypeFromFar(filename1),
51      FLAGS_delta, FLAGS_begin_key, FLAGS_end_key);
52
53  if (!result)
54    VLOG(1) << "FARs are not equal.";
55
56  return result ? 0 : 2;
57}
58