📄 lm_02.cc
字号:
// file: $isip/class/asr/LanguageModel/lm_02.cc// version: $Id: lm_02.cc,v 1.8 2002/12/12 17:26:11 huang Exp $//// isip include files//#include "LanguageModel.h"// method: diagnose//// arguments:// Integral::DEBUG level: (input) debug level for diagnostics//// return: a boolean value indicating status//boolean LanguageModel::diagnose(Integral::DEBUG level_a) { //--------------------------------------------------------------------------- // // 0. preliminaries // //--------------------------------------------------------------------------- // output the class name // if (level_a > Integral::NONE) { SysString output(L"diagnosing class "); output.concat(CLASS_NAME); output.concat(L": "); Console::put(output); Console::increaseIndention(); } //-------------------------------------------------------------------------- // // 1. required public methods // //-------------------------------------------------------------------------- // set indentation // if (level_a > Integral::NONE) { Console::put(L"testing required public methods: class constructors...\n"); Console::increaseIndention(); } // test destructor/constructor(s) and memory management // LanguageModel lm0; LanguageModel lm1(lm0); if (!lm1.eq(lm0)) { return Error::handle(name(), L"copy constructor/eq", Error::TEST, __FILE__, __LINE__); } // test large allocation construction and deletion // if (level_a == Integral::ALL) { Console::put(L"\ntesting large chunk memory allocation and deletion:\n"); // set the memory to a strange block size so we can hopefully catch any // frame overrun errors // LanguageModel::setGrowSize((long)500); LanguageModel* plm = new LanguageModel(); for (long j = 1; j <= 100; j++) { LanguageModel** plms = new LanguageModel*[j * 100]; // create the objects // for (long i = 0; i < j * 100; i++) { plms[i] = new LanguageModel(); } // delete objects // for (long i = (j * 100) - 1; i >= 0; i--) { delete plms[i]; } delete [] plms; } delete plm; } // reset indentation // if (level_a > Integral::NONE) { Console::decreaseIndention(); } //--------------------------------------------------------------------- // // 2. class-specified public methods // //--------------------------------------------------------------------- // reset indentation // if (level_a > Integral::NONE) { Console::put(L"testing class-specific public methods...\n"); Console::increaseIndention(); } // test load method // long num_level = 3; Vector<SearchLevel> level1(num_level); LanguageModel lmodel1; // load the JSGF format input models // if (!lmodel1.load(L"diagnose_input_model.sof", L"diagnose_input_stat.sof", level1)) { return Error::handle(name(), L"load NATIVE input model files", Error::TEST, __FILE__, __LINE__); } // write the models into file in JSGF format // String mod1; Integral::makeTemp(mod1); String st1; Integral::makeTemp(st1); lmodel1.store(mod1, st1, level1, LanguageModel::JSGF); lmodel1.store(L"lm1.sof", L"sm1.sof", level1, LanguageModel::JSGF); // load in the same models in DiGraph format, which is the output of // the above step // Vector<SearchLevel> level2(num_level); LanguageModel lmodel2; if (!lmodel2.load(mod1, st1, level2)) { return Error::handle(name(), L"load DiGraph format model files", Error::TEST, __FILE__, __LINE__); } else if (!level2(0).eq(level1(0))) { return Error::handle(name(), L"loaded language model (level0) is not correct", Error::TEST, __FILE__, __LINE__); } else if (!level2(1).eq(level1(1))) { return Error::handle(name(), L"loaded language model (level1) is not correct", Error::TEST, __FILE__, __LINE__); } else if (!level2(2).eq(level1(2))) { return Error::handle(name(), L"loaded language model (level2) is not correct", Error::TEST, __FILE__, __LINE__); } // write the models into file in JSGF format // String mod2; Integral::makeTemp(mod2); String st2; Integral::makeTemp(st2); lmodel2.store(mod2, st2, level2, LanguageModel::NATIVE); //--------------------------------------------------------------------------- // // 3. print completion message // //--------------------------------------------------------------------------- // reset indentation // if (level_a > Integral::NONE) { Console::decreaseIndention(); } // possibly print completion message // if (level_a > Integral::NONE) { String output(L"diagnostics completed successfully for class "); output.concat(name()); output.concat(L"\n"); Console::put(output); } // exit gracefully // return true;}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -