📄 slev_06.cc
字号:
long dest_index = -1; GraphArc<Ulong>* tmp_arc = tmp_start_vert->getCurr(); GraphVertex<Ulong>* dest_vertex = tmp_arc->getVertex(); boolean is_eps = tmp_arc->getEpsilon(); // find the index of the destination vertex // for (long j = 0; j < num_vertices; j++) { if (dest_vertex == tmp_vert[j]) { dest_index = j; break; } } if (dest_index == -1) { return Error::handle(name(), L"loadSubGraphs -- Vertex not in list of Vertices", SearchLevel::ERR, __FILE__, __LINE__); } // connect the vertices in the searchnode graph // sub_graphs_d(k).insertArc(snode_vert[i], snode_vert[dest_index], is_eps, (double)tmp_arc->getWeight()); // goto the next arc // arcs_remain = tmp_start_vert->gotoNext(); } } // finally check if the number of vertices are same in the converted graph // if (sub_graphs_d(k).length() != tmp_graphs(k).length()) { return Error::handle(name(), L"loadSubGraphs:: different number of vertices after conversion", SearchLevel::ERR, __FILE__, __LINE__); } // clean memory created by the tmp_graphs // tmp_graphs(k).clear(Integral::FREE); delete [] snode_vert; delete [] snode; } // end convert all the sub_graphs // exit gracefully // return true;}// method: storeSubGraphs//// arguments:// Sof& sof: (input) sof file object// long tag: (input) sof object instance tag//// return: a boolean indicating status//// this method has the object write itself from an Sof file//boolean SearchLevel::storeSubGraphs(Sof& sof_a, long tag_a) { // make sure the symbol table has been loaded // long index = 0; long dst_index = 0; boolean is_eps = false; long num_graphs = sub_graphs_d.length(); long num_symbols = symbol_table_d.length(); if (num_symbols == 0) { // please load symbol table first // return Error::handle(name(), L"storeSubGraphs", SearchLevel::ERR, __FILE__, __LINE__); } // if no tag is specified, the tag should be its level number // if (tag_a == DEF_TAG) { tag_a = (long)level_index_d; } // declare a Vector of Graph<Ulong> to be written to file // Ulong tmp_item; SearchNode* snode; GraphArc<SearchNode>* dst_arc; GraphVertex<SearchNode>* dst_vertex; Vector< DiGraph<Ulong> > tmp_graphs; // convert each Graph<SearchNode> > to Graph<Ulong> // tmp_graphs.setLength(sub_graphs_d.length()); for (long k = 0; k < num_graphs; k++) { // set the properties of graphs // long num_vertices = sub_graphs_d(k).length() + 2; tmp_graphs(k).setWeighted(sub_graphs_d(k).isWeighted()); // insert all vertices corresponding the current graph index // index = 0; GraphVertex<SearchNode>* vertices[num_vertices]; GraphVertex<Ulong>* tmp_vertices[num_vertices]; // add the start vertices to the arrays // vertices[index] = sub_graphs_d(k).getStart(); tmp_vertices[index++] = tmp_graphs(k).getStart(); // add the rest of the vertices to the arrays // for (boolean more = sub_graphs_d(k).gotoFirst(); more; more = sub_graphs_d(k).gotoNext()) { // get the current vertex // vertices[index] = const_cast<GraphVertex<SearchNode>* >(sub_graphs_d(k).getCurr()); // get the search node corresponding to the vertex // snode = vertices[index]->getItem(); // insert a vertex in the Graph<Ulong> for the current vertex // using the symbol ID of the vertex as the node item // tmp_item.assign(snode->getSymbolId()); tmp_vertices[index++] = tmp_graphs(k).insertVertex(&tmp_item); } // add the term vertices to the arrays // vertices[num_vertices - 1] = sub_graphs_d(k).getTerm(); tmp_vertices[num_vertices - 1] = tmp_graphs(k).getTerm(); // connect all vertices corresponding to the current graph index // for (long i = 0; i < num_vertices; i++) { boolean arcs_remain = vertices[i]->gotoFirst(); while (arcs_remain) { // get the destination vertex // dst_arc = vertices[i]->getCurr(); dst_vertex = dst_arc->getVertex(); is_eps = dst_arc->getEpsilon(); // find the destination vertex // dst_index = -1; for (long j = 0; j < num_vertices; j++) { if (dst_vertex == vertices[j]) { dst_index = j; break; } } // error - when we cannot find a destination index // if (dst_index == -1) { return Error::handle(name(), L"storeSubGraphs", Error::ARG, __FILE__, __LINE__); } // connect the vertices in the Graph<Ulong> // tmp_graphs(k).insertArc(tmp_vertices[i], tmp_vertices[dst_index], is_eps, (double)dst_arc->getWeight()); arcs_remain = vertices[i]->gotoNext(); } } } // write the Vector of Graph<Ulong> to file // if (!tmp_graphs.write(sof_a, tag_a, PARAM_MODEL)) { return false; } // exit gracefully // return true; }// method: load//// arguments:// Sof& sof: (input) sof file object// long tag: (input) sof object instance tag//// return: a boolean indicating status//// this method has the object read itself from an Sof file//boolean SearchLevel::load(Sof& sof_a, long tag_a) { // load the level tag // if (!loadLevelTag(sof_a, tag_a)) { return false; } if ( level_tag_d.length() == 0 ){ return Error::handle(name(), L"read - level tag is not specified", Error::ARG, __FILE__, __LINE__); } // must load the symbol table first // if (!loadSymbols(sof_a, tag_a)) { return false; } // load the non-speech symbol table (optional) // loadNonSpeechSymbols(sof_a, tag_a); // load the dummy symbol table (optional) // loadDummySymbols(sof_a, tag_a); // load the exclude symbol table (optional) // loadExcludeSymbols(sof_a, tag_a); // load the context less symbol table (optional) // loadContextLessSymbols(sof_a, tag_a); // load the skip symbol table (optional) // loadSkipSymbols(sof_a, tag_a); // load the sub graphs // if (!loadSubGraphs(sof_a, tag_a)) { return false; } // load the context mapping table (optional) // loadContextMapping(sof_a, tag_a); // exit gracefully // return true;}// method: store//// arguments:// Sof& sof: (input) sof file object// long tag: (input) sof object instance tag//// return: a boolean indicating status//// this method has the object read itself from an Sof file//boolean SearchLevel::store(Sof& sof_a, long tag_a) { // store the level tag // if (!storeLevelTag(sof_a, tag_a)) { return false; } // must store the symbol table first // if (!storeSymbols(sof_a, tag_a)) { return false; } // store the non-speech symbols (optional) // if (nonspeech_symbol_table_d.length() > 0) { storeNonSpeechSymbols(sof_a, tag_a); } // store the dummy symbols (optional) // if (dummy_symbol_table_d.length() > 0) { storeDummySymbols(sof_a, tag_a); } // store the exclude symbols (optional) // if (exclude_symbol_table_d.length() > 0) { storeExcludeSymbols(sof_a, tag_a); } // store the context less symbols (optional) // if (contextless_symbol_table_d.length() > 0) { storeContextLessSymbols(sof_a, tag_a); } // store the skip symbols (optional) // if (skip_symbol_table_d.length() > 0) { storeSkipSymbols(sof_a, tag_a); } // store the sub graphs // if (!storeSubGraphs(sof_a, tag_a)) { return false; } // store the context mapping table (optional) // if (context_map_d.length() > 0) { storeContextMapping(sof_a, tag_a); } // exit gracefully // return true;}// method: loadOccupancies//// arguments:// none//// return: a boolean indicating status//// this method reads the occupancies from the symbol occupancy file//boolean SearchLevel::loadOccupancies() { // read the symbol occupancy (optional) // if (symbol_occupancy_file_d.length() > 0) { // open the configuration file // Sof symbol_occupancy_file_sof; if (!symbol_occupancy_file_sof.open(symbol_occupancy_file_d, File::READ_ONLY)) { return Error::handle(name(), L"read - unable to open occupancy file", Error::ARG, __FILE__, __LINE__); } // make sure there are valid statistical models at this level // if (stat_models_d.length() == 0) { Error::handle(name(), L"loadOccupancies - no statistical models are present at the current level", Error::ARG, __FILE__, __LINE__); } // loop over each statistical model and retrieve their accumulators // for (long i=0; i < stat_models_d.length(); i++) { // read the accumulators corresponding to the current model // stat_models_d(i).readOccupancies(symbol_occupancy_file_sof, (long)i); } // close the occupancy files // symbol_occupancy_file_sof.close(); } // exit gracefully // return true; }// method: storeOccupancies//// arguments:// none//// return: a boolean indicating status//// this method reads the occupancies from accumulators file//boolean SearchLevel::storeOccupancies() { // write the symbol occupancy (optional) // if ((symbol_occupancy_file_d.length() > 0) && (write_symbol_occupancy_d)) { // open the configuration file // Sof symbol_occupancy_file_sof; if (!symbol_occupancy_file_sof.open(symbol_occupancy_file_d, File::WRITE_ONLY)) { return Error::handle(name(), L"read - unable to open occupancy file", Error::ARG, __FILE__, __LINE__); } // make sure there are valid statistical models at this level // if (stat_models_d.length() == 0) { Error::handle(name(), L"storeOccupancies - no statistical models are present at the current level", Error::ARG, __FILE__, __LINE__); } // loop over each statistical model and write the occupancies // for (long i=0; i < stat_models_d.length(); i++) { // write the accumulators corresponding to the current model // stat_models_d(i).writeOccupancies(symbol_occupancy_file_sof, (long)i); } // close the occupancy files // symbol_occupancy_file_sof.close(); } // exit gracefully // return true; }// method: eq//// arguments:// const SearchLevel& compare_level: (input) level to compare//// return: true if the levels are equivalent, else false//// compare two levels. they are equivalent if they contain equivalent// constituent objects//boolean SearchLevel::eq(const SearchLevel& compare_level_a) const { // compare all data // return (use_beam_prune_d.eq(compare_level_a.use_beam_prune_d) && beam_threshold_d.almostEqual(compare_level_a.beam_threshold_d) && use_instance_prune_d.eq(compare_level_a.use_instance_prune_d) && instance_threshold_d.eq(compare_level_a.instance_threshold_d) && lm_scale_d.almostEqual(compare_level_a.lm_scale_d) && symbol_penalty_d.almostEqual(compare_level_a.symbol_penalty_d) && use_context_d.eq(compare_level_a.use_context_d) && use_lexical_tree_d.eq(compare_level_a.use_lexical_tree_d) && left_context_d.eq(compare_level_a.left_context_d) && right_context_d.eq(compare_level_a.right_context_d) && context_hash_d.eq(compare_level_a.context_hash_d) && use_nsymbol_d.eq(compare_level_a.use_nsymbol_d) && nsymbol_model_d.eq(compare_level_a.nsymbol_model_d) && nsymbol_order_d.eq(compare_level_a.nsymbol_order_d) && write_symbol_occupancy_d.eq (compare_level_a.write_symbol_occupancy_d) && symbol_occupancy_file_d.eq(compare_level_a.symbol_occupancy_file_d));}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -