📄 isip_network_converter.cc
字号:
Error::ARG, __FILE__, __LINE__); } // compute the x, y position // String x_loc; String y_loc; x_loc.assign(VERTEX_INITIAL_X + VERTEX_OFFSET_X * x_pos); y_loc.assign(VERTEX_INITIAL_Y + VERTEX_OFFSET_Y * y_pos); // set the x position // hash_key.assign(vertex_prefix); hash_key.concat(IO_VERTEX_LOC_X); hash_table_a.insert(hash_key, &x_loc); // set the y position // hash_key.assign(vertex_prefix); hash_key.concat(IO_VERTEX_LOC_Y); hash_table_a.insert(hash_key, &y_loc); // increase the y index // y_index_a(x_pos) += 1; // set the color of this vertex to black // // store the vertex type // if ( (!vertex_a.isStart()) && (!vertex_a.isTerm())){ sub_graph_a.setColor(&vertex_a, Integral::BLACK); } // loop over all arcs starting from this node // for (boolean more = vertex_a.gotoFirst(); more; more = vertex_a.gotoNext()) { // if this vertex is white, expand it // GraphArc<SearchNode>* tmp_arc = vertex_a.getCurr(); GraphVertex<SearchNode>* vertex = tmp_arc->getVertex(); to_index = indexOf(sub_graph_a, vertex); // store the arc // storeArc(num_of_arcs_a, from_index, to_index, tmp_arc, hash_table_a, prefix_a); // error detecting // if ( vertex->isStart() ){ return Error::handle(L"storeVertices", L"loop back to the Start vertex", Error::ARG, __FILE__, __LINE__); } // store vertex // if ( (!vertex->isStart()) && (!vertex->isTerm())){ if (sub_graph_a.getColor(vertex) != Integral::BLACK) { storeVertex(*vertex, sub_graph_a,hash_table_a, num_of_arcs_a, y_index_a, x_index_a+1, prefix_a); } } } // exit gracefully // return true; }// method: storeArc//// arguments:// DiGraph<SearchNode>&: (output) construct this DiGraph// SingleLinkedList<GraphVertex<SearchNode>>& vertices_list_a:// (output) hold the pointers to 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 the data into a DiGraph and store pointers of vertices//boolean storeArc(long& arc_index_a, long from_index_a, long to_index_a, GraphArc<SearchNode>*& arc_a, HashTable<String, String>& hash_table_a, String& prefix_a) { // local variable // String hash_key; String arc_prefix; // set the arc prefix // arc_prefix.assign(prefix_a); arc_prefix.concat(IO_ARC_PREFIX); arc_prefix.concat(arc_index_a); // store the from_id // String from_id; from_id.assign(from_index_a); hash_key.assign(arc_prefix); hash_key.concat(IO_ARC_FROM_ID); hash_table_a.insert(hash_key, &from_id); // store the to_id // String to_id; to_id.assign(to_index_a); hash_key.assign(arc_prefix); hash_key.concat(IO_ARC_TO_ID); hash_table_a.insert(hash_key, &to_id); // store width // String width(L"0"); to_id.assign(to_index_a); hash_key.assign(arc_prefix); hash_key.concat(IO_ARC_WIDTH); hash_table_a.insert(hash_key, &width); // store height // String height(L"0"); to_id.assign(to_index_a); hash_key.assign(arc_prefix); hash_key.concat(IO_ARC_HEIGHT); hash_table_a.insert(hash_key, &height); // store loc_x // String loc_x(L"0"); to_id.assign(to_index_a); hash_key.assign(arc_prefix); hash_key.concat(IO_ARC_LOC_X); hash_table_a.insert(hash_key, &loc_x); // store loc_y // String loc_y(L"0"); to_id.assign(to_index_a); hash_key.assign(arc_prefix); hash_key.concat(IO_ARC_LOC_Y); hash_table_a.insert(hash_key, &loc_y); // get the epsilon flag // String is_epsilon; if ( arc_a->getEpsilon() ){ is_epsilon.assign(L"true"); } else { is_epsilon.assign(L"false"); } hash_key.assign(arc_prefix); hash_key.concat(IO_ARC_EPSILON); hash_table_a.insert(hash_key, &is_epsilon); // get the transition // String weight; weight.assign(arc_a->getWeight()); hash_key.assign(arc_prefix); hash_key.concat(IO_ARC_WEIGHTS); hash_table_a.insert(hash_key, &weight); // increase the arc index // arc_index_a++; // exit gracefully // return true; }// method: storeSymbols//// 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 store symbols into a hash table//boolean storeSymbols(Vector<SearchSymbol>& symbol_list_a, HashTable<String, String>& hash_table_a, String size_prefix_a, String& prefix_a) { // local variable // long num_of_symbols = symbol_list_a.length(); String num_symbols; num_symbols.assign(num_of_symbols); hash_table_a.insert(size_prefix_a, &num_symbols); // read each symbol // for (long j = 0; j < symbol_list_a.length(); 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); // put the symbol into the symbol table // hash_table_a.insert(hash_key, &symbol_list_a(j)); } // exit gracefully // return true; }// method: indexOf//// 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 find the index of a vertex in DiGraph//long indexOf(DiGraph<SearchNode>& sub_graph_a, GraphVertex<SearchNode>* vertex_a) { // special case // long size = sub_graph_a.length(); if ( vertex_a->isStart() ){ return size; } if ( vertex_a->isTerm() ){ return size+1; } // search from the beginning for the item // long count = 0; for (boolean more = sub_graph_a.gotoFirst(); more && ( sub_graph_a.getCurr() != vertex_a); more = sub_graph_a.gotoNext()) { count++; } // exit gracefully // return count; }// method: writeHashTable//// 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 write the hash table in a format of property=value//boolean writeHashTable(HashTable<String, String>& hash_table_a, String & output_a, String description_a ) { // local variable // output_a.assign(L"# "); output_a.concat(description_a); // get the keys // Vector<String> keys; Vector<String> values; hash_table_a.keys(keys); hash_table_a.values(values); // put all values // for ( int i = 0 ; i < keys.length(); i ++ ){ output_a.concat(L"\n"); output_a.concat(keys(i)); output_a.concat(L"="); //output_a.concat(*hash_table_a.get(keys(i))); output_a.concat(values(i)); } // exit gracefully // return true; }// method: writeHashTable//// 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 write the hash table in a format of property=value//boolean writeHashTable(HashTable<String, String>& hash_table_a, File & output_a, String description_a ) { // local variable // String output; output.assign(L"# "); output.concat(description_a); output.concat(L"\n"); output_a.put(output); // get the keys // Vector<String> keys; Vector<String> values; hash_table_a.keys(keys); hash_table_a.values(values); for ( int i = 0 ; i < keys.length(); i ++ ){ output.assign(keys(i)); output.concat(L"="); output.concat(values(i)); output.concat(L"\n"); output_a.put(output); } // exit gracefully // return true; }// method: storeContextMapping//// arguments://// return: a boolean value indicating status//// convert the context map to a vector of search symbols// //boolean convertContextMapping(Vector<ContextMap>& context_map_a, Vector<SearchSymbol>& context_symbol_a){ // local variable // long len = context_map_a.length(); context_symbol_a.setCapacity(len); context_symbol_a.setLength(len); // loop over all the context_maps and parse string in each loop // for (long k = 0; k < len; k++) { // local variable // String rule_name; SearchSymbol context_symbol; Vector<SearchSymbol> context; Ulong index; // get the context and the context-index from the current // context-map // context = context_map_a(k).getContext(); index = context_map_a(k).getContextIndex(); // set the rule name // for (long i = 0; i < context.length(); i++){ // read the rule name // context_symbol.concat(context(i)); if ( i != (context.length() - 1)){ context_symbol.concat(L"-"); } } // set the context list // context_symbol_a(index).assign(context_symbol); } // exit gracefully // return true;}// method: convertContextMapping//// arguments://// return: a boolean value indicating status//// convert the context map to a vector of search symbols// //boolean convertContextMapping(Vector<SearchSymbol>& context_symbol_a, Vector<ContextMap>& context_map_a){ // local variable // long len = context_symbol_a.length(); context_map_a.setCapacity(len); context_map_a.setLength(len); // loop over all the context_maps and parse string in each loop // for (long k = 0; k < len; k++) { // local variable // SearchSymbol context_symbol = context_symbol_a(k); SearchSymbol symbol; Vector<SearchSymbol> context; // get the data string // long context_length = context_symbol.countTokens(L"-"); // get the context // long j=0; for (long i = 0; i < context_length; i++) { context_symbol.tokenize(symbol, j, L"-"); context.concat(symbol); } // set this context // if (!context_map_a(k).setContext(context)) { return Error::handle(L"convertContextMapping", L"can set context", Error::READ, __FILE__, __LINE__, Error::WARNING); } context_map_a(k).setContextIndex(k); } // exit gracefully // return true;}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -