libsent/src/hmminfo/rdhmmdef_data.c

説明を見る。
00001 
00017 /*
00018  * Copyright (c) 1991-2006 Kawahara Lab., Kyoto University
00019  * Copyright (c) 2000-2005 Shikano Lab., Nara Institute of Science and Technology
00020  * Copyright (c) 2005-2006 Julius project team, Nagoya Institute of Technology
00021  * All rights reserved
00022  */
00023 
00024 #include <sent/stddefs.h>
00025 #include <sent/htk_hmm.h>
00026 
00027 extern char *rdhmmdef_token;    
00028 
00034 HTK_HMM_Data *
00035 htk_hmmdata_new(HTK_HMM_INFO *hmminfo)
00036 {
00037   HTK_HMM_Data *new;
00038 
00039   new = (HTK_HMM_Data *)mybmalloc2(sizeof(HTK_HMM_Data), &(hmminfo->mroot));
00040 
00041   new->name = NULL;
00042   new->state_num = 0;
00043   new->s = NULL;
00044   new->tr = NULL;
00045   new->next = NULL;
00046 
00047   return(new);
00048 }
00049 
00056 void
00057 htk_hmmdata_add(HTK_HMM_INFO *hmm, HTK_HMM_Data *new)
00058 {
00059   HTK_HMM_Data *match;
00060   /* link data structure */
00061   new->next = hmm->start;
00062   hmm->start = new;
00063 
00064   if (new->name == NULL) {
00065     /* HMM must have a name */
00066     rderr("Error: HMM has no name");
00067   } else {
00068     /* add index to search index tree */
00069     if (hmm->physical_root == NULL) {
00070       hmm->physical_root = aptree_make_root_node(new);
00071     } else {
00072       match = aptree_search_data(new->name, hmm->physical_root);
00073       if (strmatch(match->name, new->name)) {
00074         /* HMM of the same name should not be defined */
00075         j_printerr("Error: HMM \"%s\" is defined more than twice\n", new->name);
00076         rderr(NULL);
00077       } else {
00078         aptree_add_entry(new->name, new, match->name, &(hmm->physical_root));
00079       }
00080     }
00081   }
00082 }
00083 
00098 static HTK_HMM_Data *
00099 htk_hmmdata_read(FILE *fp, HTK_HMM_INFO *hmm)
00100 {
00101   HTK_HMM_Data *new;
00102   int i;
00103   short sid;
00104 
00105   new = htk_hmmdata_new(hmm);
00106 
00107   /* begin tag */
00108   if (!currentis("BEGINHMM")) rderr("<BEGINHMM> not found");
00109   read_token(fp);
00110 
00111   /* read global opt if any */
00112   /* read_global_opt(fp, &(new->opt)); */
00113 
00114   /* num of state */
00115   if (!currentis("NUMSTATES")) rderr("<NUMSTATES> not found");
00116   read_token(fp);
00117   NoTokErr("state num not found\n");
00118   new->state_num = atoi(rdhmmdef_token);
00119   read_token(fp);
00120 
00121   /* malloc state */
00122   new->s = (HTK_HMM_State **)mybmalloc2(sizeof(HTK_HMM_State *) * new->state_num, &(hmm->mroot));
00123   for(i=0;i<new->state_num;i++) {
00124     new->s[i] = NULL;
00125   }
00126 
00127   /* read/set each state info */
00128   for (;;) {
00129     if (!currentis("STATE")) break;
00130     read_token(fp); NoTokErr("STATE id not found");
00131     sid = atoi(rdhmmdef_token) - 1;
00132     read_token(fp);
00133     new->s[sid] = get_state_data(fp, hmm);
00134   }
00135 
00136   /* read/set transition info */
00137   new->tr = get_trans_data(fp, hmm);
00138   if ((new->tr)->statenum != new->state_num) {
00139     rderr("# of transition != # of state");
00140   }
00141 
00142   /* read/set duration */
00143 
00144   /* end tag */
00145   if (!currentis("ENDHMM")) rderr("<ENDHMM> not found");
00146   read_token(fp);
00147 
00148   return(new);
00149 }  
00150 
00158 void
00159 def_HMM(char *name, FILE *fp, HTK_HMM_INFO *hmm)
00160 {
00161   HTK_HMM_Data *new;
00162 
00163   /* read in HMM model data from fp, and return newly malloced HTK_HMM_Data */
00164   new = htk_hmmdata_read(fp, hmm);
00165 
00166   /* set name and add the new data to the main structure */
00167   new->name = name;
00168   htk_hmmdata_add(hmm, new);
00169 }

Juliusに対してTue Dec 26 16:19:28 2006に生成されました。  doxygen 1.5.0