search_bestfirst_main.c

来自「julius version 4.12.about sound recognit」· C语言 代码 · 共 2,134 行 · 第 1/5 页

C
2,134
字号
    } else if (r->lmtype == LM_DFA) {      acc = dfa_acceptable(now, r);    }    if (acc && now->estimated_next_t <= 5) {      new = newnode(r);      /* new に now の面咳をコピ〖して·呵姜弄なスコアを纷换 */      /* copy content of 'now' to 'new', and compute the final score */      last_next_word(now, new, param, r);      if (debug2_flag) {	jlog("DEBUG:  This is acceptable as a sentence candidate\n");      }      /* g[] が掐蜗幌眉に茫していなければ逮笛 */      /* reject this sentence candidate if g[] does not reach the end */      if (new->score <= LOG_ZERO) {	if (debug2_flag) {	  jlog("DEBUG:  But invalid because Viterbi pass does not reach the 0th frame\n");	}	free_node(new);	free_node(now);	continue;      }      /* 减妄フラグを惟てて掐れ木す */      /* set endflag and push again  */      if (debug2_flag) {	jlog("DEBUG  This hypo itself was pushed with final score=%f\n", new->score);      }      new->endflag = TRUE;      if (put_to_stack(new, &start, &bottom, &stacknum, stacksize) != -1) {	if (r->graphout) {	  if (new->score > LOG_ZERO) {	    new->lastcontext = now->prevgraph;	    new->prevgraph = wordgraph_assign(new->seq[new->seqnum-1],					      WORD_INVALID,					      (new->seqnum >= 2) ? new->seq[new->seqnum-2] : WORD_INVALID,					      0,#ifdef GRAPHOUT_PRECISE_BOUNDARY					      /* wordend are shifted to the last */#ifdef PASS2_STRICT_IWCD					      new->wordend_frame[0],#else					      now->wordend_frame[0],#endif#else					      now->bestt,#endif					      new->score,					      prev_score,					      now->g[0],#ifdef GRAPHOUT_PRECISE_BOUNDARY#ifdef PASS2_STRICT_IWCD					      new->wordend_gscore[0],#else					      now->wordend_gscore[0],#endif#else					      now->tail_g_score,#endif					      now->lscore,#ifdef CM_SEARCH					      new->cmscore[new->seqnum-1],#else					      LOG_ZERO,#endif					      r					      );	  } else {	    new->lastcontext = now->lastcontext;	    new->prevgraph = now->prevgraph;	  }	} /* put_to_stack() != -1 */      }	/* recog->graphout */      /* この簿棱はここで姜わらずに, ここからさらに帽胳鸥倡する */      /* continue with the 'now' hypothesis, not terminate here */    }        /*     * この簿棱から·肌帽胳礁圭を疯年する.      * 肌帽胳礁圭は, この簿棱の夸年幌眉フレ〖ム件收に赂哼した     * 妈1パスのトレリス帽胳礁圭.      *     * N-gramの眷圭は称帽胳の n-gram 儡鲁澄唯が崔まれる.      * DFA の眷圭は, その面でさらに DFA 惧で儡鲁材墙なもののみが手ってくる     */    /*     * Determine next word set that can connect to this hypothesis.     * They come from the trellis word that has been survived at near the     * beginning of the last word.     *     * In N-gram mode, they also contain N-gram probabilities toward the     * source hypothesis.  In DFA mode, the word set is further reduced     * by the grammatical constraint     */#ifdef DEBUG    jlog("DEBUG: get next words\n");#endif    if (r->lmtype == LM_PROB) {      nwnum = ngram_nextwords(now, nextword, maxnwnum, r);    } else if (r->lmtype == LM_DFA) {      nwnum = dfa_nextwords(now, nextword, maxnwnum, r);      /* nextword が邦れたら、バッファを笼やして浩チャレンジ */      /* If the number of nextwords can exceed the buffer size, expand the	 nextword data area */      while (nwnum < 0) {	nextword = nw_expand(nextword, &maxnwnum, &nwroot, winfo->num);	nwnum = dfa_nextwords(now, nextword, maxnwnum, r);      }    }    if (debug2_flag) {      jlog("DEBUG:  %d words extracted from wordtrellis\n", nwnum);    }    /*      * 簿棱と肌帽胳礁圭から糠たな矢簿棱を栏喇し·スタックにいれる.      */    /*     * generate new hypotheses from 'now' and 'nextword',      * and push them to stack     */#ifdef DEBUG    jlog("DEBUG: generate hypo\n");#endif    if (r->lmtype == LM_DFA) {      now_noise_calced = FALSE;	/* TRUE is noise-inserted score has been calculated */    }    i = dwrk->pushctr;		/* store old value */#ifdef CM_SEARCH    /* initialize local stack */    cm_init(dwrk, winfo->num, jconf->annotate.cm_alpha#ifdef CM_MULTIPLE_ALPHA	    , jconf->annotate.cm_alpha_num#endif	    );#endif    /* for each nextword, generate a new hypothesis */    for (w = 0; w < nwnum; w++) {      if (r->lmtype == LM_DFA) {	/* limit word hypothesis */	if (! (winfo->wton[nextword[w]->id] >= cate_bgn && winfo->wton[nextword[w]->id] < cate_bgn + cate_num)) {	  continue;	}      }      new = newnode(r);      if (r->lmtype == LM_DFA) {	if (nextword[w]->can_insert_sp == TRUE) {	  /* ノイズを洞んだトレリススコアを纷换し·洞まない眷圭との呵络猛を艰る */	  /* compute hypothesis score with noise inserted */	  	  if (now_noise_calced == FALSE) {	    /* now に sp をつけた簿棱 now_noise を侯り,そのスコアを纷换 */	    /* generate temporal hypothesis 'now_noise' which has short-pause	       word after the original 'now' */	    fornoise.id = gdfa->sp_id;	    now_noise = newnode(r);	    cpy_node(now_noise, now);#if 0	    now_noise_tmp = newnode(r);	    next_word(now, now_noise_tmp, &fornoise, param, r);	    scan_word(now_noise_tmp, param, r);	    for(t=0;t<peseqlen;t++) {	      now_noise->g[t] = max(now_noise_tmp->g[t], now->g[t]);	    }	    free_node(now_noise_tmp);#else	    /* expand NOISE only if it exists in backward trellis */	    /* begin patch by kashima */	    if (jconf->pass2.looktrellis_flag) {	      if(!dfa_look_around(&fornoise, now, r)){		free_node(now_noise);		free_node(new);		continue;	      }	    }	    /* end patch by kashima */	    	    /* now_nosie の スコア g[] を纷换し·傅の now の g[] と孺秤して	       光い数を何脱 */	    /* compute trellis score g[], and adopt the maximum score	       for each frame compared with now->g[] */	    next_word(now, now_noise, &fornoise, param, r);	    scan_word(now_noise, param, r);	    for(t=0;t<peseqlen;t++) {	      now_noise->g[t] = max(now_noise->g[t], now->g[t]);	    }	    /* ノイズを洞んだ狠を雇胃したスコアを纷换したので·	       ここで呵稿のノイズ帽胳を now_noise から久す */	    /* now that score has been computed considering pause insertion,	       we can delete the last noise word from now_noise here */	    now_noise->seqnum--;#endif	    now_noise_calced = TRUE;	  }	  	  /* expand word only if it exists in backward trellis */	  /* begin patch by kashima */	  if (jconf->pass2.looktrellis_flag) {	    if(!dfa_look_around(nextword[w], now_noise, r)){	      free_node(new);	      continue;	    }	  }	  /* end patch by kashima */	  	  /* 糠しい簿棱' new' を 'now_noise' から栏喇 */	  /* generate a new hypothesis 'new' from 'now_noise' */	  next_word(now_noise, new, nextword[w], param, r);	  	} else {	  	  /* expand word only if it exists in backward trellis */	  /* begin patch by kashima */	  if (jconf->pass2.looktrellis_flag) {	    if(!dfa_look_around(nextword[w], now, r)){	      free_node(new);	      continue;	    }	  }	  /* end patch by kashima */	  	  /* 糠しい簿棱' new' を 'now_noise' から栏喇 */	  /* generate a new hypothesis 'new' from 'now_noise' */	  next_word(now, new, nextword[w], param, r);	  	}      }      if (r->lmtype == LM_PROB) {	/* 糠しい簿棱' new' を 'now_noise' から栏喇	   N-gram の眷圭はノイズを泼侍胺いしない */	/* generate a new hypothesis 'new' from 'now'.	   pause insertion is treated as same as normal words in N-gram mode. */	next_word(now, new, nextword[w], param, r);      }      if (new->score <= LOG_ZERO) { /* not on trellis */	free_node(new);	continue;      }	      dwrk->genectr++;#ifdef CM_SEARCH      /* store the local hypothesis to temporal stack */      cm_store(dwrk, new);#else       /* 栏喇した簿棱 'new' をスタックに掐れる */      /* push the generated hypothesis 'new' to stack */      /* stack overflow */      if (can_put_to_stack(new, &bottom, &stacknum, stacksize) == -1) {	free_node(new);	continue;      }            if (r->graphout) {	/* assign a word arc to the last fixed word */	new->lastcontext = now->prevgraph;	new->prevgraph = wordgraph_assign(new->seq[new->seqnum-2],					  new->seq[new->seqnum-1],					  (new->seqnum >= 3) ? new->seq[new->seqnum-3] : WORD_INVALID,					  new->bestt + 1,#ifdef GRAPHOUT_PRECISE_BOUNDARY#ifdef PASS2_STRICT_IWCD					  /* most up-to-date wordend_gscore is on new, because the last phone of 'now' will be computed at next_word() */					  new->wordend_frame[new->bestt],#else					  now->wordend_frame[new->bestt],#endif#else					  now->bestt,#endif					  new->score, prev_score,#ifdef PASS2_STRICT_IWCD					  new->g[new->bestt] - new->lscore,#else					  now->g[new->bestt+1],#endif#ifdef GRAPHOUT_PRECISE_BOUNDARY#ifdef PASS2_STRICT_IWCD					  /* most up-to-date wordend_gscore is on new, because the last phone of 'now' will be computed at next_word() */					  new->wordend_gscore[new->bestt],#else					  now->wordend_gscore[new->bestt],#endif#else					  now->tail_g_score,#endif					  now->lscore,#ifdef CM_SEARCH					  new->cmscore[new->seqnum-2],#else					  LOG_ZERO,#endif					  r					  );      }	/* recog->graphout */      put_to_stack(new, &start, &bottom, &stacknum, stacksize);      if (debug2_flag) {	j = new->seq[new->seqnum-1];	jlog("DEBUG:  %15s [%15s](id=%5d)(%f) [%d-%d] pushed\n",winfo->wname[j], winfo->woutput[j], j, new->score, new->estimated_next_t + 1, new->bestt);      }      dwrk->current = new;      //callback_exec(CALLBACK_DEBUG_PASS2_PUSH, r);      dwrk->pushctr++;#endif    } /* end of nextword loop */#ifdef CM_SEARCH    /* compute score sum */    cm_sum_score(dwrk#ifdef CM_MULTIPLE_ALPHA		 , jconf->annotate.cm_alpha_bgn 		 , jconf->annotate.cm_alpha_end		 , jconf->annotate.cm_alpha_step#endif		 );    /* compute CM and put the generated hypotheses to global stack */    while ((new = cm_get_node(dwrk)) != NULL) {      cm_set_score(dwrk, new#ifdef CM_MULTIPLE_ALPHA		   , jconf->annotate.cm_alpha_bgn		   , jconf->annotate.cm_alpha_end		   , jconf->annotate.cm_alpha_step#endif		   );#ifdef CM_SEARCH_LIMIT      if (new->cmscore[new->seqnum-1] < jconf->annotate.cm_cut_thres#ifdef CM_SEARCH_LIMIT_AFTER	  && dwrk->finishnum > 0#endif	  ) {	free_node(new);	continue;      }#endif /* CM_SEARCH_LIMIT */      /*      j = new->seq[new->seqnum-1];	      printf("  %15s [%15s](id=%5d)(%f) [%d-%d] cm=%f\n",winfo->wname[j], winfo->woutput[j], j, new->score, new->estimated_next_t + 1, new->bestt, new->cmscore[new->seqnum-1]);*/      /* stack overflow */      if (can_put_to_stack(new, &bottom, &stacknum, stacksize) == -1) {	free_node(new);	continue;      }      if (r->graphout) {	/* assign a word arc to the last fixed word */	new->lastcontext = now->prevgraph;	new->prevgraph = wordgraph_assign(new->seq[new->seqnum-2],					  new->seq[new->seqnum-1],					  (new->seqnum >= 3) ? new->seq[new->seqnum-3] : WORD_INVALID,					  new->bestt + 1,#ifdef GRAPHOUT_PRECISE_BOUNDARY#ifdef PASS2_STRICT_IWCD					  new->wordend_frame[new->bestt],#else					  now->wordend_frame[new->bestt],#endif#else					  now->bestt,#endif					  new->score, prev_score,#ifdef PASS2_STRICT_IWCD					  new->g[new->bestt] - new->lscore,#else					  now->g[new->bestt+1],#endif#ifdef GRAPHOUT_PRECISE_BOUNDARY#ifdef PASS2_STRICT_IWCD					  new->wordend_gscore[new->bestt],#else					  now->wordend_gscore[new->bestt],#endif#else					  now->tail_g_score,#endif					  now->lscore,#ifdef CM_SEARCH					  new->cmscore[new->seqnum-2],#else					  LOG_ZERO,#endif					  r					  );      }	/* recog->graphout */            put_to_stack(new, &start, &bottom, &stacknum, stacksize);      if (debug2_flag) {	j = new->seq[new->seqnum-1];	jlog("DEBUG:  %15s [%15s](id=%5d)(%f) [%d-%d] pushed\n",winfo->wname[j], winfo->woutput[j], j, new->score, new->estimated_next_t + 1, new->bestt);      }      dwrk->current = new;      //callback_exec(CALLBACK_DEBUG_PASS2_PUSH, r);      dwrk->pushctr++;    }#endif    if (debug2_flag) {      jlog("DEBUG: %d pushed\n",dwrk->pushctr-i);    }    if (r->lmtype == LM_DFA) {      if (now_noise_calced == TRUE) free_node(now_noise);    }        /*      * 艰り叫した簿棱を嘉てる     * free the source hypothesis     */    free_node(now);  }  /***************/  /* End of Loop */  /***************/  /* output */  if (dwrk->finishnum == 0) {		/* if search failed */    /* finalize result when no hypothesis was obtained */    if (verbo

⌨️ 快捷键说明

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