📄 gc_read_1.cc
字号:
probability_a[0]*=target_prob; } if(alternative_bool==ISIP_TRUE) { size_a+=offset; // make room for adding "~prob_vale" for every terminal // by moving all symbols to backward offset position // for(int_4 k=size_a-1; k>=i_start+offset; k--) symbols_a[k]=symbols_a[k-offset]; int_4 j_start=i_start+offset+1; //get start position int_4 j_new_start=i_start+1; //get start position // deal with every terminal or sub-expression // for(int_4 j=0; j<sub_total; j++) { i_brace_indicate=0; // find the first terminal or expression // if it is sub-expression, move all the way // till the end of sub-expression // if(strcmp((char *)symbols_a[j_start], (char *)BRACE_START)==0) { symbols_a[j_new_start++]=symbols_a[j_start]; // copy the symbol to correct position // i_brace_indicate++; j_start++; //move to next symbol while (i_brace_indicate!=0) { if(strcmp((char *)symbols_a[j_start], (char *)BRACE_START)==0) { symbols_a[j_new_start++]=symbols_a[j_start]; i_brace_indicate++; } else if(strcmp((char *)symbols_a[j_start], (char *)BRACE_CLOSE)==0) { symbols_a[j_new_start++]=symbols_a[j_start]; i_brace_indicate--; } else symbols_a[j_new_start++]=symbols_a[j_start]; j_start++; //move to next symbol } //end of while i_brace_indicate // if it is "~" just eat it // if(strcmp((char *)symbols_a[j_start], (char *)PROBABILITY_SYMBOL)==0) { // copy ~ mark and add new probability value // symbols_a[j_new_start++]=symbols_a[j_start++]; char_1* temp_buff = new char_1[GC_GRAM_MAX_SYMBOL_SIZE]; sprintf((char*)temp_buff, "%3.3f",probability_a[j]); symbols_a[j_new_start++]=temp_buff; j_start++; //eat the older probability value symbols_a[j_new_start++]=symbols_a[j_start++]; } // create new ~ mark and new probability value // else { char_1* temp_buff1 = new char_1[GC_GRAM_MAX_SYMBOL_SIZE]; char_1* temp_buff2 = new char_1[GC_GRAM_MAX_SYMBOL_SIZE]; sprintf((char*)temp_buff1, "%s","~"); sprintf((char*)temp_buff2, "%3.3f",probability_a[j]); symbols_a[j_new_start++]=temp_buff1; symbols_a[j_new_start++]=temp_buff2; offset-=2; // if last element, add ')' // if(j==sub_total-1) { char_1* temp_buff3 = new char_1[GC_GRAM_MAX_SYMBOL_SIZE]; sprintf((char*)temp_buff3, "%s",")"); symbols_a[j_new_start++]=temp_buff3; } else symbols_a[j_new_start++]=symbols_a[j_start++]; } } //end of if BRACE_START // if move to here this is terminal // else { symbols_a[j_new_start++]=symbols_a[j_start++]; if(strcmp((char *)symbols_a[j_start], (char *)PROBABILITY_SYMBOL)==0) { // copy ~ mark and add new probability value // symbols_a[j_new_start++]=symbols_a[j_start++]; char_1* temp_buff = new char_1[GC_GRAM_MAX_SYMBOL_SIZE]; sprintf((char*)temp_buff, "%3.3f",probability_a[j]); symbols_a[j_new_start++]=temp_buff; j_start++; //eat the older probability value symbols_a[j_new_start++]=symbols_a[j_start++]; } else { // add ~ mark and new probability value // char_1* temp_buff1 = new char_1[GC_GRAM_MAX_SYMBOL_SIZE]; char_1* temp_buff2 = new char_1[GC_GRAM_MAX_SYMBOL_SIZE]; sprintf((char*)temp_buff1, "%s","~"); sprintf((char*)temp_buff2, "%3.3f",probability_a[j]); symbols_a[j_new_start++]=temp_buff1; symbols_a[j_new_start++]=temp_buff2; offset-=2; // if last element, add ')' // if(j==sub_total-1) { char_1* temp_buff3 = new char_1[GC_GRAM_MAX_SYMBOL_SIZE]; sprintf((char*)temp_buff3, "%s",")"); symbols_a[j_new_start++]=temp_buff3; } else symbols_a[j_new_start++]=symbols_a[j_start++]; } } //end of else } //end of for( sub_total) loop alternative_bool=ISIP_FALSE; // move all symbols back to its original position // for(int_4 k=j_new_start; k<size_a-2; k++) symbols_a[k]=symbols_a[k+2]; size_a-=2; symbols_a[size_a]=(char_1*)NULL; } //end of if (alternative_bool ==ISIP_TRUE) else { // first terminal has probability value already // if(prob_bool_a[0]==ISIP_TRUE) { i_pointer=i_start+1; //find the probability value position // if it is sub-expression, move all the way // till the end of sub-expression // if(strcmp((char *)symbols_a[i_pointer], (char *)BRACE_START)==0) { i_brace_indicate++; i_pointer++; //move to next symbol while (i_brace_indicate!=0) { if(strcmp((char *)symbols_a[i_pointer], (char *)BRACE_START)==0) i_brace_indicate++; else if(strcmp((char *)symbols_a[i_pointer], (char *)BRACE_CLOSE)==0) i_brace_indicate--; else i_pointer++; //move to next symbol } //end of while i_brace_indicate // if it is "~" just eat it // it is sure we can find this point // if(strcmp((char *)symbols_a[i_pointer], (char *)PROBABILITY_SYMBOL)==0) { char_1* temp_buff = new char_1[GC_GRAM_MAX_SYMBOL_SIZE]; sprintf((char*)temp_buff, "%3.3f",probability_a[0]); symbols_a[i_pointer+1]=temp_buff; } else i_pointer--; //push back the symbol } //end of if BRACE_START // if move to here this is terminal // else { i_pointer++; if(strcmp((char *)symbols_a[i_pointer], (char *)PROBABILITY_SYMBOL)==0) { char_1* temp_buff = new char_1[GC_GRAM_MAX_SYMBOL_SIZE]; sprintf((char*)temp_buff, "%3.3f",probability_a[0]); symbols_a[i_pointer+1]=temp_buff; } else i_pointer--; } // remove the target probability value // for(int_4 k=i_end+1; k< GC_GRAM_MAX_SYMBOL_SIZE-2; k++) symbols_a[k]=symbols_a[k+2]; // size will reduce two because we delete the ~prob_value // size_a=size_a-2; } //end of if // first terminal has no probability value // else { i_pointer=i_start+1; //find the probability value position // if it is sub-expression, move all the way // till the end of sub-expression // if(strcmp((char *)symbols_a[i_pointer], (char *)BRACE_START)==0) { i_brace_indicate++; i_pointer++; //move to next symbol while (i_brace_indicate!=0) { if(strcmp((char *)symbols_a[i_pointer], (char *)BRACE_START)==0) i_brace_indicate++; else if(strcmp((char *)symbols_a[i_pointer], (char *)BRACE_CLOSE)==0) i_brace_indicate--; i_pointer++; //move to next symbol } //end of while i_brace_indicate i_pointer--; //push back the symbol } //end of if BRACE_START // remove the target probability value by moving all symbol // backward two position // for(int_4 k=i_end; k>i_pointer; k--) symbols_a[k+2]=symbols_a[k]; // add ~ mark and probability value // char_1* temp_buff1 = new char_1[GC_GRAM_MAX_SYMBOL_SIZE]; char_1* temp_buff2 = new char_1[GC_GRAM_MAX_SYMBOL_SIZE]; sprintf((char*)temp_buff1, "%s","~"); sprintf((char*)temp_buff2, "%3.3f",probability_a[0]); symbols_a[i_pointer+1]=temp_buff1; symbols_a[i_pointer+2]=temp_buff2; // if last element, add ')' // if(sub_total==1) { char_1* temp_buff3 = new char_1[GC_GRAM_MAX_SYMBOL_SIZE]; sprintf((char*)temp_buff3, "%s",")"); symbols_a[i_pointer+3]=temp_buff3; } } } i_pointer=size_a-1; i_end=0; // search for new created ")~" after distribution // while(i_pointer>0) { if((strcmp((char *)symbols_a[i_pointer], (char *)PROBABILITY_SYMBOL)==0 && strcmp((char *)symbols_a[i_pointer-1], (char *)BRACE_CLOSE)==0) ) { target_prob=(float_8) atof((char*)symbols_a[i_pointer+1]); i_end=i_pointer-1; i_brace_indicate++; break; } i_pointer--; } i_brace_indicate=0; // we only need the i_loop for while_loop // if ")~" exist, need to search again after enter while loop again // i_loop=i_end; }//end of while (i_loop) // exit gracefully // return ISIP_TRUE;}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -