游雁
2024-02-19 94de39dde2e616a01683c518023d0fab72b4e103
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
// fstext/prune-special-test.cc
 
// Copyright 2014  Guoguo Chen
 
// See ../../COPYING for clarification regarding multiple authors
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//  http://www.apache.org/licenses/LICENSE-2.0
//
// THIS CODE IS PROVIDED *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
// KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY IMPLIED
// WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE,
// MERCHANTABLITY OR NON-INFRINGEMENT.
// See the Apache 2 License for the specific language governing permissions and
// limitations under the License.
 
 
#include "fstext/prune-special.h"
#include "fstext/rand-fst.h"
#include "fstext/fstext-utils.h"
 
namespace fst {
 
static void TestPruneSpecial() {
  typedef StdArc Arc;
  typedef Arc::Label Label;
  typedef Arc::StateId StateId;
  typedef Arc::Weight Weight;
 
  RandFstOptions opts;
  opts.acyclic = false;
  VectorFst<Arc> *ifst = RandFst<StdArc>(opts);
 
  float beam = 0.55;
 
  {
    FstPrinter<Arc> fstprinter(*ifst, NULL, NULL, NULL, false, true, "\t");
    fstprinter.Print(&std::cout, "standard output");
    std::cout << std::endl;
  }
 
  // Do the special pruning.
  VectorFst<Arc> ofst1;
  PruneSpecial<StdArc>(*ifst, &ofst1, beam);
  {
    FstPrinter<Arc> fstprinter(ofst1, NULL, NULL, NULL, false, true, "\t");
    fstprinter.Print(&std::cout, "standard output");
    std::cout << std::endl;
  }
 
  // Do the normal pruning.
  VectorFst<Arc> ofst2;
  Prune(*ifst, &ofst2, beam);
  {
    FstPrinter<Arc> fstprinter(ofst2, NULL, NULL, NULL, false, true, "\t");
    fstprinter.Print(&std::cout, "standard output");
    std::cout << std::endl;
  }
 
  KALDI_ASSERT(RandEquivalent(ofst1, ofst2,
                              5/*paths*/, 0.01/*delta*/, kaldi::Rand()/*seed*/,
                              100/*path length-- max?*/));
 
  delete ifst;
}
 
 
} // namespace fst
 
int main() {
  kaldi::g_kaldi_verbose_level = 4;
  using namespace fst;
  for (int i = 0; i < 25; i++) {
    TestPruneSpecial();
  }
}