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