graphout.c

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

C
2,136
字号
      jlog("DEBUG: merge_context: update left\n");      dst->left_lscore[d] = src->left_lscore[s];    }#ifdef GDEBUG    else {      jlog("DEBUG: merge_contexts: \"%s\"[%d..%d] already exist\n",	     wchmm_local->winfo->woutput[adding->wid], adding->lefttime, adding->righttime);    }#endif  }  /* right context */  for(s=0;s<src->rightwordnum;s++) {    adding = src->rightword[s];    if (adding->mark) continue;    /* direct link between dst and src will disapper to avoid unneccesary loop */    if (adding == dst) {#ifdef GDEBUG      jlog("DEBUG: merge_contexts: skipping direct link (src) -> (dst)\n");#endif      continue;    }    for(d=0;d<dst->rightwordnum;d++) {      if (dst->rightword[d]->mark) continue;      if (dst->rightword[d] == adding) {	break;      }    }    if (d >= dst->rightwordnum) { /* no rightword matched */      wordgraph_add_rightword(dst, adding, src->right_lscore[s]);#ifdef GDEBUG      jlog("DEBUG: merge_contexts: added \"%s\"[%d..%d] as a new right context\n",	     wchmm_local->winfo->woutput[adding->wid], adding->lefttime, adding->righttime);#endif      ret = TRUE;    } else if (dst->right_lscore[d] < src->right_lscore[s]) {      jlog("DEBUG: merge_context: update right\n");      dst->right_lscore[d] = src->right_lscore[s];    }#ifdef GDEBUG    else {      jlog("DEBUG: merge_contexts: \"%s\"[%d..%d] already exist\n",	     wchmm_local->winfo->woutput[adding->wid], adding->lefttime, adding->righttime);    }#endif  }    return(ret);}/**  * <JA> * 焊コンテキスト惧のあるグラフ帽胳を侍のグラフ帽胳に弥き垂える.  *  * @param wg [i/o] 拎侯滦据のグラフ帽胳 * @param from [in] 弥き垂え傅となる焊コンテキスト惧のグラフ帽胳 * @param to [in] 弥き垂え黎のグラフ帽胳 * @param lscore [in] 儡鲁咐胳スコア * </JA> * <EN> * Substitute a word at left context of a graph word to another. *  * @param wg [i/o] target graph word. * @param from [in] left context word to be substituted * @param to [in] substitution destination. * @param lscore [in] word connection score * </EN> */static voidswap_leftword(WordGraph *wg, WordGraph *from, WordGraph *to, LOGPROB lscore){  int i;  #ifdef GDEBUG  jlog("DEBUG: swapleft: replacing left of \"%s\"[%d..%d] from \"%s\"[%d..%d] to \"%s\"[%d..%d]...\n",	 wchmm_local->winfo->woutput[wg->wid], wg->lefttime, wg->righttime,	 wchmm_local->winfo->woutput[from->wid], from->lefttime, from->righttime,	 wchmm_local->winfo->woutput[to->wid], to->lefttime, to->righttime);#endif    for(i=0;i<wg->leftwordnum;i++) {    if (wg->leftword[i] == from) {      wg->leftword[i] = to;      wg->left_lscore[i] = lscore;    }  }}/**  * <JA> * 宝コンテキスト惧のあるグラフ帽胳を侍のグラフ帽胳に弥き垂える.  *  * @param wg [i/o] 拎侯滦据のグラフ帽胳 * @param from [in] 弥き垂え傅となる宝コンテキスト惧のグラフ帽胳 * @param to [in] 弥き垂え黎のグラフ帽胳 * @param lscore [in] 儡鲁咐胳スコア * </JA> * <EN> * Substitute a word at right context of a graph word to another. *  * @param wg [i/o] target graph word. * @param from [in] right context word to be substituted * @param to [in] substitution destination. * @param lscore [in] word connection score * </EN> */static voidswap_rightword(WordGraph *wg, WordGraph *from, WordGraph *to, LOGPROB lscore){  int i;  #ifdef GDEBUG  jlog("DEBUG: swapright: replacing right of \"%s\"[%d..%d] from \"%s\"[%d..%d] to \"%s\"[%d..%d]...\n",	 wchmm_local->winfo->woutput[wg->wid], wg->lefttime, wg->righttime,	 wchmm_local->winfo->woutput[from->wid], from->lefttime, from->righttime,	 wchmm_local->winfo->woutput[to->wid], to->lefttime, to->righttime);#endif  for(i=0;i<wg->rightwordnum;i++) {    if (wg->rightword[i] == from) {      wg->rightword[i] = to;      wg->right_lscore[i] = lscore;    }  }}/**  * <JA> * 焊コンテキストリスト面の脚剩を近殿する *  * @param wg [i/o] 拎侯滦据のグラフ帽胳 * </JA> * <EN> * Delete duplicate entries in left context list of a graph word. *  * @param wg [i/o] target graph word * </EN> */static voiduniq_leftword(WordGraph *wg){  int i, j, dst;  boolean ok;  dst = 0;  for(i=0;i<wg->leftwordnum;i++) {    ok = TRUE;    for(j=0;j<dst;j++) {      if (wg->leftword[i] == wg->leftword[j]) {	ok = FALSE;	break;      }    }    if (ok == TRUE) {      wg->leftword[dst] = wg->leftword[i];      wg->left_lscore[dst] = wg->left_lscore[i];      dst++;    }  }  wg->leftwordnum = dst;}/**  * <JA> * 宝コンテキストリスト面の脚剩を近殿する *  * @param wg [i/o] 拎侯滦据のグラフ帽胳 * </JA> * <EN> * Delete duplicate entries in right context list of a graph word. *  * @param wg [i/o] target graph word * </EN> */static voiduniq_rightword(WordGraph *wg){  int i, j, dst;  boolean ok;  dst = 0;  for(i=0;i<wg->rightwordnum;i++) {    ok = TRUE;    for(j=0;j<dst;j++) {      if (wg->rightword[i] == wg->rightword[j]) {	ok = FALSE;	break;      }    }    if (ok == TRUE) {      wg->rightword[dst] = wg->rightword[i];      wg->right_lscore[dst] = wg->right_lscore[i];      dst++;    }  }  wg->rightwordnum = dst;}/**  * <JA> * 焊宝のグラフ帽胳のコンテキストリストからそのグラフ帽胳极咳を久殿する.  *  * @param wg [in] 拎侯滦据のグラフ帽胳 * </JA> * <EN> * Remove the specified word graph from contexts of all left and right words. *  * @param wg [in] target graph word * </EN> */static voidwordgraph_remove_context(WordGraph *wg){  WordGraph *w;  int i,j,k;  if (wg == NULL) return;  for(i=0;i<wg->leftwordnum;i++) {    w = wg->leftword[i];    k=0;    for(j=0;j<w->rightwordnum;j++) {      if (w->rightword[j] != wg) {	if (j != k) {	  w->rightword[k] = w->rightword[j];	  w->right_lscore[k] = w->right_lscore[j];	}	k++;      }    }    w->rightwordnum = k;  }  for(i=0;i<wg->rightwordnum;i++) {    w = wg->rightword[i];    k=0;    for(j=0;j<w->leftwordnum;j++) {      if (w->leftword[j] != wg) {	if (j != k) {	  w->leftword[k] = w->leftword[j];	  w->left_lscore[k] = w->left_lscore[j];	}	k++;      }    }    w->leftwordnum = k;#ifdef GDEBUG2    if (w->leftwordnum == 0) {      jlog("DEBUG: leftword becomes 0 by remove_context\n");      put_wordgraph(jlog_get_fp(), w, wchmm_local->winfo);      jlog("DEBUG: by deleting its left context:\n");      put_wordgraph(jlog_get_fp(), wg, wchmm_local->winfo);    }#endif  }}/**  * <JA> * グラフ帽胳の焊宝のコンテキストをリンクする.  *  * @param wg [in] 拎侯滦据のグラフ帽胳 * </JA> * <EN> * link all words at the context of the graph word. *  * @param wg [in] target graph word * </EN> */static voidwordgraph_link_context(WordGraph *wg){  int i,j;  WordGraph *left, *right;    if (wg == NULL) return;  for(i=0;i<wg->leftwordnum;i++) {    left = wg->leftword[i];    if (left->mark) continue;    if (left == wg) continue;    for(j=0;j<wg->rightwordnum;j++) {      right = wg->rightword[j];      if (right->mark) continue;      if (right == wg) continue;      if (left == right) continue;      wordgraph_check_and_add_leftword(right, left, wg->left_lscore[i]);      wordgraph_check_and_add_rightword(left, right, wg->right_lscore[j]);    }  }}/**************************************************************//* Operations for organizing WordGraph set *//**  * <JA> * 帽胳グラフ面の猴近マ〖クの烧いた帽胳を猴近する.  *  * @param rootp [i/o] 帽胳グラフのル〖トノ〖ドへのポインタ *  * @return 猴近された帽胳の眶 * </JA> * <EN> * Actually erase the marked words in word graph. *  * @param rootp [i/o] pointer to root node of a word graph *  * @return the number of erased words. * </EN> */static intwordgraph_exec_erase(WordGraph **rootp){  WordGraph *wg, *we, *wtmp;  int count;  if (*rootp == NULL) return(0);    wg = *rootp;  count = 0;  while (wg != NULL) {    we = wg->next;    while(we != NULL && we->mark == TRUE) {      wtmp = we->next;      wordgraph_free(we); count++;      we = wtmp;    }    wg->next = we;    wg = we;  }  if ((*rootp)->mark == TRUE) {    wtmp = (*rootp)->next;    wordgraph_free(*rootp); count++;    *rootp = wtmp;  }  return(count);}/**  * <JA> * グラフソ〖ト脱 qsort コ〖ルバック *  * @param x [in] 妥燎1 * @param y [in] 妥燎2 *  * @return x > y なら 1, x < y なら -1, x = y なら 0 を手す.  * </JA> * <EN> * qsort callback for word sorting. *  * @param x [in] element 1 * @param y [in] element 2 *  * @return 1 if x>y, -1 if x<y, 0 if x = y. * </EN> */static intcompare_lefttime(WordGraph **x, WordGraph **y){  if ((*x)->lefttime > (*y)->lefttime) return 1;  else if ((*x)->lefttime < (*y)->lefttime) return -1;  else {    if ((*x)->righttime > (*y)->righttime) return 1;    else if ((*x)->righttime < (*y)->righttime) return -1;    else {      if ((*x)->fscore_head < (*y)->fscore_head) return 1;      else if ((*x)->fscore_head > (*y)->fscore_head) return -1;      else return 0;    }  }}/**  * <JA> * 帽胳グラフ柒の链帽胳を倡幌箕粗界にソ〖トし·奶し戎规をつける.  *  * @param rootp [i/o] 帽胳グラフのル〖トノ〖ドへのポインタ呈羌眷疥 * @param r [i/o] 千急借妄インスタンス * </JA> * <EN> * Sort words by left time and annotate sequencial id for them in a word graph. *  * @param rootp [i/o] address of pointer to root node of a word graph * @param r [i/o] recognition process instance * </EN> * * @callgraph * @callergraph *  */intwordgraph_sort_and_annotate_id(WordGraph **rootp, RecogProcess *r){  WordGraph *wg;  int cnt;  WordGraph **wlist;  int i;  WordGraph *wo;  /* count total number of words in the graph */  cnt = 0;  for(wg=*rootp;wg;wg=wg->next) cnt++;  if (cnt == 0) return 0;  /* sort them by lefttime */  wlist = (WordGraph **)mymalloc(sizeof(WordGraph *) * cnt);  i = 0;  for(wg=*rootp;wg;wg=wg->next) {    wlist[i++] = wg;  }  qsort(wlist, cnt, sizeof(WordGraph *), (int (*)(const void *, const void *))compare_lefttime);  /* annotated id and re-order the link by the id */  wo = NULL;  for(i=cnt-1;i>=0;i--) {    wg = wlist[i];    wg->id = i;    wg->next = wo;    wo = wg;  }  *rootp = wo;  free(wlist);  return cnt;}/**  * <JA> * 帽胳グラフ柒の链帽胳を链て豺庶する. 

⌨️ 快捷键说明

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