prune-special-test.cc
Go to the documentation of this file.
1 // fstext/prune-special-test.cc
2 
3 // Copyright 2014 Guoguo Chen
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 "fstext/prune-special.h"
22 #include "fstext/rand-fst.h"
23 #include "fstext/fstext-utils.h"
24 
25 namespace fst {
26 
27 static void TestPruneSpecial() {
28  typedef StdArc Arc;
29  typedef Arc::Label Label;
30  typedef Arc::StateId StateId;
31  typedef Arc::Weight Weight;
32 
33  RandFstOptions opts;
34  opts.acyclic = false;
35  VectorFst<Arc> *ifst = RandFst<StdArc>(opts);
36 
37  float beam = 0.55;
38 
39  {
40  FstPrinter<Arc> fstprinter(*ifst, NULL, NULL, NULL, false, true, "\t");
41  fstprinter.Print(&std::cout, "standard output");
42  std::cout << std::endl;
43  }
44 
45  // Do the special pruning.
46  VectorFst<Arc> ofst1;
47  PruneSpecial<StdArc>(*ifst, &ofst1, beam);
48  {
49  FstPrinter<Arc> fstprinter(ofst1, NULL, NULL, NULL, false, true, "\t");
50  fstprinter.Print(&std::cout, "standard output");
51  std::cout << std::endl;
52  }
53 
54  // Do the normal pruning.
55  VectorFst<Arc> ofst2;
56  Prune(*ifst, &ofst2, beam);
57  {
58  FstPrinter<Arc> fstprinter(ofst2, NULL, NULL, NULL, false, true, "\t");
59  fstprinter.Print(&std::cout, "standard output");
60  std::cout << std::endl;
61  }
62 
63  KALDI_ASSERT(RandEquivalent(ofst1, ofst2,
64  5/*paths*/, 0.01/*delta*/, kaldi::Rand()/*seed*/,
65  100/*path length-- max?*/));
66 
67  delete ifst;
68 }
69 
70 
71 } // namespace fst
72 
73 int main() {
75  using namespace fst;
76  for (int i = 0; i < 25; i++) {
78  }
79 }
fst::StdArc::StateId StateId
For an extended explanation of the framework of which grammar-fsts are a part, please see Support for...
Definition: graph.dox:21
fst::StdArc StdArc
int main()
static void TestPruneSpecial()
fst::StdArc::Label Label
int Rand(struct RandomState *state)
Definition: kaldi-math.cc:45
fst::StdArc::Weight Weight
#define KALDI_ASSERT(cond)
Definition: kaldi-error.h:185
int32 g_kaldi_verbose_level
This is set by util/parse-options.
Definition: kaldi-error.cc:46