fstrand.cc
Go to the documentation of this file.
1 // fstbin/fstrand.cc
2 
3 // Copyright 2009-2011 Microsoft Corporation
4 
5 // See ../../COPYING for clarification regarding multiple authors
6 //
7 // Licensed under the Apache License, Version 2.0 (the "License");
8 // you may not use this file except in compliance with the License.
9 // You may obtain a copy of the License at
10 //
11 // http://www.apache.org/licenses/LICENSE-2.0
12 //
13 // THIS CODE IS PROVIDED *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14 // KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY IMPLIED
15 // WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE,
16 // MERCHANTABLITY OR NON-INFRINGEMENT.
17 // See the Apache 2 License for the specific language governing permissions and
18 // limitations under the License.
19 
20 
21 #include "base/kaldi-common.h"
22 #include "util/kaldi-io.h"
23 #include "util/parse-options.h"
24 #include "util/text-utils.h"
25 #include "fstext/rand-fst.h"
26 #include "time.h"
27 #include "fstext/fstext-utils.h"
28 #include "fstext/kaldi-fst-io.h"
29 
30 int main(int argc, char *argv[]) {
31  try {
32  using namespace fst;
33  using kaldi::int32;
34 
35  const char *usage =
36  "Generate random FST\n"
37  "\n"
38  "Usage: fstrand [out.fst]\n";
39 
40  srand(time(NULL));
41  RandFstOptions opts;
42 
43 
44  kaldi::ParseOptions po(usage);
45  po.Register("allow-empty", &opts.allow_empty,
46  "If true, we may generate an empty FST.");
47 
48  po.Read(argc, argv);
49 
50  if (po.NumArgs() > 1) {
51  po.PrintUsage();
52  exit(1);
53  }
54 
55  std::string fst_out_filename = po.GetOptArg(1);
56 
57  VectorFst <StdArc> *rand_fst = RandFst<StdArc>(opts);
58 
59  WriteFstKaldi(*rand_fst, fst_out_filename);
60  delete rand_fst;
61  return 0;
62  } catch(const std::exception &e) {
63  std::cerr << e.what();
64  return -1;
65  }
66 }
67 
For an extended explanation of the framework of which grammar-fsts are a part, please see Support for...
Definition: graph.dox:21
void PrintUsage(bool print_command_line=false)
Prints the usage documentation [provided in the constructor].
kaldi::int32 int32
void Register(const std::string &name, bool *ptr, const std::string &doc)
The class ParseOptions is for parsing command-line options; see Parsing command-line options for more...
Definition: parse-options.h:36
int Read(int argc, const char *const *argv)
Parses the command line options and fills the ParseOptions-registered variables.
int main(int argc, char *argv[])
Definition: fstrand.cc:30
int NumArgs() const
Number of positional parameters (c.f. argc-1).
void WriteFstKaldi(std::ostream &os, bool binary, const VectorFst< Arc > &t)
std::string GetOptArg(int param) const