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

◆ main()

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

Definition at line 55 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().

55  {
56  try {
57  using namespace kaldi;
58  using namespace fst;
59  typedef fst::StdArc::Label Label;
60  const char *usage = "Create input symbols for CLG\n"
61  "Usage: fstmakecontextsyms phones-symtab ilabels_input_file [output-symtab.txt]\n"
62  "E.g.: fstmakecontextsyms phones.txt ilabels.sym > context_symbols.txt\n";
63 
64  ParseOptions po(usage);
65 
66  std::string disambig_list_file = "",
67  phone_separator = "/",
68  initial_disambig = "#-1";
69 
70  po.Register("phone-separator", &phone_separator,
71  "Separator for phones in phone-in-context symbols.");
72  po.Register("initial-disambig", &initial_disambig,
73  "Name for special disambiguation symbol that occurs at start "
74  "of context-dependent phone sequences");
75 
76  po.Read(argc, argv);
77 
78  if (po.NumArgs() < 2 || po.NumArgs() > 3) {
79  po.PrintUsage();
80  exit(1);
81  }
82 
83  std::string phones_symtab_filename = po.GetArg(1),
84  ilabel_info_filename = po.GetArg(2),
85  clg_symtab_filename = po.GetOptArg(3);
86 
87  std::vector<std::vector<kaldi::int32> > ilabel_info;
88  {
89  bool binary;
90  Input ki(ilabel_info_filename, &binary);
91  ReadILabelInfo(ki.Stream(),
92  binary, &ilabel_info);
93  }
94 
95  fst::SymbolTable *phones_symtab = NULL;
96  { // read phone symbol table.
97  std::ifstream is(phones_symtab_filename.c_str());
98  phones_symtab = fst::SymbolTable::ReadText(is, phones_symtab_filename);
99  if (!phones_symtab) KALDI_ERR << "Could not read phones symbol-table file "<<phones_symtab_filename;
100  }
101 
102  fst::SymbolTable *clg_symtab =
103  CreateILabelInfoSymbolTable(ilabel_info,
104  *phones_symtab,
105  phone_separator,
106  initial_disambig);
107 
108  if (clg_symtab_filename == "") {
109  if (!clg_symtab->WriteText(std::cout))
110  KALDI_ERR << "Cannot write symbol table to standard output.";
111  } else {
112  if (!clg_symtab->WriteText(clg_symtab_filename))
113  KALDI_ERR << "Cannot open symbol table file "<<clg_symtab_filename<<" for writing.";
114  }
115  delete clg_symtab;
116  delete phones_symtab;
117  return 0;
118  } catch(const std::exception &e) {
119  std::cerr << e.what();
120  return -1;
121  }
122 }
fst::StdArc::Label Label
This code computes Goodness of Pronunciation (GOP) and extracts phone-level pronunciation feature for...
Definition: chain.dox:20
For an extended explanation of the framework of which grammar-fsts are a part, please see Support for...
Definition: graph.dox:21
void ReadILabelInfo(std::istream &is, bool binary, vector< vector< int32 > > *info)
Utility function for reading ilabel-info vectors from disk.
Definition: context-fst.cc:335
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:147
fst::StdArc::Label Label
SymbolTable * CreateILabelInfoSymbolTable(const vector< vector< int32 > > &info, const SymbolTable &phones_symtab, std::string separator, std::string initial_disambig)
The following function is mainly of use for printing and debugging.
Definition: context-fst.cc:345