libsent/src/hmminfo/rdhmmlist.c

Go to the documentation of this file.
00001 
00046 /*
00047  * Copyright (c) 1991-2006 Kawahara Lab., Kyoto University
00048  * Copyright (c) 2000-2005 Shikano Lab., Nara Institute of Science and Technology
00049  * Copyright (c) 2005-2006 Julius project team, Nagoya Institute of Technology
00050  * All rights reserved
00051  */
00052 
00053 #include <sent/stddefs.h>
00054 #include <sent/htk_hmm.h>
00055 #include <sent/ptree.h>
00056 
00057 #define MAXLINEINHMMLIST 256    
00058 
00059 
00067 boolean
00068 rdhmmlist(FILE *fp, HTK_HMM_INFO *hmminfo)
00069 {
00070   char *buf, *lname, *pname;
00071   HMM_Logical *new, *match;
00072   HTK_HMM_Data *mapped;
00073   boolean ok_flag = TRUE;
00074   int n;
00075   /* 1 column ... define HMM_Logical of the name as referring to HMM of the same name */
00076   /* 2 column ... define HMM_Logical of the name "$1" which has pointer to $2 */
00077 
00078   buf = (char *)mymalloc(MAXLINEINHMMLIST);
00079   n = 0;
00080   while (getl(buf, MAXLINEINHMMLIST, fp) != NULL) {
00081     n++;
00082     lname = first_token(buf);
00083     if (strlen(lname) >= MAX_HMMNAME_LEN) {
00084       j_error("Error: HMMList: %d: name too long: \"%s\"\n", n, lname);
00085     }
00086     pname = next_token_if_any();
00087     if (pname == NULL) {
00088       /* 1 column */
00089       mapped = htk_hmmdata_lookup_physical(hmminfo, lname);
00090       if (mapped == NULL) {
00091         j_printerr("Error: HMMList: line %d: physical HMM \"%s\" not found\n", n, lname);
00092         ok_flag = FALSE;
00093         continue;
00094       }
00095     } else {
00096       /* 2 column */
00097       mapped = htk_hmmdata_lookup_physical(hmminfo, pname);
00098       if (strlen(pname) >= MAX_HMMNAME_LEN) {
00099         j_error("Error: HMMList: %d: name too long: \"%s\"\n", n, pname);
00100       }
00101       if (mapped == NULL) {
00102         j_printerr("Error: HMMList: line %d: physical HMM \"%s\" not found\n", n, pname);
00103         ok_flag = FALSE;
00104         continue;
00105       }
00106     }
00107     /* create new HMM_Logical */
00108     new = (HMM_Logical *)mybmalloc2(sizeof(HMM_Logical), &(hmminfo->lroot));
00109     new->name = mybstrdup2(lname, &(hmminfo->lroot));
00110     new->is_pseudo = FALSE;
00111     new->body.defined = mapped;
00112     new->next = hmminfo->lgstart;
00113     hmminfo->lgstart = new;
00114     /* add index to search index tree */
00115     if (hmminfo->logical_root == NULL) {
00116       hmminfo->logical_root = aptree_make_root_node(new);
00117     } else {
00118       match = aptree_search_data(new->name, hmminfo->logical_root);
00119       if (strmatch(match->name, new->name)) {
00120         j_printerr("Error: HMMList: line %d: logical HMM \"%s\" duplicated\n", n, new->name);
00121         ok_flag = FALSE;
00122       } else {
00123         aptree_add_entry(new->name, new, match->name, &(hmminfo->logical_root));
00124       }
00125     }
00126     
00127   }
00128 
00129   hmminfo->totallogicalnum = n;
00130   free(buf);
00131   return(ok_flag);
00132 }

Generated on Tue Dec 26 16:16:33 2006 for Julius by  doxygen 1.5.0