1 // fstunion.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 // Creates the union of two FSTs. 21 // 22 23 #include <string> 24 25 #include <fst/script/union.h> 26 #include <iostream> 27 #include <fstream> 28 29 int main(int argc, char **argv) { 30 using fst::script::FstClass; 31 using fst::script::MutableFstClass; 32 using fst::script::Union; 33 34 string usage = "Creates the union of two FSTs.\n\n Usage: "; 35 usage += argv[0]; 36 usage += " in1.fst in2.fst [out.fst]\n"; 37 38 std::set_new_handler(FailedNewHandler); 39 SetFlags(usage.c_str(), &argc, &argv, true); 40 if (argc < 3 || argc > 4) { 41 ShowUsage(); 42 return 1; 43 } 44 45 string in1_name = strcmp(argv[1], "-") != 0 ? argv[1] : ""; 46 string in2_name = strcmp(argv[2], "-") != 0 ? argv[2] : ""; 47 string out_name = argc > 3 ? argv[3] : ""; 48 49 if (in1_name == "" && in2_name == "") { 50 LOG(ERROR) << argv[0] 51 << ": Can't use standard i/o for both inputs."; 52 return 1; 53 } 54 55 MutableFstClass *fst1 = MutableFstClass::Read(in1_name, true); 56 if (!fst1) return 1; 57 58 FstClass *fst2 = FstClass::Read(in2_name); 59 if (!fst2) { 60 return 1; 61 } 62 63 Union(fst1, *fst2); 64 fst1->Write(out_name); 65 66 return 0; 67 } 68