Julius 4.2
libsent/src/dfa/init_dfa.c
説明を見る。
00001 
00026 /*
00027  * Copyright (c) 1991-2011 Kawahara Lab., Kyoto University
00028  * Copyright (c) 2000-2005 Shikano Lab., Nara Institute of Science and Technology
00029  * Copyright (c) 2005-2011 Julius project team, Nagoya Institute of Technology
00030  * All rights reserved
00031  */
00032 
00033 #include <sent/stddefs.h>
00034 #include <sent/dfa.h>
00035 #include <sent/vocabulary.h>
00036 #include <sent/htk_hmm.h>
00037 
00038 /* read in dfa info from file */
00045 boolean
00046 init_dfa(DFA_INFO *dinfo, char *filename)
00047 {
00048   FILE *fd;
00049   
00050   if ((fd = fopen_readfile(filename)) == NULL) {
00051     jlog("Error: init_dfa: failed to open %s\n",filename);
00052     return FALSE;
00053   }
00054   if (!rddfa(fd, dinfo)) {
00055     jlog("Error; init_dfa: error in reading %s\n",filename);
00056     return FALSE;
00057   }
00058   if (fclose_readfile(fd) == -1) {
00059     jlog("Error: init_dfa: failed to close %s\n", filename);
00060     return FALSE;
00061   }
00062 
00063   return TRUE;
00064 }
00065 
00073 boolean
00074 make_dfa_voca_ref(DFA_INFO *dinfo, WORD_INFO *winfo)
00075 {
00076   WORD_ID i;
00077   boolean ok_flag = TRUE;
00078 
00079   /* word -> terminal symbol */
00080   for (i = 0; i < winfo->num; i++) {
00081     winfo->wton[i] = dfa_symbol_lookup(dinfo, winfo->wname[i]);
00082     if (winfo->wton[i] == WORD_INVALID) {
00083       /* error: not found */
00084       jlog("Error: init_dfa: no such terminal symbol \"%s\" in DFA grammar\n",
00085              winfo->wname[i]);
00086       put_voca(jlog_get_fp(), winfo, i);
00087       ok_flag = FALSE;
00088     }
00089   }
00090 
00091   if (ok_flag) {
00092     /* terminal symbol -> word */
00093     make_terminfo(&(dinfo->term), dinfo, winfo);
00094   }
00095 
00096   return ok_flag;
00097 }
00098 
00106 void
00107 dfa_find_pause_word(DFA_INFO *dfa, WORD_INFO *winfo, HTK_HMM_INFO *hmminfo)
00108 {
00109   int i, t,p;
00110   WORD_ID w;
00111 
00112   dfa->sp_id = WORD_INVALID;
00113   dfa->is_sp = (boolean *)mymalloc(sizeof(boolean) * dfa->term_num);
00114   for(t=0;t<dfa->term_num;t++) dfa->is_sp[t] = FALSE;
00115   
00116   for(t=0;t<dfa->term_num;t++) {
00117     for(i=0;i<dfa->term.wnum[t]; i++) {
00118       w = dfa->term.tw[t][i];
00119       p = 0;
00120       while(p < winfo->wlen[w] && winfo->wseq[w][p] == hmminfo->sp) p++;
00121       if (p >= winfo->wlen[w]) {        /* w consists of only hmminfo->sp model */
00122         dfa->is_sp[t] = TRUE;
00123         if (dfa->sp_id == WORD_INVALID) dfa->sp_id = w;
00124         break;                  /* mark this category if at least 1 sp_word was found */
00125       }
00126     }
00127   }
00128 }
00129 
00137 boolean
00138 dfa_pause_word_append(DFA_INFO *dst, DFA_INFO *src, int coffset)
00139 {
00140   int i;
00141   /* dst info must be already appended */
00142   /* [coffset..dst->term_num-1] is the new categories */
00143   if (dst->term_num - coffset != src->term_num) {
00144     jlog("Error: init_dfa: appended term num not match!\n");
00145     return FALSE;
00146   }
00147   
00148   if (dst->is_sp == NULL) {
00149     dst->is_sp = (boolean *)mymalloc(sizeof(boolean) * dst->term_num);
00150   } else {
00151     dst->is_sp = (boolean *)myrealloc(dst->is_sp, sizeof(boolean) * dst->term_num);
00152   }
00153   for(i=0;i<src->term_num;i++) {
00154     dst->is_sp[coffset+i] = src->is_sp[i];
00155   }
00156   if (dst->sp_id == WORD_INVALID) {
00157     if (src->sp_id != WORD_INVALID) {/* src has pause word */
00158       dst->sp_id = src->sp_id;
00159     }
00160   }
00161 
00162   return TRUE;
00163 }
00164