⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 jp_09.cc

📁 这是一个从音频信号里提取特征参量的程序
💻 CC
📖 第 1 页 / 共 3 页
字号:
// file: $isip/class/asr/JSGFParser/jp_09.cc// version: $Id: jp_09.cc,v 1.2 2002/12/21 01:13:43 alphonso Exp $//// isip include files//#include "JSGFParser.h"// method: drawGraph//// arguments: none//// return: a boolean value indicating status//// This method draw a ISIP DiGraph (directed graph) based on the given rules// in the grammar//boolean JSGFParser::drawGraph() {    Stack<String> replaced_rules_a;    // replace all rule reference  //  JSGFToken t;  t = public_rule_table_d(0).first();    replaced_rules_a.clear();  replaceRuleReference(t, replaced_rules_a);  /////////////////////////////////////////////////////////////  Queue<JSGFToken> final = final_d;  while (!final.isEmpty()) {    JSGFToken tt;    final.remove(&tt);    //tt.printToken();    if (tt.token_type_d == 5 || tt.token_type_d == 7) {      String cc;      cc.assign(tt.vertex_index_d);      //  cc.debug(L"-------------index");    }   }  //////////////////////////////////////////////////////////////  // preprocess the token queue final_d by getting rid of weight tokens  // after setting the weight values to their modified object  // tag tokens are also skipped  //  Queue<JSGFToken> tmp_queue;  while (!final_d.isEmpty()) {    JSGFToken current, next;    final_d.remove(&current);    // skip tag token    //    if (current.token_type_d == 6) {      continue;    }    // get rid of weight token after assigning its value to appropriate object    //    else if (current.token_type_d == 8) {            // get the next token and assign the weight to it      //      final_d.remove(&next);      next.setTerminalWeight(current);      tmp_queue.add(&next);    }    // otherwise store the token    //    else {      tmp_queue.add(&current);    }  }  // update the token queue final_d  //  final_d.assign(tmp_queue);/////////////////////////////////////////////////////////////////////////////////// debug /////////////////////////////////////  final = final_d;  while (!final.isEmpty()) {    JSGFToken tt;    final.remove(&tt);    //tt.printToken();    if (tt.token_type_d == 5 || tt.token_type_d == 7) {      String cc;      cc.assign(tt.vertex_index_d);      //  cc.debug(L"-------------index");    }     Float w(tt.weight_d);    //  w.debug(L"--------------------weight----");  }/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////    // declare dummy arrays  //  Vector<JSGFToken> dummy_start;  Vector<JSGFToken> dummy_end;  boolean is_alter = false;   // call the recursive function to draw the graph  //  drawUnit(dummy_start, dummy_end, is_alter);  // exit gracefully  //  return true;}// method: drawUnit// arguments: Vector<JSGFToken>& start_a: (input/output) start token of//                                        the rule/group //            Vector<JSGFToken>& end_a: (input/output) end token of//                                        the rule/group//            boolean is_alter: (input) boolean value for determing if the//                              token or group  is alternative//// return: a boolean value indicating status//// This recursive method draws a rule unit in parentheses//boolean JSGFParser::drawUnit(Vector<JSGFToken>& start_a,			     Vector<JSGFToken>& end_a,			     boolean is_alter_a) {  // declare variables  //  JSGFToken current, next, dummy;  JSGFToken*  op_token;  Long curr_vert_index;      // get the first token as the current  //  final_d.remove(&current);  // if the current token is ( leading a grouping unit  // recursively process the grouped rule expansion  //  if (current.operator_d[0].eq(L"(")) {    drawUnit(start_a, end_a, false);    boolean is_loop = false;        // get weight    //    boolean epsilon = true;    float weight = 0.0;    if (current.weighted_terminal_d) {      epsilon = false;      weight = current.weight_d;    }        // determining if next token is "+" or "*"     //    if (final_d.length() != 0) {      op_token = final_d.peek();      if (op_token->operator_d[0].eq(L"+") ||	  op_token->operator_d[0].eq(L"*" )) {	is_loop = true;		// set flag (is_head_group_d = true) for each token in the start_a	// 	if (op_token->operator_d[0].eq(L"*" )) {	  for(int i = 0; i < start_a.length(); i++) {	    start_a(i).is_head_group_d = true;	  }	}	final_d.remove(&dummy);      }    }    if(is_loop) {            for(int i = 0; i < end_a.length(); i++) {	GraphVertex<String>* end_vert = vertex_list_d[end_a(i).vertex_index_d];	for(int j = 0; j < start_a.length(); j++) {	  GraphVertex<String>* start_vert = vertex_list_d[start_a(j).vertex_index_d];	  boolean find_arc = findArcIndex(end_a(i).vertex_index_d, start_a(j).vertex_index_d);	  if(!find_arc) {	    Pair< Long, Long> pair;	    Long t_1(end_a(i).vertex_index_d);	    Long t_2(start_a(j).vertex_index_d);	    pair.assign(t_1, t_2);	    arc_index_d.concat(pair);	 	    // there exists weight problem for + or *	    //draw arc from parent to the child (next)	    //	    graph_d.insertArc(end_vert, start_vert, false, weight);	  }	} // end for loop(int j = 0)      } //end for loop(int i = 0)    }    // set weight for each start token    //    for(int j = 0; j < start_a.length(); j++) {      if(current.weighted_terminal_d && !is_loop) {	start_a(j).weighted_terminal_d = true;	start_a(j).weight_d = current.weight_d;      }           }// end for loop (int j =0)  }  // if the current token is [ leading a optional grouping unit  // recursively process the optional grouped rule expansion  //  if (current.operator_d[0].eq(L"[")) {    //is_optional = true;    drawUnit(start_a, end_a, false);    boolean is_loop = false;    // get weight    //    boolean epsilon = true;    float weight = 0.0;    if (current.weighted_terminal_d) {      epsilon = false;      weight = current.weight_d;    }        // set flag (is_head_group_d = true) for each token in the start_a    //          for(int i = 0; i < start_a.length(); i++) {      start_a(i).is_head_group_d = true;    }    // determining if next token is "+" or "*"     //    if (final_d.length() != 0) {      op_token = final_d.peek();      if (op_token->operator_d[0].eq(L"+") ||	  op_token->operator_d[0].eq(L"*" )) {	final_d.remove(&dummy);	is_loop = true;      }    }        if(is_loop) {            for(int i = 0; i < end_a.length(); i++) {	GraphVertex<String>* end_vert = vertex_list_d[end_a(i).vertex_index_d];	for(int j = 0; j < start_a.length(); j++) {	  GraphVertex<String>* start_vert = vertex_list_d[start_a(j).vertex_index_d];	  boolean find_arc = findArcIndex(end_a(i).vertex_index_d, start_a(j).vertex_index_d);	  if(!find_arc) {	    	    Pair< Long, Long> pair;	    Long t_1(end_a(i).vertex_index_d);	    Long t_2(start_a(j).vertex_index_d);	    pair.assign(t_1, t_2);	        	    arc_index_d.concat(pair);	    	    // there exists weight problem for + or *	    //draw arc from parent to the child (next)	    //	    graph_d.insertArc(end_vert, start_vert, false, weight);	  }	} // end for loop(int j = 0)      } //end for loop(int i = 0)    }    // set weight for each start token    //    for(int j = 0; j < start_a.length(); j++) {      if(current.weighted_terminal_d && !is_loop) {	start_a(j).weighted_terminal_d = true;	start_a(j).weight_d = current.weight_d;      }           }// end for loop (int j =0)      }  // if it is terminal or quoted token, create a vertex and add to the array  //  if (current.token_type_d == 5 || current.token_type_d == 7) {    // store corresponding vertex index of the token into the start list    //    curr_vert_index = current.vertex_index_d;    start_a.concat(current);    end_a.concat(current);        // get weight    //    boolean epsilon = true;    float weight = 0;    if (current.weighted_terminal_d) {      epsilon = false;      weight = current.weight_d;    }    GraphVertex<String>* child_vert = vertex_list_d[current.vertex_index_d];        // determining if next token is "+" or "*"     //    if (final_d.length() != 0) {      op_token = final_d.peek();      if (op_token->operator_d[0].eq(L"+") ||	  op_token->operator_d[0].eq(L"*" )) {	final_d.remove(&dummy);	current.is_head_group_d = true;	boolean find_arc = findArcIndex(current.vertex_index_d, current.vertex_index_d);	if(!find_arc) {	  	    Pair< Long, Long> pair;	    Long t_1(current.vertex_index_d);	    Long t_2(current.vertex_index_d);	    pair.assign(t_1, t_2);	        	    arc_index_d.concat(pair);	    	    // there exists weight problem for + or *	    //draw arc from parent to the child (next)	    //	    if (!epsilon) {	      graph_d.insertArc(child_vert, child_vert, false, weight);	    }	    else {	      graph_d.insertArc(child_vert, child_vert, true);	    }	}      }    }  }  // if the next is a recursive grammar  //   else if (current.operator_d[0].eq(L"@@")) {    Stack<String> replaced_rules;    // token queue for final processing in graph drawing section    //    Queue<JSGFToken> rule_final;        // replace all rule reference    //    String t;    boolean is_processed = false;    t = current.rulename_d;    for(long i = 0; i < recursive_grammar_d.length(); i++) {      if(t.eq(recursive_grammar_d(i).first())) {	is_processed = true;	start_a.concat(recursive_grammar_d(i).second());	end_a.clear(Integral::RELEASE);      }	    }    if(!is_processed) {      replaced_rules.clear();          replaceRecursionRuleReference(t, replaced_rules, rule_final);        /////////////////////////////////////////////////////////////      Queue<JSGFToken> final = rule_final;      while (!final.isEmpty()) {	JSGFToken tt;	final.remove(&tt);	//tt.printToken();      }      //////////////////////////////////////////////////////////////          // preprocess the token queue final_d by getting rid of weight tokens      // after setting the weight values to their modified object      // tag tokens are also skipped      //      Queue<JSGFToken> tmp_queue;      while (!rule_final.isEmpty()) {		JSGFToken current, next;	rule_final.remove(&current);		// skip tag token	//	if (current.token_type_d == 6) {	  continue;	}	// get rid of weight token after assigning its value to appropriate object	//	else if (current.token_type_d == 8) {	  	  // get the next token and assign the weight to it	  //	  rule_final.remove(&next);	  next.setTerminalWeight(current);	  tmp_queue.add(&next);	}	// otherwise store the token	//	else {	  tmp_queue.add(&current);	}      }        // update the token queue rule_final      //      rule_final.assign(tmp_queue);            ////////////////////////////////////////////////////////////////      /////////////////// debug /////////////////////////////////////      final = rule_final;      while (!final.isEmpty()) {	JSGFToken tt;	final.remove(&tt);	//      tt.printToken();	Float w(tt.weight_d);	//      w.debug(L"--------------------weight----");      }      //////////////////////////////////////////////////////////////      ///////////////////////////////////////////////////////////////              // call the recursive function to get start token and end token      // for the right recursive rule      //      searchStartEnd(start_a, end_a, false, rule_final);      end_a.clear(Integral::RELEASE);      Pair<String, Vector<JSGFToken> > pair;      Vector<JSGFToken> start_tokens;      start_tokens.concat(start_a);      pair.assign(t, start_tokens);            recursive_grammar_d.concat(pair);    }        // set weight for each start token    //    for(int j = 0; j < start_a.length(); j++) {      if(current.weighted_terminal_d) {	start_a(j).weighted_terminal_d = true;	start_a(j).weight_d = current.weight_d;      }           }// end for loop (int j =0)      }  // loop through all tokens until meeting a grouping unit or the end  //  while (true) {    JSGFToken*  op_token1;    Long next_vert_index;    //    GraphVertex<String>* next_vert;    if(final_d.length() == 0)      break;    if (is_alter_a) {            // determining if next token is "]" or ")" or ";"       //      op_token1 = final_d.peek();      if (op_token1->operator_d[0].eq(L"]") ||	  op_token1->operator_d[0].eq(L")")) {	break;      }    }    // get the next token    //    final_d.remove(&next);    if (next.operator_d[0].eq(L"]") ||	next.operator_d[0].eq(L")")) {      break;    }    // if the next token is a terminal or quoted token for sequence    //    if (next.token_type_d == 5 || next.token_type_d == 7) {      // initialize is_optional = false;      //      boolean is_optional = false;            // get weight      //      boolean epsilon = true;      float weight = 0.0;      if (next.weighted_terminal_d) {	epsilon = false;	weight = next.weight_d;      }      GraphVertex<String>* child_vert = vertex_list_d[next.vertex_index_d];      JSGFToken* op_token2 = (JSGFToken*)NULL;      // determining if next token is "+" or "*"       //      if (final_d.length() != 0) {	op_token2 = final_d.peek();	if (op_token2->operator_d[0].eq(L"+") ||	    op_token2->operator_d[0].eq(L"*" )) {	  final_d.remove(&dummy);	  boolean find_arc = findArcIndex(next.vertex_index_d, next.vertex_index_d);	  if(!find_arc) {	    	    Pair< Long, Long> pair;	    Long t_1(next.vertex_index_d);	    Long t_2(next.vertex_index_d);	    pair.assign(t_1, t_2);	        	    arc_index_d.concat(pair);	    	    // there exists weight problem for + or *	    //draw arc from parent to the child (next)	    //	    if (!epsilon) {	      graph_d.insertArc(child_vert, child_vert, false, weight);	    }	    else {	      graph_d.insertArc(child_vert, child_vert, true);	    }	  }	}	// determing if there exists optional_group token in the start_a	//	for(int j = 0; j < start_a.length(); j++) {	  if(start_a(j).is_head_group_d) {	    is_optional = true;	    if (!op_token2->operator_d[0].eq(L"*")) {	      start_a(j).is_head_group_d = false;	    }	  } 	}// end for loop (int j =0)      }// end if (final_d.length() != 0)      else {		// determing if there exists optional_group token in the start_a	//	for(int j = 0; j < start_a.length(); j++) {	  if(start_a(j).is_head_group_d) {	    is_optional = true;	    start_a(j).is_head_group_d = false;	  } 	}// end for loop (int j =0)      }

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -