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

📄 ngram_decode.c

📁 julius version 4.12.about sound recognition.
💻 C
📖 第 1 页 / 共 2 页
字号:
 * * This function builds a list of next word candidates by looking up * the word trellis at specified frame, with lookup_range frame margin. * If the same words exists in the near frames, only the one nearest to the * specified frame will be chosen. *  * @param r [in] recognition process instance * @param nw [out] pointer to hold the extracted words as list of next word candidates * @param hypo [in] partial sentence hypothesis from which the words will be expanded * @param tm [in] center time frame to look up the words * @param t_end [in] right frame boundary for the lookup. *  * @return the number of next words candidates stored in @a nw. * </EN> */static intget_backtrellis_words(RecogProcess *r, NEXTWORD **nw, NODE *hypo, short tm, short t_end){  int num = 0;  int t, t_step;  int oldnum=0;  BACKTRELLIS *bt;  int lookup_range;  if (tm < 0) return(0);  bt = r->backtrellis;  lookup_range = r->config->pass2.lookup_range;#ifdef PREFER_CENTER_ON_TRELLIS_LOOKUP  /* fix for 3.2 (01/10/18 by ri) */  /* before and after (one near center frame has high priority) */  for (t_step = 0; t_step < lookup_range; t_step++) {    /* before or center */    t = tm - t_step;    if (t < 0 || t > bt->framelen - 1 || t >= t_end) continue;    num = pick_backtrellis_words(r, nw, oldnum, hypo, t);    if (num > oldnum) {      qsort(nw, num, sizeof(NEXTWORD *),	    (int (*)(const void *,const void *))compare_nw);      oldnum = num;    }    if (t_step == 0) continue;	/* center */    /* after */    t = tm + t_step;    if (t < 0 || t > bt->framelen - 1 || t >= t_end) continue;    num = pick_backtrellis_words(r, nw, oldnum, hypo, t);    if (num > oldnum) {      qsort(nw, num, sizeof(NEXTWORD *),	    (int (*)(const void *,const void *))compare_nw);      oldnum = num;    }  }#else  /* before the center frame */  for(t = tm; t >= tm - lookup_range; t--) {    if (t < 0) break;    num = pick_backtrellis_words(r, nw, oldnum, hypo, t);    if (num > oldnum) {      qsort(nw, num, sizeof(NEXTWORD *),	    (int (*)(const void *,const void *))compare_nw);      oldnum = num;    }  }  /* after the center frame */  for(t = tm + 1; t < tm + lookup_range; t++) {    if (t > bt->framelen - 1) break;    if (t >= t_end) break;    num = pick_backtrellis_words(r, nw, oldnum, hypo, t);    if (num > oldnum) {      qsort(nw, num, sizeof(NEXTWORD *),	    (int (*)(const void *,const void *))compare_nw);      oldnum = num;    }  }#endif  return num;}/**  * <JA> * @brief  润鸥倡帽胳を近殿.  *  * 扩腆により鸥倡滦据とならない帽胳をリストから久殿する.  *  * @param nw [i/o] 肌帽胳礁圭∈礁圭面の鸥倡できない帽胳が久殿される∷ * @param hypo [in] 鸥倡傅の婶尸矢簿棱 * @param num [in] @a nw に附哼呈羌されている帽胳眶 * @param winfo [in] 帽胳辑今 *  * @return 糠たに nw に崔まれる肌帽胳眶 * </JA> * <EN> * @brief  Remove non-expansion word from list. *  * Remove words in the nextword list which should not be expanded. *  * @param nw [i/o] list of next word candidates (will be shrinked by removing some words) * @param hypo [in] partial sentence hypothesis from which the words will be expanded * @param num [in] current number of next words in @a nw * @param winfo [in] word dictionary *  * @return the new number of words in @a nw * </EN> */static intlimit_nw(NEXTWORD **nw, NODE *hypo, int num, WORD_INFO *winfo){  int src,dst;  int newnum;  /* <s>からは部も鸥倡しない */  /* no hypothesis will be generated after "<s>" */  if (hypo->seq[hypo->seqnum-1] == winfo->head_silwid) {    return(0);  }  dst = 0;  for (src=0; src<num; src++) {    if (nw[src]->id == winfo->tail_silwid) {      /* </s> は鸥倡しない */      /* do not expand </s> (it only appears at start) */      continue;    }#ifdef FIX_35_INHIBIT_SAME_WORD_EXPANSION    /* 木涟帽胳と票じトレリス帽胳は鸥倡しない */    /* inhibit expanding the exactly the same trellis word twice */    if (nw[src]->tre == hypo->tre) continue;#endif        if (src != dst) memcpy(nw[dst], nw[src], sizeof(NEXTWORD));    dst++;  }  newnum = dst;  return newnum;}	/**  * <JA> * @brief  介袋帽胳簿棱礁圭を滇める.  * * N-gramベ〖スの玫瑚では·介袋簿棱は帽胳琐萨の痰不帽胳に盖年されている.  * ただし·ショ〖トポ〖ズセグメンテ〖ション箕は·妈1パスで呵姜フレ〖ムに姜眉が * 荒った帽胳の面で锑刨呵络の帽胳となる.  *  * @param nw [out] 肌帽胳铬输リスト∈评られた介袋帽胳簿棱を呈羌する∷ * @param peseqlen [in] 掐蜗フレ〖ム墓 * @param maxnw [in] @a nw に呈羌できる帽胳の呵络眶 * @param r [in] 千急借妄インスタンス *  * @return @a nw に呈羌された帽胳铬输眶を手す.  * </JA> * <EN> * @brief  Get initial word hypotheses at the beginning. * * on N-gram based recogntion, the initial hypothesis is fixed to the tail * silence word.  Exception is that, in short-pause segmentation mode, the * initial hypothesis will be chosen from survived words on the last input * frame in the first pass. *  * @param nw [out] pointer to hold the initial word candidates * @param peseqlen [in] input frame length * @param maxnw [in] maximum number of words that can be stored in @a nw * @param r [in] recognition process instance *  * @return the number of words extracted and stored to @a nw. * </EN> * * @callgraph * @callergraph */intngram_firstwords(NEXTWORD **nw, int peseqlen, int maxnw, RecogProcess *r){  if (r->config->successive.enabled) {    /* in sp segment mode  */    if (r->sp_break_2_begin_word != WORD_INVALID) {      /* 介袋簿棱は 呵姜フレ〖ムに荒った帽胳トレリス惧の呵锑帽胳 */      /* the initial hypothesis is the best word survived on the last frame of	 the segment */      nw[0]->id = r->sp_break_2_begin_word;    } else {      /* 呵姜セグメント: 介袋簿棱は 帽胳の琐萨の痰不帽胳(=winfo->tail_silwid) */      /* we are in the last of sentence: initial hypothesis is word-end silence word */      nw[0]->id = r->lm->winfo->tail_silwid;    }  } else {    /* initial hypothesis should be word-end silence word */    nw[0]->id = r->lm->winfo->tail_silwid;  }#ifdef FIX_PENALTY  nw[0]->lscore = 0.0;#else  nw[0]->lscore = r->config->lmp.lm_penalty2;#endif  return 1;			/* number of words = 1 */}/**  * <JA> * @brief 肌帽胳簿棱礁圭を手す.  * * 涂えられた婶尸矢簿棱から·肌に儡鲁しうる帽胳の礁圭を手す. 悸狠には· * 妈1パスの冯蔡であるトレリス帽胳礁圭 bt 惧で·鸥倡傅の婶尸矢簿棱の呵姜帽胳の * ∈夸年された∷幌眉フレ〖ム hypo->estimated_next_t の涟稿に赂哼する * 帽胳礁圭を艰叫し·それらの N-gram 儡鲁澄唯を纷换して手す.  * 艰り叫された肌帽胳簿棱は·あらかじめ maxnm の墓さだけ * 挝拌が澄瘦されている nw に呈羌される.  *  * @param hypo [in] 鸥倡傅の矢簿棱 * @param nw [out] 肌帽胳铬输リストを呈羌する挝拌へのポインタ * @param maxnw [in] @a nw の呵络墓 * @param r [in] 千急借妄インスタンス *  * @return 藐叫され nw に呈羌された肌帽胳簿棱の眶を手す.  * </JA> * <EN> * @brief  Return the list of next word candidate. * * Given a partial sentence hypothesis "hypo", it returns the list of * next word candidates.  Actually, it extracts from word trellis the * list of words whose word-end node has survived near the estimated * beginning-of-word frame of last word "hypo->estimated_next_t", and store * them to "nw" with their N-gram probabilities.  *  * @param hypo [in] source partial sentence hypothesis * @param nw [out] pointer to store the list of next word candidates (should be already allocated) * @param maxnw [in] maximum number of words that can be stored to @a nw * @param r [in] recognition process instance *  * @return the number of extracted next word candidates in @a nw. * </EN> * @callgraph * @callergraph */intngram_nextwords(NODE *hypo, NEXTWORD **nw, int maxnw, RecogProcess *r){  int num, num2;  if (hypo->seqnum == 0) {    j_internal_error("ngram_nextwords: hypo contains no word\n");  }  /* 簿棱の夸年姜眉箕癸において backtrellis柒に荒っている帽胳を评る */  /* get survived words on backtrellis at the estimated end frame */  num = get_backtrellis_words(r, nw, hypo, hypo->estimated_next_t, hypo->bestt);  /* 鸥倡できない帽胳をチェックして嘲す */  /* exclude unallowed words */  num2 = limit_nw(nw, hypo, num, r->lm->winfo);  if (debug2_flag) jlog("DEBUG: ngram_decode: %d-%d=%d unfolded\n",num, num-num2,num2);  return(num2);}/**  * <JA> * @brief  减妄冉年 *  * 涂えられた婶尸矢簿棱が·矢∈すなわち玫瑚姜位∷として * 减妄材墙であるかどうかを手す. N-gram では矢片に滦炳する痰不帽胳 * (silhead) であれば减妄する.  *  * @param hypo [in] 婶尸矢簿棱 * @param r [in] 千急借妄インスタンス *  * @return 矢として减妄材墙であれば TRUE·稍材墙なら FALSE を手す.  * </JA> * <EN> * @brief  Acceptance check. *  * Return whether the given partial hypothesis is acceptable as a sentence * and can be treated as a final search candidate.  In N-gram mode, it checks * whether the last word is the beginning-of-sentence silence (silhead). *  * @param hypo [in] partial sentence hypothesis to be examined * @param r [in] recognition process instance *  * @return TRUE if acceptable as a sentence, or FALSE if not. * </EN> * @callgraph * @callergraph */booleanngram_acceptable(NODE *hypo, RecogProcess *r){  if (r->config->successive.enabled) {    /* 呵稿の簿棱が妈1パス呵锑簿棱の呵介の帽胳と办米しなければならない */    /* the last word should be equal to the first word on the best hypothesis on 1st pass */    if (hypo->seq[hypo->seqnum-1] == r->sp_break_2_end_word) {      return TRUE;    }  } else {    /* 呵稿の簿棱が矢片痰不帽胳でなければならない */    /* the last word should be head silence word */    if (hypo->seq[hypo->seqnum-1] == r->lm->winfo->head_silwid) {      return TRUE;    }  }  return FALSE;}/* end of file */

⌨️ 快捷键说明

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