📄 lm_03.cc
字号:
// file: $isip/class/asr/LanguageModel/lm_03.cc// version: $Id: lm_03.cc,v 1.10 2002/09/25 20:26:41 huang Exp $//// isip include files//#include "LanguageModel.h"#include <Console.h>// method: read//// arguments:// Sof& sof: (input) sof file object// long tag: (input) sof object instance tag// const String& name: (input) sof object instance name// boolean use_context_a: (input) read contextsof object instance name//// return: a boolean value indicating status//// this method has the object read itself from an Sof file according// to the specified name and tag//boolean LanguageModel::read(Sof& sof_a, const String& tag_a, SearchLevel& level_a, boolean use_context_a, Vector<SearchSymbol>* symbol_table_a) { // symbol list for the given search level // Vector<SearchSymbol> symbol_list; Vector<SearchSymbol> nonspeech_symbol_list; Vector<DiGraph<String> > graph_list; Vector<String> graph_name_list; // declare variables for reading the sof file // String algo_line; String head_line; // check the level tag of the object from the Sof file // long level_index = level_a.getLevelIndex(); if(!sof_a.find(tag_a, level_index)) { return Error::handle(tag_a, L"no matching tag", Error::TEST, __FILE__, __LINE__); } // get the size of the data for this level // // long level_size = sof_a.getObjectSize(tag_a, level_index); // read the first algorithm name // sof_a.gets(algo_line, Sof::BUFFER_SIZE); // check the alogotithm name // if(algo_line.eq(L"algorithm = \"JSGF\";", true)) { // take off the grammar head line "grammar = {" and // move the sof pointer to the beginning line of grammar // sof_a.gets(head_line, Sof::BUFFER_SIZE); while(!head_line.eq(L"", true)) { // declare variables // Vector<SearchSymbol> sub_symbol_list; Vector<String> nonspeech_list; Vector<String> tmp_symbol_list; DiGraph<String> sub_graph; String graph_name; // read the actual data from the sof file // readJSGF(sof_a, nonspeech_list, tmp_symbol_list, sub_graph, graph_name); // convert the non-speech list of Strings to // the non-speech symbol list of SearchSymbols // if (nonspeech_list.length() > 0) { for (long i = 0; i < nonspeech_list.length(); i++) { SearchSymbol tmp; tmp.assign(nonspeech_list(i)); nonspeech_symbol_list.concat(tmp); } } // convert the symbol list of Strings to // the sub symbol list of SearchSymbols // for (long i = 0; i < tmp_symbol_list.length(); i++) { SearchSymbol tmp; tmp.assign(tmp_symbol_list(i)); sub_symbol_list.concat(tmp); } // check if any symobl in sub_symbol_list already exists in symbol_list // boolean same = false; for(long i=0; i<sub_symbol_list.length(); i++) { for(long j=0; j<symbol_list.length(); j++) { if(sub_symbol_list(i).eq(symbol_list(j))) { same = true; break; } } if (!same){ // add the sub symbol list // symbol_list.concat(sub_symbol_list(i)); } same = false; } // add the sub-graph to the graph list if the graph is not empty // if (!graph_name.eq(L"")) { graph_list.concat(sub_graph); } // add the graph name to the graph name list if the graph is not empty // if (!graph_name.eq(L"")) { graph_name_list.concat(graph_name); } // read next JSGF object head and pass over the blank line // sof_a.gets(head_line, Sof::BUFFER_SIZE); String previous; previous = head_line; sof_a.gets(head_line, Sof::BUFFER_SIZE); // when the end of the data of this level is reached // if(head_line.eq(previous, true) || head_line.eq(L"algorithm = \"JSGF\";", true)) { break; } } // end of while loop } // end: if(algo_line.eq(L"algorithm = \"JSGF\";", true)) // if no alogorithm matches // else { return Error::handle(algo_line, L"no matching algorithm", Error::TEST, __FILE__, __LINE__); } // add the symbol list to the given search level // level_a.setSymbolTable(symbol_list); // add the nonspeech symbol list to the given search level // level_a.setNonSpeechSymbolTable(nonspeech_symbol_list); // also set a copy of symbol list to the protected search level // in case the level_a is from input instead of class protected data // //search_levels_d(level_index).setSymbolTable(symbol_list); // get the number of graphs in this level // long num_graphs = graph_list.length(); // call private method to re-orgnize the vector graph_list // to match the order of the symbols in the upper search level // if(level_index > 0) { // get the symbol table of the upper level // Vector<SearchSymbol>& symbol_table = *symbol_table_a; Vector<SearchSymbol> graph_symbols; // do we have context mapping ? // if ( use_context_a ){ // set the symbol table // for (long j = 0; j < num_graphs; j++) { String symbol; Ulong index; index.assign(j); symbol.assign(L"G_"); symbol.concat(index); graph_symbols.concat(symbol); } } // test the symbol_table // if ( symbol_table_a == NULL && !use_context_a ){ return Error::handle(tag_a, L"no symbol table of upper level", Error::TEST, __FILE__, __LINE__); } // align the graphs in the graph list // if ( use_context_a ){ alignGraphs(graph_list, graph_symbols, graph_name_list); } else { alignGraphs(graph_list, symbol_table, graph_name_list); } } // declare a vector of SearchNode graphs // Vector< DiGraph<SearchNode> > node_graphs(num_graphs); // number of symbols in the symbol table on this level // long num_symbols = symbol_list.length(); for(long i=0; i<num_graphs; i++) { // convert each graph from SearchSymbol type to SearchNode type // convertGraph(graph_list(i), node_graphs(i), num_symbols, level_a); } // add the converted node graph list to the given search level // level_a.setNumSubGraphs(num_graphs); for(long i=0; i<num_graphs; i++) { level_a.setSubGraph(i, node_graphs(i)); } // gracefully exit // return true;}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -