epsilon-property-test.cc
Go to the documentation of this file.
1 // fstext/epsilon-property-test.cc
2 
3 // Copyright 2014 Johns Hopkins University (Author: Daniel Povey)
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/rand-fst.h"
23 
24 
25 namespace fst {
26 
28 
29  for (int32 i = 0; i < 10; i++) {
30  RandFstOptions opts;
31  opts.acyclic = true;
32  VectorFst<LogArc> *fst = RandFst<LogArc>(opts);
33  VectorFst<LogArc> fst2(*fst); // copy it...
34  EnsureEpsilonProperty(&fst2);
35 
36  std::vector<char> info;
37  ComputeStateInfo(fst2, &info);
38  for (size_t i = 0; i < info.size(); i++) {
39  char c = info[i];
40  assert(!((c & kStateHasEpsilonArcsEntering) != 0 &&
42  assert(!((c & kStateHasEpsilonArcsLeaving) != 0 &&
43  (c & kStateHasNonEpsilonArcsLeaving) != 0));
44  }
45  assert(RandEquivalent(fst2, *fst, 5, 0.01, kaldi::Rand(), 10));
46  delete fst;
47  }
48 }
49 
50 } // end namespace fst
51 
52 int main() {
53  using namespace fst;
54  for (int i = 0; i < 2; i++) {
56  }
57  std::cout << "Test OK\n";
58 }
void EnsureEpsilonProperty(VectorFst< Arc > *fst)
This function modifies the fst (while maintaining equivalence) in such a way that, after the modification, all states of the FST which have epsilon-arcs entering them, have no non-epsilon arcs entering them, and all states which have epsilon-arcs leaving them, have no non-epsilon arcs leaving them.
For an extended explanation of the framework of which grammar-fsts are a part, please see Support for...
Definition: graph.dox:21
kaldi::int32 int32
void TestEnsureEpsilonProperty()
void ComputeStateInfo(const VectorFst< Arc > &fst, std::vector< char > *epsilon_info)
This function will set epsilon_info to have size equal to the NumStates() of the FST, containing a logical-or of the enum values kStateHasEpsilonArcsEntering, kStateHasNonEpsilonArcsEntering, kStateHasEpsilonArcsLeaving, and kStateHasNonEpsilonArcsLeaving.
int main()
int Rand(struct RandomState *state)
Definition: kaldi-math.cc:45