Home | History | Annotate | Download | only in bin
      1 // fstproject.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 work with FstClass
     18 //
     19 // \file
     20 // Projects a transduction onto its input or output language.
     21 //
     22 
     23 #include <fst/script/project.h>
     24 
     25 DEFINE_bool(project_output, false, "Project on output (vs. input)");
     26 
     27 int main(int argc, char **argv) {
     28   namespace s = fst::script;
     29   using fst::script::FstClass;
     30   using fst::script::MutableFstClass;
     31 
     32   string usage = "Projects a transduction onto its input"
     33       " or output language.\n\n  Usage: ";
     34   usage += argv[0];
     35   usage += " [in.fst [out.fst]]\n";
     36 
     37   std::set_new_handler(FailedNewHandler);
     38   SET_FLAGS(usage.c_str(), &argc, &argv, true);
     39   if (argc > 3) {
     40     ShowUsage();
     41     return 1;
     42   }
     43 
     44   string in_name = (argc > 1 && strcmp(argv[1], "-") != 0) ? argv[1] : "";
     45   string out_name = argc > 2 ? argv[2] : "";
     46 
     47   MutableFstClass *fst = MutableFstClass::Read(in_name, true);
     48   if (!fst) return 1;
     49 
     50   fst::ProjectType project_type = FLAGS_project_output ?
     51       fst::PROJECT_OUTPUT : fst::PROJECT_INPUT;
     52 
     53   s::Project(fst, project_type);
     54 
     55   fst->Write(out_name);
     56 
     57   return 0;
     58 }
     59