📄 slev_08.cc
字号:
// file: $isip/class/search/SearchLevel/slev_08.cc// version: $Id: slev_08.cc,v 1.12 2003/01/22 23:18:28 huang Exp $//// isip include files//#include "SearchLevel.h"// method: loadNSymbolModel//// arguments:// Sof& sof: (input) sof file object// long tag: (input) sof object instance tag//// return: a boolean value indicating status//// this method reads context mapping information from an Sof file//boolean SearchLevel::loadNSymbolModel(Sof& sof_a, long tag_a) { // if no tag is specified, the tag should be this level number // if (tag_a == DEF_TAG) { tag_a = (long)level_index_d; } // make sure the symbol table has been loaded // long num_symbols = symbol_table_d.length(); if (num_symbols < 1) { return Error::handle(name(), L"loadContextMapping", Error::ARG, __FILE__, __LINE__); } // setup the symbol table // Vector<String> symbol_table(num_symbols); for (long i=0; i < num_symbols; i++) { symbol_table(i).assign(symbol_table_d(i)); } // set the language model order // nsymbol_model_d.setOrder(nsymbol_order_d); // load the nsymbol model // if (!nsymbol_model_d.load(sof_a, tag_a, symbol_table)) { return Error::handle(name(), L"loadNSymbolModel", Error::ARG, __FILE__, __LINE__); } // exit gracefully // return true;}// method: storeContextMapping//// arguments:// Sof& sof: (input) sof file object// long tag: (input) sof object instance tag//// return: a boolean value indicating status//// this method reads context mapping information from an Sof file//boolean SearchLevel::storeContextMapping(Sof& sof_a, long tag_a) { // if no tag is specified, the tag should be this level number // if (tag_a == DEF_TAG) { tag_a = (long)level_index_d; } // write the context map at this level // context_map_d.write(sof_a, tag_a, PARAM_CONTEXT_MAPPING); // gracefully exit // return true; }// method: loadContextMapping//// arguments:// Sof& sof: (input) sof file object// long tag: (input) sof object instance tag//// return: a boolean value indicating status//// this method reads context mapping information from an Sof file//boolean SearchLevel::loadContextMapping(Sof& sof_a, long tag_a) { // if no tag is specified, the tag should be this level number // if (tag_a == DEF_TAG) { tag_a = (long)level_index_d; } // make sure the symbol table has been loaded // long num_symbols = symbol_table_d.length(); if (num_symbols < 1) { return Error::handle(name(), L"loadContextMapping", Error::ARG, __FILE__, __LINE__); } // read the context map at this level // context_map_d.read(sof_a, tag_a, PARAM_CONTEXT_MAPPING); // when there is a context mapping table at this level // if (context_map_d.length() > 0) { // add start and terminal search symbol to the symbol table // symbol_table_d.concat(SearchSymbol::NO_LEFT_CONTEXT); symbol_table_d.concat(SearchSymbol::NO_RIGHT_CONTEXT); // set up start and terminal search node for each subgraph // for (long i = 0; i < sub_graphs_d.length(); i++) { // start vertex // SearchNode* snode_p = new SearchNode(); snode_p->setSearchLevel(this); snode_p->setSymbol(SearchSymbol::NO_LEFT_CONTEXT); sub_graphs_d(i).getStart()->setItem(snode_p); // terminal vertex // snode_p = new SearchNode(); snode_p->setSearchLevel(this); snode_p->setSymbol(SearchSymbol::NO_RIGHT_CONTEXT); sub_graphs_d(i).getTerm()->setItem(snode_p); } // insert all context pairs into the context mapping hash table // long total_context_length = left_context_d + right_context_d + 1; // check the context length // if ( context_map_d.length() > 0 ){ if (context_map_d(0).getContext().length() != total_context_length) { total_context_length = context_map_d(0).getContext().length(); String msg(L"Warning: left_context_d + right_context_d + 1 != total context length\n check the setting for right/left context length and the length of context mapping"); Console::put(msg); context_map_d(0).getContext().debug(L"a invalid context"); } } Context context(total_context_length); // loop over all context pairs // for (long i = 0; i < context_map_d.length(); i++) { // loop over the symbols in the context // for (long j = 0; j < total_context_length; j++) { SearchSymbol ss(context_map_d(i).getContext()(j)); long symbol_id = getSymbolIndex(ss); // check whether the symbol is valid // if (symbol_id == -1) { ss.debug(L"symbol"); return Error::handle(name(), L"loadContextMapping", Error::ARG, __FILE__, __LINE__); } else { context.assignAndAdvance(symbol_id); } } // insert a context specification into the hash table // Ulong index = context_map_d(i).getContextIndex(); // check if the context is already in the table // Ulong* existing_index = context_hash_d.get(context); // if this context is not in the table yet, insert it // if (existing_index == NULL) { context_hash_d.insert(context, &index); } // if the context is already in the table, then check whether // the index of the model is the same as the one from table // else { // if indices are different, explain conflict and return error // if (!existing_index->eq(index)) { context.debug(L"Context:"); String out; out.concat(L" is already in context mapping table with the index: "); out.concat(*existing_index); out.concat(L"\n while new index is: "); out.concat(index); Console::put(out); return Error::handle(name(), L"loadContextMapping", Error::ARG, __FILE__, __LINE__); } // otherwise indices are not conflicting, just print a warning // else { context.debug(L"Warning: This context is already in the table:"); } } } // output the debugging information // if (debug_level_d >= Integral::ALL) { context_hash_d.debug(L"context hash table:"); } } // when there is NO context mapping table at this level // else { // symbols will be mapped to the model with the same index at lower level // Context dummy(1); for (Ulong i = 0; i < (ulong)num_symbols; i++) { dummy.assignAndAdvance(i); context_hash_d.insert(dummy, &i); } if (debug_level_d >= Integral::ALL) { context_hash_d.debug(L"dummy context hash table:"); } } // exit gracefully // return true;}// method: getSubGraphIndex//// arguments:// const Context& context: (input) context containing symbol indices//// return: pointer to an index of the model of the input context//Ulong* SearchLevel::getSubGraphIndex(const Context& context_a) { return context_hash_d.get(context_a);}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -