Julius 4.2
libsent/src/hmminfo/check_hmm_restriction.c
説明を見る。
00001 
00040 /*
00041  * Copyright (c) 1991-2011 Kawahara Lab., Kyoto University
00042  * Copyright (c) 2000-2005 Shikano Lab., Nara Institute of Science and Technology
00043  * Copyright (c) 2005-2011 Julius project team, Nagoya Institute of Technology
00044  * All rights reserved
00045  */
00046 
00047 #include <sent/stddefs.h>
00048 #include <sent/htk_hmm.h>
00049 #include <sent/htk_param.h>
00050 #include <sent/hmm.h>
00051 
00062 boolean
00063 htk_hmm_has_several_arc_on_edge(HTK_HMM_INFO *hmminfo)
00064 {
00065   HTK_HMM_Data *dt;
00066   HTK_HMM_Trans *t;
00067   boolean flag;
00068   int i;
00069 
00070   for (dt = hmminfo->start; dt; dt = dt->next) {
00071     t = dt->tr;
00072     flag = FALSE;
00073     for (i=0;i<t->statenum;i++) {
00074       if (t->a[0][i] != LOG_ZERO) {
00075         if (flag == FALSE) {
00076           flag = TRUE;
00077         } else {
00078           jlog("Stat: check_hmm_restriction: an HMM with several arcs from initial state found: \"%s\"\n", dt->name);
00079           return (TRUE);
00080         }
00081       }
00082     }
00083     flag = FALSE;
00084     for (i=0;i<t->statenum;i++) {
00085       if (t->a[i][t->statenum-1] != LOG_ZERO) {
00086         if (flag == FALSE) {
00087           flag = TRUE;
00088         } else {
00089           jlog("Stat: check_hmm_restriction: an HMM with several arcs to final state found: \"%s\"\n", dt->name);
00090           return (TRUE);
00091         }
00092       }
00093     }
00094   }
00095 
00096   return FALSE;
00097 }
00098 
00108 static boolean
00109 trans_ok_p(HTK_HMM_Trans *t)
00110 {
00111   int i;
00112   int tflag;
00113   int retflag = TRUE;
00114 
00115   /* check arc to initial state */
00116   tflag = FALSE;
00117   for (i=0;i<t->statenum;i++) {
00118     if (t->a[i][0] != LOG_ZERO) {
00119       tflag = TRUE;
00120       break;
00121     }
00122   }
00123   if (tflag) {
00124     jlog("Error: check_hmm_restriction: transition to initial state is not allowed\n");
00125     retflag = FALSE;
00126   }
00127   /* check arc from final state */
00128   tflag = FALSE;
00129   for (i=0;i<t->statenum;i++) {
00130     if (t->a[t->statenum-1][i] != LOG_ZERO) {
00131       tflag = TRUE;
00132       break;
00133     }
00134   }
00135   if (tflag) {
00136     jlog("Error: check_hmm_restriction: transition from final state is not allowed\n");
00137     retflag = FALSE;
00138   }
00139   /* check if arc from/to initial/final state exist */
00140   tflag = FALSE;
00141   for (i=0;i<t->statenum;i++) {
00142     if (t->a[0][i] != LOG_ZERO) {
00143       tflag = TRUE;
00144       break;
00145     }
00146   }
00147   if (tflag == FALSE) {
00148     jlog("Error: check_hmm_restriction: no transition from initial state\n");
00149     retflag = FALSE;
00150   }
00151   tflag = FALSE;
00152   for (i=0;i<t->statenum;i++) {
00153     if (t->a[i][t->statenum-1] != LOG_ZERO) {
00154       tflag = TRUE;
00155       break;
00156     }
00157   }
00158   if (tflag == FALSE) {
00159     jlog("Error: check_hmm_restriction: no transition to final state\n");
00160     retflag = FALSE;
00161   }
00162     
00163   return(retflag);
00164 }
00165 
00173 boolean
00174 check_hmm_limit(HTK_HMM_Data *dt)
00175 {
00176   boolean return_flag = TRUE;
00177 
00178   if (trans_ok_p(dt->tr) == FALSE) {
00179     return_flag = FALSE;
00180     jlog("Error: check_hmm_restriction: HMM \"%s\" has unsupported arc.\n", dt->name);
00181     put_htk_trans(jlog_get_fp(), dt->tr);
00182   }
00183   if (dt->tr->statenum < 3) {
00184     return_flag = FALSE;
00185     jlog("Error: HMM \"%s\" has no output state (statenum=%d)\n", dt->name, dt->tr->statenum);
00186   }
00187   return(return_flag);
00188 }
00189 
00197 boolean
00198 check_all_hmm_limit(HTK_HMM_INFO *hmminfo)
00199 {
00200   HTK_HMM_Data *dt;
00201   boolean return_flag = TRUE;
00202 
00203   for (dt = hmminfo->start; dt; dt = dt->next) {
00204     if (check_hmm_limit(dt) == FALSE) {
00205       return_flag = FALSE;
00206     }
00207   }
00208   return(return_flag);
00209 }
00210 
00211 
00231 boolean
00232 is_skippable_model(HTK_HMM_Data *d)
00233 {
00234   if (d->tr->a[0][d->tr->statenum-1] != LOG_ZERO) {
00235     return TRUE;
00236   }
00237   return FALSE;
00238 }