void output(){ put_values();//检索出特征值并初始化放在values数组里 dp();//动态规划搜索最优解放在result数组里 if(threshold==0){ output_sentence(); }else{ if(sl_decoder_show_sentence){ output_raw_sentence(); printf(" "); } cal_betas(); output_allow_cws(); } }
int sentence_main(int sentence_id,std::vector<std::vector<float> >& excitationLvl) { char str[256]; match = 0; strcpy(recall_sentence, "\0"); receive_input_sentence(sentence_id); //fyang do_recall_sentence(1, sentence_id,excitationLvl); //Test //int i,j; //end Test output_sentence(sentence_id); #ifdef DEBUG_ALL printf("total words=%d \n", total_words_in_sentence); printf("confabulated sentence %d\n", sentence_id); #endif }
void output_sentence(int sentence_id) { int msg[MSG_LEN]; int lex_count, dcount, i, word_count1, word_count2, i1, i2; int size[MAX_LEX_SENTENCE]; char candidate_char[DEFAULT_SENTENCE_LENGTH]; char temp[128], *s, s1[DEFAULT_SENTENCE_LENGTH][DEFAULT_WORD_LENGTH+2], s2[DEFAULT_SENTENCE_LENGTH][DEFAULT_WORD_LENGTH+2]; int temp_size; int *temp_lexicon_array_sentence = NULL; std::vector<std::vector<float> > excitationLvl; int ambiguity = 0, first_ambiguity = 0; for(dcount = 0; dcount < MAX_LEX_SENTENCE; dcount++) { size[dcount] = candidate_size_sentence[dcount]; // if(size[dcount] > 1) { // if(ambiguity == 0) first_ambiguity = dcount; // ambiguity++; // } } if(temp_lexicon_array_sentence != NULL) { printf("SEVERE ERROR!!! temp_lexicon_array_sentence = %x\n", temp_lexicon_array_sentence); exit(1); } temp_lexicon_array_sentence = (int *)malloc(sizeof(int)*candidate_size_sentence[first_ambiguity]); #ifdef DEBUG_SENTENCE printf("total ambiguity = %d first ambiguity lex = %d\n", ambiguity, first_ambiguity); #endif for(i = 0; i < candidate_size_sentence[first_ambiguity]; i++) { temp_lexicon_array_sentence[i] = lexicon_array_sentence[first_ambiguity][i]; #ifdef DEBUG_SENTENCE printf("temp_lexicon_array_sentence[%d] = %d\n", i, temp_lexicon_array_sentence[i]); #endif } if(ambiguity == 0 ) { #ifdef DEBUG_SENTENCE printf("************the sentence is*************** \n"); #endif //getchar(); for(dcount = 0; dcount < DEFAULT_SENTENCE_LENGTH; dcount++) { #ifdef DEBUG_SENTENCE printf("size[%d] = %d\n",dcount,size[dcount]); // printf("size[%d]=%d str = %s\n", dcount, size[dcount], (input_sentence[sentence_id][dcount].word)[0].str); #endif if(size[dcount] <= 0) { if((input_sentence[sentence_id][dcount].word)[0].str == NULL) { strcat(recall_sentence, "` "); } else if(strlen( (input_sentence[sentence_id][dcount].word)[0].str) > 0 && strcmp( (input_sentence[sentence_id][dcount].word)[0].str, "`")) { strcat(recall_sentence, (input_sentence[sentence_id][dcount].word)[0].str); strcat(recall_sentence, " "); } } else { if(strlen(dictionary[lexicon_array_sentence[dcount][0]]) > 0 && strcmp(dictionary[lexicon_array_sentence[dcount][0]], "`")) { strcat(recall_sentence, dictionary[lexicon_array_sentence[dcount][0]]); strcat(recall_sentence, " "); } } } //fyang /*strcat(recall_sentence, "\nTag:"); for(dcount = 2*DEFAULT_SENTENCE_LENGTH-1; dcount < 3*DEFAULT_SENTENCE_LENGTH-1; dcount++) { printf("size[%d] = %d\n",dcount,size[dcount]); if(size[dcount] <= 0) { if((input_sentence[sentence_id][dcount].word)[0].str == NULL) { printf("a "); strcat(recall_sentence, "` "); } else if(strlen( (input_sentence[sentence_id][dcount].word)[0].str) > 0 && strcmp( (input_sentence[sentence_id][dcount].word)[0].str, "`")) { printf("b "); strcat(recall_sentence, (input_sentence[sentence_id][dcount].word)[0].str); strcat(recall_sentence, " "); } } else { if(strlen(dictionary[lex_table_sentence[dcount].lex_list[lexicon_array_sentence[dcount][0]]]) > 0){ //&& // strcmp(dictionary[lex_table_sentence[dcount].lex_list[lexicon_array_sentence[dcount][0]]], "`")) { printf("c "); strcat(recall_sentence, dictionary[lex_table_sentence[dcount].lex_list[lexicon_array_sentence[dcount][0]]]); strcat(recall_sentence, " "); } } }*/ #ifdef DEBUG_SENTENCE printf("ambiguity = 0 Got:%sLen=%d\n", recall_sentence, strlen(recall_sentence)); #endif } else if(ambiguity == 1) { //printf("************the sentences are*************** \n"); #ifdef DEBUG_SENTENCE printf("size of first ambiguity(%d) = %d\n", first_ambiguity, size[first_ambiguity]); #endif //for(i = 0; i < size[first_ambiguity]; i++) { for MPI for(dcount = 0; dcount < DEFAULT_SENTENCE_LENGTH; dcount++) { #ifdef DEBUG_ALL printf("size[%d] = %d\n",dcount,size[dcount]); #endif /* if(dcount == first_ambiguity) { if(strlen(dictionary[lex_table_sentence[dcount].lex_list[lexicon_array_sentence[dcount][i]]]) > 0 && strcmp(dictionary[lex_table_sentence[dcount].lex_list[lexicon_array_sentence[dcount][i]]], "`")) { strcat(recall_sentence, dictionary[lex_table_sentence[dcount].lex_list[lexicon_array_sentence[dcount][i]]]); strcat(recall_sentence, " "); } } else { */ if(size[dcount] <= 0) { if( (input_sentence[sentence_id][dcount].word)[0].str == NULL) { strcat(recall_sentence, "` "); } else if(strlen( (input_sentence[sentence_id][dcount].word)[0].str) > 0 && strcmp( (input_sentence[sentence_id][dcount].word)[0].str, "`")) { strcat(recall_sentence, (input_sentence[sentence_id][dcount].word)[0].str); strcat(recall_sentence, " "); } } else { if(strlen(dictionary[lexicon_array_sentence[dcount][0]]) > 0 && strcmp(dictionary[lexicon_array_sentence[dcount][0]], "`")) { strcat(recall_sentence, dictionary[lexicon_array_sentence[dcount][0]]); strcat(recall_sentence, " "); } } // } } //fyang /* strcat(recall_sentence, "\nTag:"); for(dcount = 2*DEFAULT_SENTENCE_LENGTH-1; dcount < 3*DEFAULT_SENTENCE_LENGTH-1; dcount++) { printf("size[%d] = %d\n",dcount,size[dcount]); if(dcount == first_ambiguity) { if(strlen(dictionary[lex_table_sentence[dcount].lex_list[lexicon_array_sentence[dcount][i]]]) > 0 && strcmp(dictionary[lex_table_sentence[dcount].lex_list[lexicon_array_sentence[dcount][i]]], "`")) { strcat(recall_sentence, dictionary[lex_table_sentence[dcount].lex_list[lexicon_array_sentence[dcount][i]]]); strcat(recall_sentence, " "); } } else { if(size[dcount] <= 0) { if( (input_sentence[sentence_id][dcount].word)[0].str == NULL) { strcat(recall_sentence, "` "); } else if(strlen( (input_sentence[sentence_id][dcount].word)[0].str) > 0 && strcmp( (input_sentence[sentence_id][dcount].word)[0].str, "`")) { strcat(recall_sentence, (input_sentence[sentence_id][dcount].word)[0].str); strcat(recall_sentence, " "); } } else { if(strlen(dictionary[lex_table_sentence[dcount].lex_list[lexicon_array_sentence[dcount][0]]]) > 0 && strcmp(dictionary[lex_table_sentence[dcount].lex_list[lexicon_array_sentence[dcount][0]]], "`")) { strcat(recall_sentence, dictionary[lex_table_sentence[dcount].lex_list[lexicon_array_sentence[dcount][0]]]); strcat(recall_sentence, " "); } } } }*/ #ifdef DEBUG_SENTENCE printf("ambiguity = 1 Got:%sLen=%d\n", recall_sentence, strlen(recall_sentence)); #endif } else { #ifdef DEBUG_SENTENCE printf("\n\nambiguity = %d, first ambiguity[%d] size %d\n", ambiguity, first_ambiguity, size[first_ambiguity]); printf("************the partial sentence is *************** \n"); for(dcount = 0; dcount < DEFAULT_SENTENCE_LENGTH; dcount++) { printf("( "); for(i = 0; i < candidate_size_sentence[dcount]; i++) { printf("%s %d ", dictionary[lexicon_array_sentence[dcount][i]], lexicon_array_sentence[dcount][i]); } printf(") "); } printf("\n"); #endif temp_size = input_sentence[sentence_id][first_ambiguity].size; input_sentence[sentence_id][first_ambiguity].size = 1; strcpy(temp, input_sentence[sentence_id][first_ambiguity].word[0].str); //for(i = 0; i < size[first_ambiguity]; i++) { for MPI for(i = 0; i < 1; i++) { //printf("str %s copy %s\n", input_sentence[first_ambiguity].word[0].str, dictionary[lex_table_sentence[first_ambiguity].lex_list[temp_lexicon_array_sentence[i]]]); strcpy(input_sentence[sentence_id][first_ambiguity].word[0].str, dictionary[temp_lexicon_array_sentence[i]]); //printf("str %s copy %s\n", input_sentence[first_ambiguity].word[0].str, dictionary[lex_table_sentence[first_ambiguity].lex_list[temp_lexicon_array_sentence[i]]]); //for(i2 = 0; i2 < size[first_ambiguity]; i2++) printf("%s %d ", dictionary[lex_table_sentence[first_ambiguity].lex_list[temp_lexicon_array_sentence[i2]] ], temp_lexicon_array_sentence[i2]); //printf("\n"); do_recall_sentence(1, sentence_id,excitationLvl); output_sentence(sentence_id); //printf("done partial sentence i = %d\n firsts ambiguity = %d size = %d remaining: \n", i, first_ambiguity, size[first_ambiguity]); //for(i2 = 0; i2 < size[first_ambiguity]; i2++) printf("%s ", dictionary[lex_table_sentence[first_ambiguity].lex_list[temp_lexicon_array_sentence[i2]]]); } //getchar(); //printf("multi ambiguity\n"); //exit(1); free(input_sentence[sentence_id][first_ambiguity].word[0].str); #ifdef DEBUG_MEM printf("loc free 8 %x\n", input_sentence[sentence_id][first_ambiguity].word[0].str); #endif input_sentence[sentence_id][first_ambiguity].word[0].str = NULL; input_sentence[sentence_id][first_ambiguity].word[0].str = (char *)malloc(sizeof(char)*(strlen(temp) + 1 ) ); strcpy(input_sentence[sentence_id][first_ambiguity].word[0].str, temp); input_sentence[sentence_id][first_ambiguity].size = temp_size; } free(temp_lexicon_array_sentence); temp_lexicon_array_sentence = NULL; }