• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // fstclosure.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@google.com (Michael Riley)
17 // Modified: jpr@google.com (Jake Ratkiewicz) to use FstClass
18 //
19 // \file
20 // Creates the Kleene closure of an FST.
21 //
22 
23 #include <fst/script/closure.h>
24 
25 DEFINE_bool(closure_plus, false,
26             "Do not add the empty path (T+ instead of T*)");
27 
main(int argc,char ** argv)28 int main(int argc, char **argv) {
29   using fst::script::FstClass;
30   using fst::script::MutableFstClass;
31 
32   string usage = "Creates the Kleene closure of an FST.\n\n  Usage: ";
33   usage += argv[0];
34   usage += " [in.fst [out.fst]]\n";
35 
36   std::set_new_handler(FailedNewHandler);
37   SetFlags(usage.c_str(), &argc, &argv, true);
38   if (argc > 3) {
39     ShowUsage();
40     return 1;
41   }
42 
43   string in_fname = (argc > 1 && strcmp(argv[1], "-") != 0) ? argv[1] : "";
44   string out_fname = argc > 2 ? argv[2] : "";
45 
46   MutableFstClass *fst = MutableFstClass::Read(in_fname, true);
47   if (!fst) return 1;
48 
49   fst::ClosureType closure_type =
50       FLAGS_closure_plus ? fst::CLOSURE_PLUS : fst::CLOSURE_STAR;
51 
52   fst::script::Closure(fst, closure_type);
53   fst->Write(out_fname);
54 
55   return 0;
56 }
57