📄 slev_06.cc
字号:
vertex_more; vertex_more = (sub_graphs_d(k).gotoNext() & tmp_graphs(k).gotoNext())) { // retrieve the current vertices // GraphVertex<Ulong>* tmp_graph_vertex = tmp_graphs(k).getCurr(); GraphVertex<SearchNode>* sub_graph_vertex = sub_graphs_d(k).getCurr(); num_arcs = tmp_graph_vertex->length(); if (num_arcs != sub_graph_vertex->length()) { return Error::handle(name(), L"loadTransitionAccumulators - number of arcs loaded from the accumulator file does not match the number of arcs at this level", Error::ARG, __FILE__, __LINE__); } // loop over each arc corresponding to the current vertex // arc_more = false; for (arc_more = (tmp_graph_vertex->gotoFirst() & sub_graph_vertex->gotoFirst()); arc_more; arc_more = (tmp_graph_vertex->gotoNext() & sub_graph_vertex->gotoNext())) { // read the accumulator value // sub_graph_vertex->getCurr()->setAccumulator(sub_graph_vertex->getCurr()->getAccumulator() + tmp_graph_vertex->getCurr()->getWeight()); } } } // exit gracefully // return true; }// method: loadEmissionAccumulators//// arguments:// Sof& sof: (input) sof file object// long tag: (input) sof object instance tag//// return: a boolean indicating status//// this method reads the emission accumulators from file//boolean SearchLevel::loadEmissionAccumulators(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 we skip the top level // if (tag_a == 0) { return true; } // make sure there are valid statistical models at this level // if (stat_models_d.length() == 0) { return true; } // 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).readAccumulator(sof_a, (long)i); } // exit gracefully // return true; }// method: storeTransitionAccumulators//// arguments:// Sof& sof: (input) sof file object// long tag: (input) sof object instance tag//// return: a boolean indicating status//// this method writes the transition accumulators to file//boolean SearchLevel::storeTransitionAccumulators(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) { return true; } // write the symbol table // storeSymbols(sof_a, tag_a); // if no tag is specified, the tag should be its level number // if (tag_a == DEF_TAG) { tag_a = (long)level_index_d; } // make sure we skip the top level // if (tag_a == 0) { return true; } // 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->getAccumulator()); 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: storeEmissionAccumulators//// arguments:// Sof& sof: (input) sof file object// long tag: (input) sof object instance tag//// return: a boolean indicating status//// this method writes the emission accumulators to file//boolean SearchLevel::storeEmissionAccumulators(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 we skip the top level // if (tag_a == 0) { return true; } // make sure there are valid statistical models at this level // if (stat_models_d.length() == 0) { return true; } // loop over each statistical model and store their accumulators // for (long i=0; i < stat_models_d.length(); i++) { // write the accumulators corresponding to the current model // stat_models_d(i).writeAccumulator(sof_a, (long)i); } // exit gracefully // return true;}// method: loadContextLessSymbols//// arguments:// Sof& sof: (input) sof file object// long tag: (input) sof object instance tag//// return: a boolean indicating status//// this method read the context less symbol table from Sof file//boolean SearchLevel::loadContextLessSymbols(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; } // read the context less symbol table if being present in the file // if (contextless_symbol_table_d.read(sof_a, tag_a, PARAM_CONTEXTLESS_SYMBOL)) { // verify that the context less symbols are a subset of all valid symbols // SearchSymbol symbol; for (int i=0; i < contextless_symbol_table_d.length(); i++) { symbol.assign(contextless_symbol_table_d(i)); if (!isValidSymbol(getSymbolIndex(symbol))) { symbol.debug(L"invalid context less symbol"); return Error::handle(name(), L"loadContextLessSymbols: there is a context less symbol that does not appear in the symbol table", SearchLevel::ERR, __FILE__, __LINE__); } } } // exit gracefully // return true;}// method: storeContextLessSymbols//// arguments:// Sof& sof: (input) sof file object// long tag: (input) sof object instance tag//// return: a boolean indicating status//// this method writes the ContextLess symbol table from Sof file//boolean SearchLevel::storeContextLessSymbols(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; } // store the symbol table and exit // return contextless_symbol_table_d.write(sof_a, tag_a, PARAM_CONTEXTLESS_SYMBOL);}// method: loadSkipSymbols//// arguments:// Sof& sof: (input) sof file object// long tag: (input) sof object instance tag//// return: a boolean indicating status//// this method read the context less symbol table from Sof file//boolean SearchLevel::loadSkipSymbols(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; } // read the context less symbol table if being present in the file // if (skip_symbol_table_d.read(sof_a, tag_a, PARAM_SKIP_SYMBOL)) { // verify that the context less symbols are a subset of all valid symbols // SearchSymbol symbol; for (int i=0; i < skip_symbol_table_d.length(); i++) { symbol.assign(skip_symbol_table_d(i)); if (!isValidSymbol(getSymbolIndex(symbol))) { symbol.debug(L"invalid context less symbol"); return Error::handle(name(), L"loadSkipSymbols: there is a context less symbol that does not appear in the symbol table", SearchLevel::ERR, __FILE__, __LINE__); } } } // exit gracefully // return true;}// method: storeSkipSymbols//// arguments:// Sof& sof: (input) sof file object// long tag: (input) sof object instance tag//// return: a boolean indicating status//// this method writes the Skip symbol table from Sof file//boolean SearchLevel::storeSkipSymbols(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; } // store the symbol table and exit // return skip_symbol_table_d.write(sof_a, tag_a, PARAM_SKIP_SYMBOL);}// method: loadDummySymbols//// arguments:// Sof& sof: (input) sof file object// long tag: (input) sof object instance tag//// return: a boolean indicating status//// this method read the dummy symbol table from Sof file//boolean SearchLevel::loadDummySymbols(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; } // read the dummy symbol table if being present in the file // if (dummy_symbol_table_d.read(sof_a, tag_a, PARAM_DUMMY_SYMBOL)) { // verify that the dummy symbols are a subset of all valid symbols // SearchSymbol symbol; for (int i=0; i < dummy_symbol_table_d.length(); i++) { symbol.assign(dummy_symbol_table_d(i)); if (!isValidSymbol(getSymbolIndex(symbol))) { symbol.debug(L"invalid dummy symbol"); return Error::handle(name(), L"loadDummySymbols: there is a dummy symbol that does not appear in the symbol table", SearchLevel::ERR, __FILE__, __LINE__); } } } // exit gracefully // return true;}// method: storeDummySymbols//// arguments:// Sof& sof: (input) sof file object// long tag: (input) sof object instance tag//// return: a boolean indicating status//// this method writes the dummy symbol table from Sof file//boolean SearchLevel::storeDummySymbols(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; } // store the symbol table and exit //
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -