From 50c2f24d3f8ef32426b7ef83f1bd896dba33da7e Mon Sep 17 00:00:00 2001 From: Max Hawkins Date: Fri, 27 Nov 2015 00:15:05 +0100 Subject: [PATCH] simplify mkgraph api --- gentle/language_model.py | 8 +++----- mkgraph.cc | 25 ++++++++++++------------- 2 files changed, 15 insertions(+), 18 deletions(-) diff --git a/gentle/language_model.py b/gentle/language_model.py index f393abb9..8ea29bf0 100644 --- a/gentle/language_model.py +++ b/gentle/language_model.py @@ -68,11 +68,9 @@ def make_bigram_language_model(kaldi_seq, proto_langdir='PROTO_LANGDIR'): hclg_filename = tempfile.mktemp(suffix='_HCLG.fst') try: subprocess.check_output([MKGRAPH_PATH, - os.path.join(proto_langdir, 'langdir'), - os.path.join(proto_langdir, 'modeldir'), - txt_fst_file.name, - os.path.join(proto_langdir, "graphdir/words.txt"), - hclg_filename]) + proto_langdir, + txt_fst_file.name, + hclg_filename]) except Exception, e: os.unlink(hclg_filename) raise e diff --git a/mkgraph.cc b/mkgraph.cc index 413c894c..1b877186 100644 --- a/mkgraph.cc +++ b/mkgraph.cc @@ -13,11 +13,11 @@ int main(int argc, char *argv[]) { using namespace fst; using fst::script::ArcSort; try { - const char *usage = "Usage: ./mkgraph [options] \n"; + const char *usage = "Usage: ./mkgraph [options] \n"; ParseOptions po(usage); po.Read(argc, argv); - if (po.NumArgs() != 5) { + if (po.NumArgs() != 3) { po.PrintUsage(); return 1; } @@ -27,17 +27,16 @@ int main(int argc, char *argv[]) { float self_loop_scale = 0.1; bool reverse = false; - std::string lang_dir = po.GetArg(1), - model_dir = po.GetArg(2), - grammar_fst_filename = po.GetArg(3), - words_filename = po.GetArg(4), - out_filename = po.GetArg(5); - - std::string lang_fst_filename = lang_dir + "/L.fst", - lang_disambig_fst_filename = lang_dir + "/L_disambig.fst", - disambig_phones_filename = lang_dir + "/phones/disambig.int", - model_filename = model_dir + "/final.mdl", - tree_filename = model_dir + "/tree"; + std::string proto_dir = po.GetArg(1), + grammar_fst_filename = po.GetArg(2), + out_filename = po.GetArg(3); + + std::string lang_fst_filename = proto_dir + "/langdir/L.fst", + lang_disambig_fst_filename = proto_dir + "/langdir/L_disambig.fst", + disambig_phones_filename = proto_dir + "/langdir/phones/disambig.int", + model_filename = proto_dir + "/modeldir/final.mdl", + tree_filename = proto_dir + "/modeldir/tree", + words_filename = proto_dir + "/graphdir/words.txt"; if (!std::ifstream(lang_fst_filename.c_str())) { std::cerr << "expected " << lang_fst_filename << " to exist" << std::endl;