31 vector<vector<StdArc::Label> > *path,
32 vector<StdArc::Weight> *cost,
34 vector<StdArc::Label> cur_path,
37 if (proxy.Final(cur_state) != StdArc::Weight::Zero()) {
38 cur_cost =
Times(proxy.Final(cur_state), cur_cost);
39 path->push_back(cur_path);
40 cost->push_back(cur_cost);
44 for (ArcIterator<StdFst> aiter(proxy, cur_state);
45 !aiter.Done(); aiter.Next()) {
46 const StdArc &arc = aiter.Value();
48 cur_path.push_back(arc.ilabel);
50 arc.nextstate, cur_path, temp_cost);
58 int main(
int argc,
char *argv[]) {
60 using namespace kaldi;
63 typedef kaldi::uint64 uint64;
68 "Reads in the proxy keywords FSTs and print them to a file where each\n" 69 "line is \"kwid w1 w2 .. 2n\"\n" 72 " print-proxy-keywords [options] <proxy-rspecifier> " 73 " <kwlist-wspecifier> [<cost-wspecifier>]]\n" 75 " print-proxy-keywords ark:proxy.fsts ark,t:kwlist.txt" 87 std::string proxy_rspecifier = po.
GetArg(1),
88 kwlist_wspecifier = po.
GetArg(2),
98 for (; !proxy_reader.
Done(); proxy_reader.
Next()) {
99 std::string key = proxy_reader.
Key();
100 VectorFst<StdArc> proxy = proxy_reader.
Value();
103 if (proxy.Properties(kAcyclic,
true) == 0) {
104 KALDI_WARN <<
"Proxy FST has cycles, skip printing paths for " << key;
108 vector<vector<StdArc::Label> > paths;
109 vector<StdArc::Weight> costs;
111 vector<StdArc::Label>(), StdArc::Weight::One());
113 for (int32
i = 0;
i < paths.size();
i++) {
114 vector<int32> kwlist;
116 cost.push_back(costs[
i].Value());
117 for (int32
j = 0;
j < paths[
i].size();
j++) {
118 kwlist.push_back(paths[
i][
j]);
120 kwlist_writer.
Write(key, kwlist);
121 if (cost_wspecifier !=
"")
122 cost_writer.
Write(key, cost);
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();
fst::StdArc::StateId StateId
This code computes Goodness of Pronunciation (GOP) and extracts phone-level pronunciation feature for...
For an extended explanation of the framework of which grammar-fsts are a part, please see Support for...
void PrintUsage(bool print_command_line=false)
Prints the usage documentation [provided in the constructor].
A templated class for writing objects to an archive or script file; see The Table concept...
void Write(const std::string &key, const T &value) const
LatticeWeightTpl< FloatType > Times(const LatticeWeightTpl< FloatType > &w1, const LatticeWeightTpl< FloatType > &w2)
The class ParseOptions is for parsing command-line options; see Parsing command-line options for more...
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...
int Read(int argc, const char *const *argv)
Parses the command line options and fills the ParseOptions-registered variables.
std::string GetArg(int param) const
Returns one of the positional parameters; 1-based indexing for argc/argv compatibility.
fst::StdArc::Weight Weight
int main(int argc, char *argv[])
int NumArgs() const
Number of positional parameters (c.f. argc-1).
#define KALDI_ASSERT(cond)
std::string GetOptArg(int param) const