1 // fstequal.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: riley (at) google.com (Michael Riley) 17 // Modified: jpr (at) google.com (Jake Ratkiewicz) to use FstClass 18 // 19 // \file 20 // Two FSTS are equal iff they their exit status is zero. 21 // 22 23 #include <fst/script/equal.h> 24 25 DEFINE_double(delta, fst::kDelta, "Comparison/quantization delta"); 26 27 int main(int argc, char **argv) { 28 namespace s = fst::script; 29 using fst::script::FstClass; 30 31 string usage = "Two FSTs are equal iff the exit status is zero.\n\n Usage: "; 32 usage += argv[0]; 33 usage += " in1.fst in2.fst\n"; 34 35 std::set_new_handler(FailedNewHandler); 36 SetFlags(usage.c_str(), &argc, &argv, true); 37 if (argc != 3) { 38 ShowUsage(); 39 return 1; 40 } 41 42 string in1_name = strcmp(argv[1], "-") == 0 ? "" : argv[1]; 43 string in2_name = strcmp(argv[2], "-") == 0 ? "" : argv[2]; 44 45 if (in1_name.empty() && in2_name.empty()) { 46 LOG(ERROR) << argv[0] << ": Can't take both inputs from standard input."; 47 return 1; 48 } 49 50 FstClass *ifst1 = FstClass::Read(in1_name); 51 if (!ifst1) return 1; 52 53 FstClass *ifst2 = FstClass::Read(in2_name); 54 if (!ifst2) return 1; 55 56 bool result = s::Equal(*ifst1, *ifst2, FLAGS_delta); 57 if (!result) 58 VLOG(1) << "FSTs are not equal."; 59 60 return result ? 0 : 2; 61 } 62