1 // fstepsnormalize.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 // Modified: jpr@google.com (Jake Ratkiewicz) to use FstClass
18 //
19 // \file
20 // Epsilon normalizes an FST.
21 //
22 
23 #include <fst/script/epsnormalize.h>
24 
25 DEFINE_bool(eps_norm_output, false, "Normalize output epsilons");
26 
main(int argc,char ** argv)27 int main(int argc, char **argv) {
28   namespace s = fst::script;
29   using fst::script::FstClass;
30   using fst::script::VectorFstClass;
31 
32 
33   string usage = "Epsilon normalizes an FST.\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   FstClass *ifst = FstClass::Read(in_name);
48   if (!ifst) return 1;
49 
50   fst::EpsNormalizeType eps_norm_type = FLAGS_eps_norm_output ?
51       fst::EPS_NORM_OUTPUT : fst::EPS_NORM_INPUT;
52 
53   VectorFstClass ofst(ifst->ArcType());
54   s::EpsNormalize(*ifst, &ofst, eps_norm_type);
55   ofst.Write(out_name);
56 
57   return 0;
58 }
59