23 void MakeEvent(std::string &qry, fst::SymbolTable *phone_syms,
26 using namespace kaldi;
29 size_t found, old_found = 0;
31 while ((found = qry.find(
'/', old_found)) != std::string::npos) {
32 std::string valstr = qry.substr(old_found, found - old_found);
37 KALDI_ERR <<
"Bad query: invalid pdf-class (" << valstr <<
')';
41 value =
static_cast<EventValueType>(phone_syms->Find(valstr.c_str()));
43 KALDI_ERR <<
"Bad query: invalid symbol (" << valstr <<
')';
46 query_event->push_back(std::make_pair(key++, value));
47 old_found = found + 1;
49 std::string valstr = qry.substr(old_found);
53 KALDI_ERR <<
"Bad query: invalid symbol (" << valstr <<
')';
55 query_event->push_back(std::make_pair(key, value));
60 int main(
int argc,
char **argv) {
61 using namespace kaldi;
64 bool use_tooltips =
false;
65 bool gen_html =
false;
68 "Outputs a decision tree description in GraphViz format\n" 69 "Usage: draw-tree [options] <phone-symbols> <tree>\n" 70 "e.g.: draw-tree phones.txt tree | dot -Gsize=8,10.5 -Tps | ps2pdf - tree.pdf\n";
74 "a query to trace through the tree" 75 "(format: pdf-class/ctx-phone1/.../ctx-phoneN)");
76 po.
Register(
"use-tooltips", &use_tooltips,
"use tooltips instead of labels");
77 po.
Register(
"gen-html", &gen_html,
"generates HTML boilerplate(useful with SVG)");
80 std::cout <<
"<html>\n<head><title>Decision Tree</tree></head>\n" 81 <<
"<body><object data=\"tree.svg\" type=\"image/svg+xml\"/>" 82 <<
"</body>\n</html>\n";
89 std::string phnfile = po.
GetArg(1);
90 std::string treefile = po.
GetArg(2);
92 fst::SymbolTable *phones_symtab = NULL;
94 std::ifstream is(phnfile.c_str());
95 phones_symtab = ::fst::SymbolTable::ReadText(is, phnfile);
97 KALDI_ERR <<
"Could not read phones symbol table file "<< phnfile;
107 Input ki(treefile, &binary);
109 *phones_symtab, use_tooltips);
115 }
catch (
const std::exception &e) {
116 std::cerr << e.what();
This code computes Goodness of Pronunciation (GOP) and extracts phone-level pronunciation feature for...
void PrintUsage(bool print_command_line=false)
Prints the usage documentation [provided in the constructor].
void Register(const std::string &name, bool *ptr, const std::string &doc)
static const EventKeyType kPdfClass
int main(int argc, char **argv)
std::vector< std::pair< EventKeyType, EventValueType > > EventType
The class ParseOptions is for parsing command-line options; see Parsing command-line options for more...
void MakeEvent(std::string &qry, fst::SymbolTable *phone_syms, kaldi::EventType **query)
int32 EventKeyType
Things of type EventKeyType can take any value.
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.
int NumArgs() const
Number of positional parameters (c.f. argc-1).
int32 EventValueType
Given current code, things of type EventValueType should generally be nonnegative and in a reasonably...
void Render(const EventType *query)