All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
fstmakecontextsyms.cc File Reference
#include "tree/context-dep.h"
#include "util/common-utils.h"
#include "fst/fstlib.h"
#include "fstext/fstext-utils.h"
#include "fstext/context-fst.h"
Include dependency graph for fstmakecontextsyms.cc:

Go to the source code of this file.

Functions

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

Function Documentation

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

Definition at line 50 of file fstmakecontextsyms.cc.

References fst::CreateILabelInfoSymbolTable(), ParseOptions::GetArg(), ParseOptions::GetOptArg(), KALDI_ERR, ParseOptions::NumArgs(), ParseOptions::PrintUsage(), ParseOptions::Read(), fst::ReadILabelInfo(), ParseOptions::Register(), and Input::Stream().

50  {
51  try {
52  using namespace kaldi;
53  using namespace fst;
54  typedef fst::StdArc::Label Label;
55  const char *usage = "Create input symbols for CLG\n"
56  "Usage: fstmakecontextsyms phones-symtab ilabels_input_file [output-symtab.txt]\n"
57  "E.g.: fstmakecontextsyms phones.txt ilabels.sym > context_symbols.txt\n";
58 
59  ParseOptions po(usage);
60 
61  std::string disambig_list_file = "",
62  phone_separator = "/",
63  initial_disambig = "#-1";
64 
65  po.Register("phone-separator", &phone_separator,
66  "Separator for phones in phone-in-context symbols.");
67  po.Register("initial-disambig", &initial_disambig,
68  "Name for special disambiguation symbol that occurs at start "
69  "of context-dependent phone sequences");
70 
71  po.Read(argc, argv);
72 
73  if (po.NumArgs() < 2 || po.NumArgs() > 3) {
74  po.PrintUsage();
75  exit(1);
76  }
77 
78  std::string phones_symtab_filename = po.GetArg(1),
79  ilabel_info_filename = po.GetArg(2),
80  clg_symtab_filename = po.GetOptArg(3);
81 
82  std::vector<std::vector<kaldi::int32> > ilabel_info;
83  {
84  bool binary;
85  Input ki(ilabel_info_filename, &binary);
86  ReadILabelInfo(ki.Stream(),
87  binary, &ilabel_info);
88  }
89 
90  fst::SymbolTable *phones_symtab = NULL;
91  { // read phone symbol table.
92  std::ifstream is(phones_symtab_filename.c_str());
93  phones_symtab = fst::SymbolTable::ReadText(is, phones_symtab_filename);
94  if (!phones_symtab) KALDI_ERR << "Could not read phones symbol-table file "<<phones_symtab_filename;
95  }
96 
97  fst::SymbolTable *clg_symtab =
98  CreateILabelInfoSymbolTable(ilabel_info,
99  *phones_symtab,
100  phone_separator,
101  initial_disambig);
102 
103  if (clg_symtab_filename == "") {
104  if (!clg_symtab->WriteText(std::cout))
105  KALDI_ERR << "Cannot write symbol table to standard output.";
106  } else {
107  if (!clg_symtab->WriteText(clg_symtab_filename))
108  KALDI_ERR << "Cannot open symbol table file "<<clg_symtab_filename<<" for writing.";
109  }
110  delete clg_symtab;
111  delete phones_symtab;
112  return 0;
113  } catch(const std::exception &e) {
114  std::cerr << e.what();
115  return -1;
116  }
117 }
Relabels neural network egs with the read pdf-id alignments.
Definition: chain.dox:20
Definition: graph.dox:21
The class ParseOptions is for parsing command-line options; see Parsing command-line options for more...
Definition: parse-options.h:36
#define KALDI_ERR
Definition: kaldi-error.h:127
fst::StdArc::Label Label
SymbolTable * CreateILabelInfoSymbolTable(const vector< vector< I > > &info, const SymbolTable &phones_symtab, std::string separator, std::string initial_disambig)
The following function is mainly of use for printing and debugging.
void ReadILabelInfo(std::istream &is, bool binary, vector< vector< I > > *info)
Useful utility function for reading these vectors from disk.