[Julius-cvs 267] CVS update: julius4/libsent/src/hmminfo

Back to archive index

sumom****@users***** sumom****@users*****
2008年 9月 30日 (火) 12:58:18 JST


Index: julius4/libsent/src/hmminfo/cdset.c
diff -u julius4/libsent/src/hmminfo/cdset.c:1.3 julius4/libsent/src/hmminfo/cdset.c:1.4
--- julius4/libsent/src/hmminfo/cdset.c:1.3	Wed Feb 13 17:40:07 2008
+++ julius4/libsent/src/hmminfo/cdset.c	Tue Sep 30 12:58:18 2008
@@ -60,7 +60,7 @@
  * @author Akinobu LEE
  * @date   Tue Feb 15 17:58:54 2005
  *
- * $Revision: 1.3 $
+ * $Revision: 1.4 $
  * 
  */
 /*
@@ -204,7 +204,7 @@
  * @return TRUE if newly registered, FALSE if the specified physical %HMM already exists in the pseudo phone.
  */
 boolean
-regist_cdset(APATNODE **root, HTK_HMM_Data *d, char *cdname)
+regist_cdset(APATNODE **root, HTK_HMM_Data *d, char *cdname, BMALLOC_BASE **mroot)
 {
   boolean need_new;
   CD_State_Set *tmp;
@@ -273,9 +273,9 @@
     lset->tr = d->tr;
     /* add to search index tree */
     if (*root == NULL) {
-      *root = aptree_make_root_node(lset);
+      *root = aptree_make_root_node(lset, mroot);
     } else {
-      aptree_add_entry(lset->name, lset, lmatch->name, root);
+      aptree_add_entry(lset->name, lset, lmatch->name, root, mroot);
     }
 
     changed = TRUE;
@@ -309,39 +309,6 @@
 }
 
 /** 
- * Remove an pseudo phone set entry from index tree
- * 
- * @param hmminfo 
- * @param cdname 
- * 
- * @return 
- */
-boolean
-remove_cdset(HTK_HMM_INFO *hmminfo, char *cdname)
-{
-  CD_Set *lmatch;
-  
-  if (hmminfo->cdset_info.cdtree == NULL) return TRUE;
-
-  lmatch = aptree_search_data(cdname, hmminfo->cdset_info.cdtree);
-  if (lmatch != NULL && strmatch(lmatch->name, cdname)) {
-    jlog("Stat: cdset: [%s] found, removed from cdset\n", lmatch->name);
-    /* found */
-    /*
-    for(j=1;j<lmatch->state_num-1;j++) {
-      free(lmatch->stateset[j].s);
-    }
-    free(lmatch->stateset);
-    */
-    aptree_remove_entry(cdname, &(hmminfo->cdset_info.cdtree));
-  } else {
-    return FALSE;
-  }
-  return TRUE;
-}
-  
-
-/** 
  * Construct the whole pseudo %HMM information, and also add them to the logical Triphone tree.
  * 
  * @param hmminfo [i/o] %HMM definition data.  The generated data will also
@@ -361,19 +328,19 @@
      for 1st pass (word end) */
   for(lg = hmminfo->lgstart; lg; lg = lg->next) {
     if (lg->is_pseudo) continue;
-    regist_cdset(&(hmminfo->cdset_info.cdtree), lg->body.defined, leftcenter_name(lg->name, buf));
+    regist_cdset(&(hmminfo->cdset_info.cdtree), lg->body.defined, leftcenter_name(lg->name, buf), &(hmminfo->cdset_root));
   }
   /* right-context set: "a+o" for /b-a+o/, /t-a+o/, ...
      for 2nd pass (word beginning) */
   for(lg = hmminfo->lgstart; lg; lg = lg->next) {
     if (lg->is_pseudo) continue;
-    regist_cdset(&(hmminfo->cdset_info.cdtree), lg->body.defined, rightcenter_name(lg->name, buf));
+    regist_cdset(&(hmminfo->cdset_info.cdtree), lg->body.defined, rightcenter_name(lg->name, buf), &(hmminfo->cdset_root));
   }
   /* both-context set: "a" for all triphone with same base phone "a"
      for 1st pass (1 phoneme word, with no previous word hypo.) */
   for(lg = hmminfo->lgstart; lg; lg = lg->next) {
     if (lg->is_pseudo) continue;
-    regist_cdset(&(hmminfo->cdset_info.cdtree), lg->body.defined, center_name(lg->name, buf));
+    regist_cdset(&(hmminfo->cdset_info.cdtree), lg->body.defined, center_name(lg->name, buf), &(hmminfo->cdset_root));
   }
 
   /* now that cdset is completely built */
@@ -409,11 +376,11 @@
  * @param root [i/o] pointer to hold the root index pointer
  */
 void
-free_cdset(APATNODE **root)
+free_cdset(APATNODE **root, BMALLOC_BASE **mroot)
 {
   if (*root != NULL) {
     aptree_traverse_and_do(*root, callback_free_lcdset_content);
-    free_aptree(*root);
+    mybfree2(mroot);
     *root = NULL;
   }
 }
Index: julius4/libsent/src/hmminfo/chkhmmlist.c
diff -u julius4/libsent/src/hmminfo/chkhmmlist.c:1.3 julius4/libsent/src/hmminfo/chkhmmlist.c:1.4
--- julius4/libsent/src/hmminfo/chkhmmlist.c:1.3	Wed Feb 13 17:40:07 2008
+++ julius4/libsent/src/hmminfo/chkhmmlist.c	Tue Sep 30 12:58:18 2008
@@ -26,7 +26,7 @@
  * @author Akinobu LEE
  * @date   Tue Feb 15 19:17:51 2005
  *
- * $Revision: 1.3 $
+ * $Revision: 1.4 $
  * 
  */
 /*
@@ -66,8 +66,8 @@
     new->endflag = FALSE;
     new->name = (char *)mybmalloc2(strlen(p)+1, &(hmminfo->mroot));
     strcpy(new->name, p);
-    if (root == NULL) root = aptree_make_root_node(new);
-    else aptree_add_entry(new->name, new, match->name, &root);
+    if (root == NULL) root = aptree_make_root_node(new, &(hmminfo->mroot));
+    else aptree_add_entry(new->name, new, match->name, &root, &(hmminfo->mroot));
     n++;
   }
   hmminfo->basephone.num = n;
@@ -223,8 +223,8 @@
   }
   new = (char *)mybmalloc2(strlen(lostname)+1, &(hmminfo->mroot));
   strcpy(new, lostname);
-  if (error_root == NULL) error_root = aptree_make_root_node(new);
-  else aptree_add_entry(new, new, match, &error_root);
+  if (error_root == NULL) error_root = aptree_make_root_node(new, &(hmminfo->mroot));
+  else aptree_add_entry(new, new, match, &error_root, &(hmminfo->mroot));
 
   error_num++;
 }
Index: julius4/libsent/src/hmminfo/hmm_lookup.c
diff -u julius4/libsent/src/hmminfo/hmm_lookup.c:1.3 julius4/libsent/src/hmminfo/hmm_lookup.c:1.4
--- julius4/libsent/src/hmminfo/hmm_lookup.c:1.3	Wed Feb 13 17:40:07 2008
+++ julius4/libsent/src/hmminfo/hmm_lookup.c	Tue Sep 30 12:58:18 2008
@@ -34,7 +34,7 @@
  * @author Akinobu LEE
  * @date   Tue Feb 15 22:34:30 2005
  *
- * $Revision: 1.3 $
+ * $Revision: 1.4 $
  * 
  */
 /*
@@ -143,9 +143,9 @@
     new->next = hmminfo->lgstart;
     hmminfo->lgstart = new;
     if (hmminfo->logical_root == NULL) {
-      hmminfo->logical_root = aptree_make_root_node(new);
+      hmminfo->logical_root = aptree_make_root_node(new, &(hmminfo->lroot));
     } else {
-      aptree_add_entry(new->name, new, match->name, &(hmminfo->logical_root));
+      aptree_add_entry(new->name, new, match->name, &(hmminfo->logical_root), &(hmminfo->lroot));
     }
   }
 
@@ -192,9 +192,9 @@
     new->next = hmminfo->lgstart;
     hmminfo->lgstart = new;
     if (hmminfo->logical_root == NULL) {
-      hmminfo->logical_root = aptree_make_root_node(new);
+      hmminfo->logical_root = aptree_make_root_node(new, &(hmminfo->lroot));
     } else {
-      aptree_add_entry(new->name, new, match->name, &(hmminfo->logical_root));
+      aptree_add_entry(new->name, new, match->name, &(hmminfo->logical_root), &(hmminfo->lroot));
     }
     hmminfo->totalpseudonum++;
   }
Index: julius4/libsent/src/hmminfo/init_phmm.c
diff -u julius4/libsent/src/hmminfo/init_phmm.c:1.3 julius4/libsent/src/hmminfo/init_phmm.c:1.4
--- julius4/libsent/src/hmminfo/init_phmm.c:1.3	Mon Jul  7 14:50:11 2008
+++ julius4/libsent/src/hmminfo/init_phmm.c	Tue Sep 30 12:58:18 2008
@@ -12,7 +12,7 @@
  * @author Akinobu LEE
  * @date   Tue Feb 15 23:05:33 2005
  *
- * $Revision: 1.3 $
+ * $Revision: 1.4 $
  * 
  */
 /*
@@ -39,6 +39,7 @@
 
   new->mroot = NULL;
   new->lroot = NULL;
+  new->cdset_root = NULL;
   new->tmp_mixnum = NULL;
 
   new->opt.stream_info.num = 0;
@@ -96,20 +97,8 @@
 hmminfo_free(HTK_HMM_INFO *hmm)
 {
   /* cdset does not use bmalloc, so free them separately */
-  free_cdset(&(hmm->cdset_info.cdtree));
+  free_cdset(&(hmm->cdset_info.cdtree), &(hmm->cdset_root));
 
-  /* free lookup indexes */
-  free_aptree(hmm->tr_root);
-  free_aptree(hmm->sw_root);
-  free_aptree(hmm->vr_root);
-  free_aptree(hmm->pdf_root);
-  free_aptree(hmm->dn_root);
-  free_aptree(hmm->st_root);
-  free_aptree(hmm->physical_root);
-  free_aptree(hmm->logical_root);
-  free_aptree(hmm->codebook_root);
-  free_aptree(hmm->basephone.root);
-  
   /* free all memory that has been allocated by bmalloc2() */
   if (hmm->mroot != NULL) mybfree2(&(hmm->mroot));
   if (hmm->lroot != NULL) mybfree2(&(hmm->lroot));
@@ -135,6 +124,7 @@
 {
   FILE *fp;
   boolean ok_p;
+  boolean binary;
 
   ok_p = FALSE;
 
@@ -180,15 +170,41 @@
       jlog("Error: init_phmm: failed to open %s\n",namemapfile);
       return FALSE;
     }
-    if (rdhmmlist(fp, hmminfo) == FALSE) {
-      jlog("Error: init_phmm: HMMList \"%s\" read error\n",namemapfile);
-      return FALSE;
+    /* detect binary / ascii by the first 4 bytes */
+    {
+      int x;
+      if (myfread(&x, sizeof(int), 1, fp) < 1) {
+	jlog("Error: init_phmm: failed to read %s\n", namemapfile);
+	return FALSE;
+      }
+      if (x == 0) {
+	binary = TRUE;
+      } else {
+	binary = FALSE;
+	myfrewind(fp);
+      }
+    }
+    if (binary) {
+      /* binary format */
+      jlog("Stat: init_phmm: loading binary hmmlist\n");
+      if (load_hmmlist_bin(fp, hmminfo) == FALSE) {
+	jlog("Error: init_phmm: HMMList \"%s\" read error\n",namemapfile);
+	return FALSE;
+      }
+    } else {
+      /* ascii format */
+      jlog("Stat: init_phmm: loading ascii hmmlist\n");
+      if (rdhmmlist(fp, hmminfo) == FALSE) {
+	jlog("Error: init_phmm: HMMList \"%s\" read error\n",namemapfile);
+	return FALSE;
+      }
     }
     if (fclose_readfile(fp) < 0) {
       jlog("Error: init_phmm: failed to close %s\n", namemapfile);
       return FALSE;
     }
     jlog("Stat: init_phmm: logical names: %5d in HMMList\n", hmminfo->totallogicalnum);
+
   } else {
     /* add all names of physical HMMs as logical names */
     hmm_add_physical_to_logical(hmminfo);
Index: julius4/libsent/src/hmminfo/rdhmmdef_data.c
diff -u julius4/libsent/src/hmminfo/rdhmmdef_data.c:1.2 julius4/libsent/src/hmminfo/rdhmmdef_data.c:1.3
--- julius4/libsent/src/hmminfo/rdhmmdef_data.c:1.2	Tue Dec 18 17:45:51 2007
+++ julius4/libsent/src/hmminfo/rdhmmdef_data.c	Tue Sep 30 12:58:18 2008
@@ -12,7 +12,7 @@
  * @author Akinobu LEE
  * @date   Wed Feb 16 01:12:19 2005
  *
- * $Revision: 1.2 $
+ * $Revision: 1.3 $
  * 
  */
 /*
@@ -68,7 +68,7 @@
   } else {
     /* add index to search index tree */
     if (hmm->physical_root == NULL) {
-      hmm->physical_root = aptree_make_root_node(new);
+      hmm->physical_root = aptree_make_root_node(new, &(hmm->mroot));
     } else {
       match = aptree_search_data(new->name, hmm->physical_root);
       if (match != NULL && strmatch(match->name, new->name)) {
@@ -76,7 +76,7 @@
 	jlog("Error: rdhmmdef_data: HMM \"%s\" is defined more than twice\n", new->name);
 	rderr(NULL);
       } else {
-	aptree_add_entry(new->name, new, match->name, &(hmm->physical_root));
+	aptree_add_entry(new->name, new, match->name, &(hmm->physical_root), &(hmm->mroot));
       }
     }
   }
Index: julius4/libsent/src/hmminfo/rdhmmdef_dens.c
diff -u julius4/libsent/src/hmminfo/rdhmmdef_dens.c:1.2 julius4/libsent/src/hmminfo/rdhmmdef_dens.c:1.3
--- julius4/libsent/src/hmminfo/rdhmmdef_dens.c:1.2	Tue Dec 18 17:45:51 2007
+++ julius4/libsent/src/hmminfo/rdhmmdef_dens.c	Tue Sep 30 12:58:18 2008
@@ -12,7 +12,7 @@
  * @author Akinobu LEE
  * @date   Wed Feb 16 01:43:43 2005
  *
- * $Revision: 1.2 $
+ * $Revision: 1.3 $
  * 
  */
 /*
@@ -22,7 +22,7 @@
  * All rights reserved
  */
 
-/* $Id: rdhmmdef_dens.c,v 1.2 2007/12/18 08:45:51 sumomo Exp $ */
+/* $Id: rdhmmdef_dens.c,v 1.3 2008/09/30 03:58:18 sumomo Exp $ */
 
 #include <sent/stddefs.h>
 #include <sent/htk_hmm.h>
@@ -88,14 +88,14 @@
   if (new->name != NULL) {
     /* add index to search index tree */
     if (hmm->dn_root == NULL) {
-      hmm->dn_root = aptree_make_root_node(new);
+      hmm->dn_root = aptree_make_root_node(new, &(hmm->mroot));
     } else {
       match = aptree_search_data(new->name, hmm->dn_root);
       if (match != NULL && strmatch(match->name, new->name)) {
 	jlog("Error: rdhmmdef_dens: ~m \"%s\" is already defined\n", new->name);
 	rderr(NULL);
       } else {
-	aptree_add_entry(new->name, new, match->name, &(hmm->dn_root));
+	aptree_add_entry(new->name, new, match->name, &(hmm->dn_root), &(hmm->mroot));
       }
     }
   }
Index: julius4/libsent/src/hmminfo/rdhmmdef_mpdf.c
diff -u julius4/libsent/src/hmminfo/rdhmmdef_mpdf.c:1.1 julius4/libsent/src/hmminfo/rdhmmdef_mpdf.c:1.2
--- julius4/libsent/src/hmminfo/rdhmmdef_mpdf.c:1.1	Mon Jul  7 14:50:11 2008
+++ julius4/libsent/src/hmminfo/rdhmmdef_mpdf.c	Tue Sep 30 12:58:18 2008
@@ -12,7 +12,7 @@
  * @author Akinobu LEE
  * @date   Wed Feb 16 01:43:43 2005
  *
- * $Revision: 1.1 $
+ * $Revision: 1.2 $
  * 
  */
 /*
@@ -68,14 +68,14 @@
   if (new->name != NULL) {
     /* add index to search index tree */
     if (hmm->pdf_root == NULL) {
-      hmm->pdf_root = aptree_make_root_node(new);
+      hmm->pdf_root = aptree_make_root_node(new, &(hmm->mroot));
     } else {
       match = aptree_search_data(new->name, hmm->pdf_root);
       if (match != NULL && strmatch(match->name, new->name)) {
 	jlog("Error: rdhmmdef_dens: ~m \"%s\" is already defined\n", new->name);
 	rderr(NULL);
       } else {
-	aptree_add_entry(new->name, new, match->name, &(hmm->pdf_root));
+	aptree_add_entry(new->name, new, match->name, &(hmm->pdf_root), &(hmm->mroot));
       }
     }
   }
Index: julius4/libsent/src/hmminfo/rdhmmdef_state.c
diff -u julius4/libsent/src/hmminfo/rdhmmdef_state.c:1.3 julius4/libsent/src/hmminfo/rdhmmdef_state.c:1.4
--- julius4/libsent/src/hmminfo/rdhmmdef_state.c:1.3	Mon Jul  7 14:50:11 2008
+++ julius4/libsent/src/hmminfo/rdhmmdef_state.c	Tue Sep 30 12:58:18 2008
@@ -12,7 +12,7 @@
  * @author Akinobu LEE
  * @date   Wed Feb 16 03:07:44 2005
  *
- * $Revision: 1.3 $
+ * $Revision: 1.4 $
  * 
  */
 /*
@@ -70,14 +70,14 @@
   if (new->name != NULL) {
     /* add index to search index tree */
     if (hmm->st_root == NULL) {
-      hmm->st_root = aptree_make_root_node(new);
+      hmm->st_root = aptree_make_root_node(new, &(hmm->mroot));
     } else {
       match = aptree_search_data(new->name, hmm->st_root);
       if (match != NULL && strmatch(match->name, new->name)) {
 	jlog("Error: rdhmmdef_state: ~s \"%s\" is already defined\n", new->name);
 	rderr(NULL);
       } else {
-	aptree_add_entry(new->name, new, match->name, &(hmm->st_root));
+	aptree_add_entry(new->name, new, match->name, &(hmm->st_root), &(hmm->mroot));
       }
     }
   }
Index: julius4/libsent/src/hmminfo/rdhmmdef_streamweight.c
diff -u julius4/libsent/src/hmminfo/rdhmmdef_streamweight.c:1.1 julius4/libsent/src/hmminfo/rdhmmdef_streamweight.c:1.2
--- julius4/libsent/src/hmminfo/rdhmmdef_streamweight.c:1.1	Mon Jul  7 14:50:11 2008
+++ julius4/libsent/src/hmminfo/rdhmmdef_streamweight.c	Tue Sep 30 12:58:18 2008
@@ -65,14 +65,14 @@
   if (new->name != NULL) {
     /* add index to search index tree */
     if (hmm->sw_root == NULL) {
-      hmm->sw_root = aptree_make_root_node(new);
+      hmm->sw_root = aptree_make_root_node(new, &(hmm->mroot));
     } else {
       match = aptree_search_data(new->name, hmm->sw_root);
       if (match != NULL && strmatch(match->name, new->name)) {
 	jlog("Error: rdhmmdef_streamweight: ~w \"%s\" is already defined\n", new->name);
 	rderr(NULL);
       } else {
-	aptree_add_entry(new->name, new, match->name, &(hmm->sw_root));
+	aptree_add_entry(new->name, new, match->name, &(hmm->sw_root), &(hmm->mroot));
       }
     }
   }
Index: julius4/libsent/src/hmminfo/rdhmmdef_tiedmix.c
diff -u julius4/libsent/src/hmminfo/rdhmmdef_tiedmix.c:1.3 julius4/libsent/src/hmminfo/rdhmmdef_tiedmix.c:1.4
--- julius4/libsent/src/hmminfo/rdhmmdef_tiedmix.c:1.3	Mon Jul  7 14:50:11 2008
+++ julius4/libsent/src/hmminfo/rdhmmdef_tiedmix.c	Tue Sep 30 12:58:18 2008
@@ -12,7 +12,7 @@
  * @author Akinobu LEE
  * @date   Wed Feb 16 03:25:11 2005
  *
- * $Revision: 1.3 $
+ * $Revision: 1.4 $
  * 
  */
 /*
@@ -60,14 +60,14 @@
 {
   GCODEBOOK *match;
   if (hmm->codebook_root == NULL) {
-    hmm->codebook_root = aptree_make_root_node(new);
+    hmm->codebook_root = aptree_make_root_node(new, &(hmm->mroot));
   } else {
     match = aptree_search_data(new->name, hmm->codebook_root);
     if (match != NULL && strmatch(match->name, new->name)) {
       jlog("Error: rdhmmdef_tiedmix: ~s \"%s\" is already defined\n", new->name);
       rderr(NULL);
     } else {
-      aptree_add_entry(new->name, new, match->name, &(hmm->codebook_root));
+      aptree_add_entry(new->name, new, match->name, &(hmm->codebook_root), &(hmm->mroot));
     }
   }
 }
Index: julius4/libsent/src/hmminfo/rdhmmdef_trans.c
diff -u julius4/libsent/src/hmminfo/rdhmmdef_trans.c:1.2 julius4/libsent/src/hmminfo/rdhmmdef_trans.c:1.3
--- julius4/libsent/src/hmminfo/rdhmmdef_trans.c:1.2	Tue Dec 18 17:45:51 2007
+++ julius4/libsent/src/hmminfo/rdhmmdef_trans.c	Tue Sep 30 12:58:18 2008
@@ -17,7 +17,7 @@
  * @author Akinobu LEE
  * @date   Wed Feb 16 03:50:55 2005
  *
- * $Revision: 1.2 $
+ * $Revision: 1.3 $
  * 
  */
 /*
@@ -69,14 +69,14 @@
   if (new->name != NULL) {
     /* add index to search index tree */
     if (hmm->tr_root == NULL) {
-      hmm->tr_root = aptree_make_root_node(new);
+      hmm->tr_root = aptree_make_root_node(new, &(hmm->mroot));
     } else {
       match = aptree_search_data(new->name, hmm->tr_root);
       if (match != NULL && strmatch(match->name,new->name)) {
 	jlog("Error: rdhmmdef_trans: ~t \"%s\" is already defined\n", new->name);
 	rderr(NULL);
       } else {
-	aptree_add_entry(new->name, new, match->name, &(hmm->tr_root));
+	aptree_add_entry(new->name, new, match->name, &(hmm->tr_root), &(hmm->mroot));
       }
     }
   }
Index: julius4/libsent/src/hmminfo/rdhmmdef_var.c
diff -u julius4/libsent/src/hmminfo/rdhmmdef_var.c:1.2 julius4/libsent/src/hmminfo/rdhmmdef_var.c:1.3
--- julius4/libsent/src/hmminfo/rdhmmdef_var.c:1.2	Tue Dec 18 17:45:51 2007
+++ julius4/libsent/src/hmminfo/rdhmmdef_var.c	Tue Sep 30 12:58:18 2008
@@ -12,7 +12,7 @@
  * @author Akinobu LEE
  * @date   Wed Feb 16 04:01:38 2005
  *
- * $Revision: 1.2 $
+ * $Revision: 1.3 $
  * 
  */
 /*
@@ -67,14 +67,14 @@
   if (new->name != NULL) {
     /* add index to search index tree */
     if (hmm->vr_root == NULL) {
-      hmm->vr_root = aptree_make_root_node(new);
+      hmm->vr_root = aptree_make_root_node(new, &(hmm->mroot));
     } else {
       match = aptree_search_data(new->name, hmm->vr_root);
       if (match != NULL && strmatch(match->name, new->name)) {
 	jlog("Error: rdhmmdef_var: ~v \"%s\" is already defined\n", new->name);
 	rderr(NULL);
       } else {
-	aptree_add_entry(new->name, new, match->name, &(hmm->vr_root));
+	aptree_add_entry(new->name, new, match->name, &(hmm->vr_root), &(hmm->mroot));
       }
     }
   }
Index: julius4/libsent/src/hmminfo/rdhmmlist.c
diff -u julius4/libsent/src/hmminfo/rdhmmlist.c:1.2 julius4/libsent/src/hmminfo/rdhmmlist.c:1.3
--- julius4/libsent/src/hmminfo/rdhmmlist.c:1.2	Tue Dec 18 17:45:51 2007
+++ julius4/libsent/src/hmminfo/rdhmmlist.c	Tue Sep 30 12:58:18 2008
@@ -41,7 +41,7 @@
  * @author Akinobu LEE
  * @date   Wed Feb 16 04:04:23 2005
  *
- * $Revision: 1.2 $
+ * $Revision: 1.3 $
  * 
  */
 /*
@@ -121,14 +121,14 @@
     hmminfo->lgstart = new;
     /* add index to search index tree */
     if (hmminfo->logical_root == NULL) {
-      hmminfo->logical_root = aptree_make_root_node(new);
+      hmminfo->logical_root = aptree_make_root_node(new, &(hmminfo->lroot));
     } else {
       match = aptree_search_data(new->name, hmminfo->logical_root);
       if (match != NULL && strmatch(match->name, new->name)) {
 	jlog("Error: rdhmmlist: line %d: logical HMM \"%s\" duplicated\n", n, new->name);
 	ok_flag = FALSE;
       } else {
-	aptree_add_entry(new->name, new, match->name, &(hmminfo->logical_root));
+	aptree_add_entry(new->name, new, match->name, &(hmminfo->logical_root), &(hmminfo->lroot));
       }
     }
     
@@ -136,5 +136,6 @@
 
   hmminfo->totallogicalnum = n;
   free(buf);
+
   return(ok_flag);
 }
Index: julius4/libsent/src/hmminfo/read_binhmmlist.c
diff -u /dev/null julius4/libsent/src/hmminfo/read_binhmmlist.c:1.1
--- /dev/null	Tue Sep 30 12:58:18 2008
+++ julius4/libsent/src/hmminfo/read_binhmmlist.c	Tue Sep 30 12:58:18 2008
@@ -0,0 +1,108 @@
+/**
+ * @file   read_rdhmmlist.c
+ * 
+ * <JA>
+ * @brief  HMMListファイルを読み込む(バイナリ版)
+ *
+ * HMMList ファイルは,辞書上の音素表記(トライフォン表記)から
+ * 実際に定義されている %HMM へのマッピングを行なうファイルです.
+ * 
+ * HMMListファイルでは,登場しうる音素について,対応する
+ * HMM 定義の名前を記述します.一行に1つづつ,第1カラムに音素名,
+ * スペースで区切って第2カラムに定義されている実際の %HMM 名を指定します.
+ * 第1カラムと第2カラムが全く同じ場合,すなわちその音素名のモデルが直接
+ * %HMM として定義されている場合は,第2カラムは省略することができます.
+ *
+ * トライフォン使用時は,HMMListファイルで登場しうる全てのトライフォンに
+ * ついて記述する必要がある点に注意して下さい.もし与えられた認識辞書
+ * 上で登場しうるトライフォンがHMMListに記述されていない場合,
+ * エラーとなります.
+ * </JA>
+ * 
+ * <EN>
+ * @brief  Read in HMMList file from binary format
+ *
+ * HMMList file specifies how the phones as described in word dictionary,
+ * or their context-dependent form, should be mapped to actual defined %HMM.
+ *
+ * In HMMList file, the possible phone names and their corresponding %HMM
+ * name should be specified one per line.  The phone name should be put on
+ * the first column, and its corresponding %HMM name in the HTK %HMM definition
+ * file should be defined on the second column.  If the two strings are
+ * the same, which occurs when a %HMM of the phone name is directly defined,
+ * the second column can be omitted.
+ *
+ * When using a triphone model, ALL the possible triphones that can appear
+ * on the given word dictionary should be specified in the HMMList file.
+ * If some possible triphone are not specified in the HMMList, Julius
+ * produces error.
+ * </EN>
+ * 
+ * @author Akinobu LEE
+ * @date   Wed Feb 16 04:04:23 2005
+ *
+ * $Revision: 1.1 $
+ * 
+ */
+/*
+ * Copyright (c) 1991-2007 Kawahara Lab., Kyoto University
+ * Copyright (c) 2000-2005 Shikano Lab., Nara Institute of Science and Technology
+ * Copyright (c) 2005-2007 Julius project team, Nagoya Institute of Technology
+ * All rights reserved
+ */
+
+#include <sent/stddefs.h>
+#include <sent/htk_hmm.h>
+#include <sent/ptree.h>
+
+static boolean
+load_hmmlist_callback(void **data_p, void *data, FILE *fp)
+{
+  HTK_HMM_INFO *hmminfo = data;
+  HMM_Logical *new;
+  int len;
+  char buf[MAX_HMMNAME_LEN];
+  HTK_HMM_Data *d;
+
+  new = (HMM_Logical *)mybmalloc2(sizeof(HMM_Logical), &(hmminfo->lroot));
+  if (myfread(&(new->is_pseudo), sizeof(boolean), 1, fp) < 1) return FALSE;
+  if (myfread(&len, sizeof(int), 1, fp) < 1) return FALSE;
+  new->name = (char *)mybmalloc2(len, &(hmminfo->lroot));
+  if (myfread(new->name, len, 1, fp) < 1) return FALSE;
+  if (myfread(&len, sizeof(int), 1, fp) < 1) return FALSE;
+  if (myfread(buf, len, 1, fp) < 1) return FALSE;
+  if (new->is_pseudo) {
+    jlog("Error: sorry, pseudo logical phone saving not implemented yet\n");
+    return FALSE;
+  } else {
+    d = htk_hmmdata_lookup_physical(hmminfo, buf);
+    if (d == NULL) {
+      jlog("Error: load_hmmlist_callback: no name \"%s\" in hmmdefs!\n", buf);
+      return FALSE;
+    }
+    new->body.defined = d;
+  }
+  new->next = hmminfo->lgstart;
+  hmminfo->lgstart = new;
+
+  *data_p = new;
+  
+  return TRUE;
+}
+
+boolean
+load_hmmlist_bin(FILE *fp, HTK_HMM_INFO *hmminfo)
+{
+  HMM_Logical *l;
+  int n;
+
+  if (aptree_read(fp, &(hmminfo->logical_root), &(hmminfo->lroot), hmminfo, load_hmmlist_callback) == FALSE) {
+    jlog("Error: load_hmmlist_bin: failed to read hmmlist from binary file\n");
+    return FALSE;
+  }
+  n = 0;
+  for(l=hmminfo->lgstart;l;l=l->next) n++;
+  hmminfo->totallogicalnum = n;
+
+  return TRUE;
+}
Index: julius4/libsent/src/hmminfo/write_binhmmlist.c
diff -u /dev/null julius4/libsent/src/hmminfo/write_binhmmlist.c:1.1
--- /dev/null	Tue Sep 30 12:58:18 2008
+++ julius4/libsent/src/hmminfo/write_binhmmlist.c	Tue Sep 30 12:58:18 2008
@@ -0,0 +1,67 @@
+/**
+ * @file   write_hmmlist.c
+ * 
+ * <JA>
+ * @brief  HMMListファイルをバイナリ形式で出力する
+ * </JA>
+ * 
+ * <EN>
+ * @brief  Write HMMList data to binary file
+ *
+ * </EN>
+ * 
+ * @author Akinobu LEE
+ * @date   Wed Feb 16 04:04:23 2005
+ *
+ * $Revision: 1.1 $
+ * 
+ */
+/*
+ * Copyright (c) 1991-2007 Kawahara Lab., Kyoto University
+ * Copyright (c) 2000-2005 Shikano Lab., Nara Institute of Science and Technology
+ * Copyright (c) 2005-2007 Julius project team, Nagoya Institute of Technology
+ * All rights reserved
+ */
+
+#include <sent/stddefs.h>
+#include <sent/htk_hmm.h>
+#include <sent/ptree.h>
+
+static boolean
+save_hmmlist_callback(void *data, FILE *fp)
+{
+  HMM_Logical *l = data;
+  char *s;
+  int len;
+
+  if (myfwrite(&(l->is_pseudo), sizeof(boolean), 1, fp) < 1) return FALSE;
+  len = strlen(l->name) + 1;
+  if (myfwrite(&len, sizeof(int), 1, fp) < 1) return FALSE;
+  if (myfwrite(l->name, len, 1, fp) < 1) return FALSE;
+  if (l->is_pseudo) {
+    s = l->body.pseudo->name;
+  } else {
+    s = l->body.defined->name;
+  }
+  len = strlen(s) + 1;
+  if (myfwrite(&len, sizeof(int), 1, fp) < 1) return FALSE;
+  if (myfwrite(s, len, 1, fp) < 1) return FALSE;
+  
+  return TRUE;
+}
+
+boolean
+save_hmmlist_bin(FILE *fp, HTK_HMM_INFO *hmminfo)
+{
+  /* set mark */
+  int x = 0;
+  if (myfwrite(&x, sizeof(int), 1, fp) < 1) {
+    jlog("Error: save_hmmlist_bin: failed to write hmmlist to binary file\n");
+    return FALSE;
+  }
+  if (aptree_write(fp, hmminfo->logical_root, save_hmmlist_callback) == FALSE) {
+    jlog("Error: save_hmmlist_bin: failed to write hmmlist to binary file\n");
+    return FALSE;
+  }
+  return TRUE;
+}


Julius-cvs メーリングリストの案内
Back to archive index