📄 languagemodel.h
字号:
// file: $isip/class/asr/LanguageModel.h//// make sure definitions are only made once//#ifndef ISIP_LANGUAGE_MODEL#define ISIP_LANGUAGE_MODEL#ifndef ISIP_SOF#include <Sof.h>#endif#ifndef ISIP_DI_GRAPH#include <DiGraph.h>#endif#ifndef ISIP_VECTOR#include <Vector.h>#endif#ifndef ISIP_STRING#include <String.h>#endif#ifndef ISIP_SEARCH_LEVEL#include <SearchLevel.h>#endif#ifndef ISIP_JSGF_PARSER#include <JSGFParser.h>#endif// LanguageModel: a class that manages language model which includes// multiple search levels. This class can be used to load in an input// grammar file, such as JSGF grammar file, and then convert it to// ISIP internal DiGraph grammar format.//class LanguageModel { //------------------------------------------------------------- // // public constants // //-------------------------------------------------------------public: //define the class name // static const String CLASS_NAME; //-------------------------------------------------------------- // // other important constants // //-------------------------------------------------------------- static const long DEF_NUM_LEVEL; static const String DEF_GRAPH_START; static const String DEF_GRAPH_TERM; static const String PARAM_STAT; static const String PARAM_STAT_HASH; // define algorithm choices // enum ALGORITHM { JSGF_1_0 = 0, NGRAM_ARPA, DEF_ALGORITHM = JSGF_1_0 }; // define file format choices for output models // enum OUTPUT_FORMAT { NATIVE = 0, JSGF, DEF_OUTPUT_FORMAT = NATIVE }; // define output types // enum OUTPUT_TYPE { TEXT = 0, BINARY, DEF_OUTPUT_TYPE = BINARY }; // define static NameMap objects // static const NameMap ALGO_MAP; static const NameMap IMPL_MAP; static const NameMap NORM_MAP; //---------------------------------------- // // error codes // //---------------------------------------- static const long ERR = (long)90100; //------------------------------------------------------------- // // protected data // //-------------------------------------------------------------protected: // the number of search levels // long num_level_d; // search levels // Vector<SearchLevel> search_levels_d; // algorithm name // ALGORITHM algorithm_d; // starting and ending points for each ISIP Graph // String graph_start_d; String graph_term_d; // debug level // static Integral::DEBUG debug_level_d; // static memory manager // static MemoryManager mgr_d; //------------------------------------------------------------- // // required public methods // //-------------------------------------------------------------public: // method: name // static const String& name() { return CLASS_NAME; } // other static methods // static boolean diagnose(Integral::DEBUG debug_level); // debug methods: // boolean debug(const unichar* msg_a) const; // method: destructor // ~LanguageModel() {} // method: default constructor // LanguageModel(); // assign methods // boolean LanguageModel::assign(const LanguageModel& arg_a); // method: operator= // LanguageModel& operator= (const LanguageModel& arg_a) { assign(arg_a); return *this; } // i/o methods // // method: sofSize // long sofSize() const; // method: read // boolean read(Sof& sof_a, const String& tag_a, SearchLevel& level_a, boolean use_context_a = false, Vector<SearchSymbol>* symbol_table_a = NULL); // method: write // boolean write(Sof& sof_a, long tag_a, const String& name_a) const; // equality methods // boolean eq(const LanguageModel& arg_a) const; // method: new // static void* operator new(size_t size) { return mgr_d.get(); } // method: new[] // static void* operator new[](size_t size) { return mgr_d.getBlock(size); } // method: delete // static void operator delete(void* ptr) { mgr_d.release(ptr); } // method: delete[] // static void operator delete[](void* ptr) { mgr_d.releaseBlock(ptr); } // method: setGrowSize // static boolean setGrowSize(long grow_size) { return mgr_d.setGrow(grow_size); } // method: clear // boolean clear(Integral::CMODE ctype_a); //------------------------------------------------------------- // // class-specified public methods // //-------------------------------------------------------------public: // method: getNumLevels // return the number of levels, num_level_d // long getNumLevels() { return num_level_d; } // method: setNumLevels // boolean setNumLevels(const String& file_a); // method: getLevel // boolean getLevel(SearchLevel& search_level_a, long index_a); // method: getLevel // Vector<SearchLevel>& getLevels(){ return search_levels_d; }; // method: load // boolean load(const Vector<String>& files_a, const Vector<String>& tags_a); boolean load(const Vector<String>& files_a, const Vector<String>& tags_a, Vector<SearchLevel>& search_levels_a); // method: load // // basic load funtion called by other fuctions // boolean load(const String& model_file_a, const String& stat_file_a, const long level_index_a, Vector<SearchLevel>& search_levels_a); boolean load(const String& model_file_a, const String& stat_file_a); boolean load(const String& model_file_a, const String& stat_file_a, Vector<SearchLevel>& search_levels_a); boolean load(const String& model_file_a, Vector<SearchLevel>& search_levels_a){ String ac_file; return load (model_file_a, ac_file, search_levels_a); } boolean loadNonGrammars(Sof& model_file_a, Vector<SearchLevel>& search_levels_a, long level_index_a); // method: store // boolean store(const String& model_file_a, const String& stat_file_a, Vector<SearchLevel>& search_levels_a, OUTPUT_FORMAT format_a = DEF_OUTPUT_FORMAT, OUTPUT_TYPE type_a = DEF_OUTPUT_TYPE); // method: store // boolean store(const String& model_file_a, const String& stat_file_a, OUTPUT_FORMAT format_a = DEF_OUTPUT_FORMAT, OUTPUT_TYPE type_a = DEF_OUTPUT_TYPE) { return store(model_file_a, stat_file_a, search_levels_d, format_a, type_a); } boolean store(const String& model_file_a, Vector<SearchLevel>& search_levels_a, OUTPUT_FORMAT format_a = DEF_OUTPUT_FORMAT, OUTPUT_TYPE type_a = DEF_OUTPUT_TYPE); boolean storeNonGrammars(Sof& model_file_a, Vector<SearchLevel>& search_levels_a, long level_index_a); boolean writeOneRule(Sof& sof_a, long tag_a, const String& format_a, const String& name_a, Vector<String>& rules_a) const; boolean readOneRule(Sof& sof_a, long tag_a, const String& format_a, const String& name_a, Vector<String>& rule_list_a); //------------------------------------------------------------- // // private methods // //-------------------------------------------------------------private: // method: readJSGF // boolean readJSGF(Sof& sof_a, Vector<String>& nonspeech_symbol_list_a, Vector<String>& sub_symbol_list_a, DiGraph<String>& sub_graph_a, String& sub_graph_name_a); // method: convertGraph // boolean convertGraph(DiGraph<String>& symbol_graph_a, DiGraph<SearchNode>& node_graph_a, long& num_symbols_a, SearchLevel& level_a); // method: alignGraphs // boolean alignGraphs(Vector< DiGraph<String> >& graph_list_a, Vector<SearchSymbol>& symbol_table_a, Vector<String>& graph_name_list_a); // method: setGraphEndings // boolean setGraphEndings(Sof& sof_a); // method: isNonSpeechDefinition // boolean isNonSpeechDefinition(String& arg_a); // method: convertToJSGF // String convertToJSGF(DiGraph<SearchNode>& graph_a, SearchSymbol grammar_name_a); String digraphToJSGF(DiGraph<SearchNode>& graph_a, SearchSymbol grammar_name_a); // method: getSubgroup // boolean getSubgroup(SingleLinkedList<GraphArc<SearchNode> > subgroup_list_a, Vector<SingleLinkedList<GraphArc<SearchNode> > > & subgroup_table_a, GraphVertex<SearchNode>* verts_a[], long num_vertices_a); // method: loadContextMapping // boolean loadContextMapping(Sof& sof_a, const String& tag_a, SearchLevel& level_a, long level_index_a); // method: storeContextMapping // boolean storeContextMapping(Sof& sof_a, const String& tag_a, SearchLevel& level_a, long level_index_a);};// end of include file//#endif
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -