📄 isip_network_converter.cc
字号:
//weight = weight / (num_of_from_vertices * num_of_to_vertices ) ; weight = weight / num_of_to_vertices ; } // insert the arc into graphs // for ( int i= 0; i < num_of_from_vertices; i++ ){ for ( int j = 0 ; j < num_of_to_vertices; j++ ){ // get the from vertex and dest vertex // GraphVertex<SearchNode>* from_vertex = &vertices_list_a(from_id)(i); GraphVertex<SearchNode>* to_vertex = &vertices_list_a(to_id)(j); // connect the vertices in the searchnode graph // sub_graph_a.insertArc(from_vertex, to_vertex, is_epsilon, weight); } } // debug infor // //prefix_a.debug(L"arc: "); // exit gracefully // return true; }// method: readSymbols//// arguments:// Vector<SearchSymbol>& Symbols_list_a:// (input) hold the pointers of symbols// long : (input) total number of symbols to read// HashTable<String, String>&: (intput) the hash table which holds the data// String& prefix_a: (input) the prefix//// return: boolean value indicating status//// this method reads the data into a DiGraph and store pointers of Symbols//boolean readSymbols(Vector<SearchSymbol>& symbol_list_a, HashTable<String, String>& hash_table_a, String& size_prefix_a, String& prefix_a) { // local variable // long num_of_symbols = 0; hash_table_a.get(size_prefix_a)->get(num_of_symbols); // read each symbol // for (long j = 0; j < num_of_symbols; j++){ // set the hash_key // String curr_symbol; curr_symbol.assign((long)j); String hash_key; hash_key.assign(prefix_a); hash_key.concat(curr_symbol); curr_symbol.assign(*hash_table_a.get(hash_key)); String new_symbol; for ( long k = 0; k < curr_symbol.length(); k ++ ){ if ( curr_symbol(k) != '\\' ){ new_symbol.concat(curr_symbol(k)); } else { k++; if ( k < curr_symbol.length() ){ new_symbol.concat(curr_symbol(k)); } } } //curr_symbol.trimLeft('\\'); // debug information // if (debug_level >= Integral::BRIEF) { Console::put(new_symbol); } // put the symbol into list // symbol_list_a.concat(new_symbol); //symbol_list_a.concat(curr_symbol); } // exit gracefully // return true; }// method: storeSearchLevel//// arguments:// SearchLevel&: (output) construct the search level// HashTable<String, String>&: (intput) the hash table which stored data// String& prefix_a: (output) the pefix//// return: boolean value indicating status//// this method reads the data into a SearchLevel//boolean storeSearchLevel(SearchLevel& search_level_a, HashTable<String, String>& hash_table_a, Vector<SearchSymbol>& graph_name_a, String& prefix_a) { // local variable // String hash_key; // set the name for this level // hash_key.assign(prefix_a); hash_key.concat(IO_LEVEL_NAME); String level_tag; level_tag.assign(search_level_a.getLevelTag()); hash_table_a.insert(hash_key, &level_tag); // debug information // if (debug_level >= Integral::BRIEF) { level_tag.debug(L"level_tag"); } // set symbol table and all other symbols // including : non_speech, exclude_symbols, // // find the number of symbols in the symbol table // store the symbol table // hash_key.assign(prefix_a); hash_key.concat(IO_LEVEL_SYMBOL_SIZE); String symbol_prefix = prefix_a; symbol_prefix.concat(IO_LEVEL_SYMBOL); // remove the NO_LEFT_CONTEXT and NO_RIGHT_CONTEXT symbols in case // these symbols exist in the symbol-table // long j = 0; Vector<SearchSymbol>& symbol_table_t = search_level_a.getSymbolTable(); long len = symbol_table_t.length(); Vector<SearchSymbol> symbol_table(len); for( long i = 0; i < len; i++) { if (!((symbol_table_t(i).eq(SearchSymbol::NO_LEFT_CONTEXT)) || (symbol_table_t(i).eq(SearchSymbol::NO_RIGHT_CONTEXT)))) { symbol_table.setLength(j + 1); symbol_table(j) = symbol_table_t(i); j++; } } symbol_table_t.assign(symbol_table); storeSymbols(search_level_a.getSymbolTable(), hash_table_a, hash_key, symbol_prefix); // find the number of contexts in the contexts table // and store the context mapping table // hash_key.assign(prefix_a); hash_key.concat(IO_LEVEL_CONTEXT_SIZE); Vector<SearchSymbol> context_table; convertContextMapping(search_level_a.getContextMap(), context_table); String context_prefix = prefix_a; context_prefix.concat(IO_LEVEL_CONTEXT); storeSymbols(context_table, hash_table_a, hash_key, context_prefix); // find the number of symbols in the non-speech symbol table // store the symbol table // hash_key.assign(prefix_a); hash_key.concat(IO_LEVEL_NON_SPEECH_SYMBOL_SIZE); symbol_prefix.assign(prefix_a); symbol_prefix.concat(IO_LEVEL_NON_SPEECH_SYMBOL); storeSymbols(search_level_a.getNonSpeechSymbolTable(), hash_table_a, hash_key, symbol_prefix); // find the number of symbols in the dummy symbol table // store the symbol table // hash_key.assign(prefix_a); hash_key.concat(IO_LEVEL_DUMMY_SYMBOL_SIZE); symbol_prefix.assign(prefix_a); symbol_prefix.concat(IO_LEVEL_DUMMY_SYMBOL); storeSymbols(search_level_a.getDummySymbolTable(), hash_table_a, hash_key, symbol_prefix); // find the number of symbols in the contextLess symbol table // store the symbol table // hash_key.assign(prefix_a); hash_key.concat(IO_LEVEL_CONTEXTLESS_SYMBOL_SIZE); symbol_prefix.assign(prefix_a); symbol_prefix.concat(IO_LEVEL_CONTEXTLESS_SYMBOL); storeSymbols(search_level_a.getContextLessSymbolTable(), hash_table_a, hash_key, symbol_prefix); // find the number of symbols in the skip symbol table // store the symbol table // hash_key.assign(prefix_a); hash_key.concat(IO_LEVEL_SKIP_SYMBOL_SIZE); symbol_prefix.assign(prefix_a); symbol_prefix.concat(IO_LEVEL_SKIP_SYMBOL); storeSymbols(search_level_a.getSkipSymbolTable(), hash_table_a, hash_key, symbol_prefix); // find the number of symbols in the exclude symbol table // store the symbol table // hash_key.assign(prefix_a); hash_key.concat(IO_LEVEL_EXCLUDE_SYMBOL_SIZE); symbol_prefix.assign(prefix_a); symbol_prefix.concat(IO_LEVEL_EXCLUDE_SYMBOL); storeSymbols(search_level_a.getExcludeSymbolTable(), hash_table_a, hash_key, symbol_prefix); // find the number of graphs // long num_of_graphs = search_level_a.getNumSubGraphs(); String num_graphs; num_graphs.assign(num_of_graphs); hash_key.assign(prefix_a); hash_key.concat(IO_LEVEL_GRAPH_SIZE); hash_table_a.insert(hash_key, &num_graphs); // store graphs for a paticular level // for (long j = 0; j < num_of_graphs; j++){ // set the prefix // String curr_graph_index; curr_graph_index.assign((long)j); String graph_prefix; graph_prefix.assign(prefix_a); graph_prefix.concat(IO_DIGRAPH_PREFIX); graph_prefix.concat(curr_graph_index); // store the graph name // hash_key.assign(prefix_a); hash_key.concat(IO_LEVEL_GRAPH_NAME); hash_key.concat(curr_graph_index); hash_table_a.insert(hash_key, &graph_name_a(j)); // debug information // if (debug_level >= Integral::BRIEF) { String msg; msg.assign(hash_key); msg.concat(L"="); msg.concat(graph_name_a(j)); Console::put(msg); } // read the graph // storeSubGraph(search_level_a, search_level_a.getSubGraph(j), hash_table_a, graph_prefix); } // exit gracefully // return true; }// method: storeSubGraph//// arguments:// DiGraph<SearchNode>&: (output) construct this DiGraph// HashTable<String, String>&: (intput) the hash table which holds the data// String& prefix_a: (input) the prefix//// return: boolean value indicating status//// this method reads the data into a DiGraph<SearchNode>//boolean storeSubGraph(SearchLevel& search_level_a, DiGraph<SearchNode>& sub_graph_a, HashTable<String, String>& hash_table_a, String& prefix_a) { // local variable // String hash_key; // find the length of the digraph , number of vertices // String num_of_vertices; num_of_vertices.assign(sub_graph_a.length()+2); // get the number of vertices // hash_key.assign(prefix_a); hash_key.concat(IO_DIGRAPH_VERTEX_SIZE); hash_table_a.insert(hash_key, &num_of_vertices); // create local variables // Vector<Long> y_index; long x_index = 0; long num_of_arcs = 0; // call store vertex recursively // sub_graph_a.makeColorHash(); sub_graph_a.setColor(Integral::WHITE); storeVertex(*sub_graph_a.getStart(), sub_graph_a, hash_table_a, num_of_arcs, y_index, x_index, prefix_a); // set the position for the term // x_index = y_index.length(); storeVertex(*sub_graph_a.getTerm(), sub_graph_a, hash_table_a, num_of_arcs, y_index, x_index, prefix_a); // store the the num_of_arcs // String num_arcs; num_arcs.assign(num_of_arcs); hash_key.assign(prefix_a); hash_key.concat(IO_DIGRAPH_ARC_SIZE); hash_table_a.insert(hash_key, &num_arcs); // exit gracefully // return true; }// method: storeVertices//// arguments:// DiGraph<SearchNode>&: (output) construct this DiGraph// SingleLinkedList<GraphVertex<SearchNode>>& vertices_list_a:// (input) hold the pointers of Vertices// HashTable<String, String>&: (intput) the hash table which holds the data// String& prefix_a: (input) the prefix//// return: boolean value indicating status//// this method reads store vertices of a DiGraph into a hash_table//boolean storeVertex(GraphVertex<SearchNode>& vertex_a, DiGraph<SearchNode>& sub_graph_a, HashTable<String, String>& hash_table_a, long& num_of_arcs_a, Vector<Long>& y_index_a, long x_index_a, String& prefix_a) { // local variable // long vertex_index = indexOf(sub_graph_a, &vertex_a); long from_index = vertex_index; long to_index = 0; String hash_key; SearchSymbol symbol_name; long vertex_type = 0; String num_of_symbols(L"0"); // set the vertex prefix // String vertex_prefix; vertex_prefix.assign(prefix_a); vertex_prefix.concat(IO_VERTEX_PREFIX); vertex_prefix.concat(vertex_index); // store the vertex type // if ( vertex_a.isStart() ){ vertex_type = START_VERTEX; symbol_name.assign(START_VERTEX_NAME); } else if ( vertex_a.isTerm() ){ vertex_type = TERM_VERTEX; symbol_name.assign(TERM_VERTEX_NAME); } else { vertex_type = NODE_VERTEX; vertex_a.getItem()->getSymbol(symbol_name); // store the symbol, only one symbol for each vertex // hash_key.assign(vertex_prefix); hash_key.concat(IO_VERTEX_SYMBOL); hash_key.concat(L"0"); hash_table_a.insert(hash_key, &symbol_name); // set the number of symbols, only one symbol on each node // num_of_symbols.assign(L"1"); } // set the symbol size ( number of symbols on ths vertex ) // hash_key.assign(vertex_prefix); hash_key.concat(IO_VERTEX_SYMBOL_SIZE); hash_table_a.insert(hash_key, &num_of_symbols); // set the vertex name // hash_key.assign(vertex_prefix); hash_key.concat(IO_VERTEX_NAME); hash_table_a.insert(hash_key, &symbol_name); // store the vertex type // String type; type.assign(vertex_type); hash_key.assign(vertex_prefix); hash_key.concat(IO_VERTEX_TYPE); hash_table_a.insert(hash_key, &type); // set the width // hash_key.assign(vertex_prefix); hash_key.concat(IO_VERTEX_WIDTH); String width; width.assign((long)VERTEX_WIDTH); hash_table_a.insert(hash_key, &width); // set the height // hash_key.assign(vertex_prefix); hash_key.concat(IO_VERTEX_HEIGHT); String height; height.assign((long)VERTEX_HEIGHT); hash_table_a.insert(hash_key, &height); // set the location and width and height // long x_pos = x_index_a; long y_pos = 0; // set the positions // if ( x_pos == y_index_a.length() ){ Long y(0); y_index_a.concat(y); }else if ( x_pos < y_index_a.length() ){ y_pos = y_index_a(x_pos); } else { return Error::handle(L"storeVertices", L"invalide x_pos",
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -