print-proxy-keywords.cc File Reference
Include dependency graph for print-proxy-keywords.cc:

Go to the source code of this file.

Namespaces

 fst
 For an extended explanation of the framework of which grammar-fsts are a part, please see Support for grammars and graphs with on-the-fly parts. (i.e.
 

Functions

bool PrintProxyFstPath (const VectorFst< StdArc > &proxy, vector< vector< StdArc::Label > > *path, vector< StdArc::Weight > *weight, StdArc::StateId cur_state, vector< StdArc::Label > cur_path, StdArc::Weight cur_weight)
 
int main (int argc, char *argv[])
 

Function Documentation

◆ main()

int main ( int  argc,
char *  argv[] 
)

Definition at line 58 of file print-proxy-keywords.cc.

References SequentialTableReader< Holder >::Done(), SequentialTableReader< Holder >::FreeCurrent(), ParseOptions::GetArg(), ParseOptions::GetOptArg(), rnnlm::i, rnnlm::j, KALDI_ASSERT, KALDI_LOG, KALDI_WARN, SequentialTableReader< Holder >::Key(), SequentialTableReader< Holder >::Next(), ParseOptions::NumArgs(), fst::PrintProxyFstPath(), ParseOptions::PrintUsage(), ParseOptions::Read(), SequentialTableReader< Holder >::Value(), and TableWriter< Holder >::Write().

58  {
59  try {
60  using namespace kaldi;
61  using namespace fst;
62  typedef kaldi::int32 int32;
63  typedef kaldi::uint64 uint64;
64  typedef StdArc::StateId StateId;
65  typedef StdArc::Weight Weight;
66 
67  const char *usage =
68  "Reads in the proxy keywords FSTs and print them to a file where each\n"
69  "line is \"kwid w1 w2 .. 2n\"\n"
70  "\n"
71  "Usage: \n"
72  " print-proxy-keywords [options] <proxy-rspecifier> "
73  " <kwlist-wspecifier> [<cost-wspecifier>]]\n"
74  "e.g.:\n"
75  " print-proxy-keywords ark:proxy.fsts ark,t:kwlist.txt"
76  " ark,t:costs.txt\n";
77 
78  ParseOptions po(usage);
79 
80  po.Read(argc, argv);
81 
82  if (po.NumArgs() < 2 || po.NumArgs() > 3) {
83  po.PrintUsage();
84  exit(1);
85  }
86 
87  std::string proxy_rspecifier = po.GetArg(1),
88  kwlist_wspecifier = po.GetArg(2),
89  cost_wspecifier = po.GetOptArg(3);
90 
91 
92  SequentialTableReader<VectorFstHolder> proxy_reader(proxy_rspecifier);
93  TableWriter<BasicVectorHolder<int32> > kwlist_writer(kwlist_wspecifier);
94  TableWriter<BasicVectorHolder<double> > cost_writer(cost_wspecifier);
95 
96  // Start processing the keywords
97  int32 n_done = 0;
98  for (; !proxy_reader.Done(); proxy_reader.Next()) {
99  std::string key = proxy_reader.Key();
100  VectorFst<StdArc> proxy = proxy_reader.Value();
101  proxy_reader.FreeCurrent();
102 
103  if (proxy.Properties(kAcyclic, true) == 0) {
104  KALDI_WARN << "Proxy FST has cycles, skip printing paths for " << key;
105  continue;
106  }
107 
108  vector<vector<StdArc::Label> > paths;
109  vector<StdArc::Weight> costs;
110  PrintProxyFstPath(proxy, &paths, &costs, proxy.Start(),
111  vector<StdArc::Label>(), StdArc::Weight::One());
112  KALDI_ASSERT(paths.size() == costs.size());
113  for (int32 i = 0; i < paths.size(); i++) {
114  vector<int32> kwlist;
115  vector<double> cost;
116  cost.push_back(costs[i].Value());
117  for (int32 j = 0; j < paths[i].size(); j++) {
118  kwlist.push_back(paths[i][j]);
119  }
120  kwlist_writer.Write(key, kwlist);
121  if (cost_wspecifier != "")
122  cost_writer.Write(key, cost);
123  }
124  n_done++;
125  }
126 
127  KALDI_LOG << "Done " << n_done << " keywords";
128  return (n_done != 0 ? 0 : 1);
129  } catch(const std::exception &e) {
130  std::cerr << e.what();
131  return -1;
132  }
133 }
fst::StdArc::StateId StateId
This code computes Goodness of Pronunciation (GOP) and extracts phone-level pronunciation feature for...
Definition: chain.dox:20
Lattice::StateId StateId
For an extended explanation of the framework of which grammar-fsts are a part, please see Support for...
Definition: graph.dox:21
A templated class for writing objects to an archive or script file; see The Table concept...
Definition: kaldi-table.h:368
kaldi::int32 int32
The class ParseOptions is for parsing command-line options; see Parsing command-line options for more...
Definition: parse-options.h:36
bool PrintProxyFstPath(const VectorFst< StdArc > &proxy, vector< vector< StdArc::Label > > *path, vector< StdArc::Weight > *weight, StdArc::StateId cur_state, vector< StdArc::Label > cur_path, StdArc::Weight cur_weight)
A templated class for reading objects sequentially from an archive or script file; see The Table conc...
Definition: kaldi-table.h:287
#define KALDI_WARN
Definition: kaldi-error.h:150
fst::StdArc::Weight Weight
Arc::Weight Weight
Definition: kws-search.cc:31
#define KALDI_ASSERT(cond)
Definition: kaldi-error.h:185
#define KALDI_LOG
Definition: kaldi-error.h:153