libsent/src/ngram/ngram_malloc.c

Go to the documentation of this file.
00001 
00018 /*
00019  * Copyright (c) 1991-2007 Kawahara Lab., Kyoto University
00020  * Copyright (c) 2000-2005 Shikano Lab., Nara Institute of Science and Technology
00021  * Copyright (c) 2005-2007 Julius project team, Nagoya Institute of Technology
00022  * All rights reserved
00023  */
00024 
00025 #include <sent/stddefs.h>
00026 #include <sent/ngram2.h>
00027 
00033 NGRAM_INFO *
00034 ngram_info_new()
00035 {
00036   NGRAM_INFO *new;
00037 
00038   new = (NGRAM_INFO *)mymalloc(sizeof(NGRAM_INFO));
00039   new->bo_wt_1 = NULL;
00040   new->p_2 = NULL;
00041 
00042   return(new);
00043 }
00044 
00045 static void
00046 free_ngram_tuple(NGRAM_TUPLE_INFO *t)
00047 {
00048   if (t->is24bit) {
00049     if (t->bgn_upper) free(t->bgn_upper);
00050     if (t->bgn_lower) free(t->bgn_lower);
00051   } else {
00052     if (t->bgn) free(t->bgn);
00053   }
00054   if (t->num) free(t->num);
00055   if (t->nnid2wid) free(t->nnid2wid);
00056   free(t->prob);
00057   if (t->bo_wt) free(t->bo_wt);
00058   if (t->nnid2ctid_upper) free(t->nnid2ctid_upper);
00059   if (t->nnid2ctid_lower) free(t->nnid2ctid_lower);
00060 }
00066 void
00067 ngram_info_free(NGRAM_INFO *ndata)
00068 {
00069   int i;
00070   /* bin test only */
00071   /* free word names */
00072   if (ndata->from_bin) {
00073     free(ndata->wname[0]);
00074     free(ndata->wname);
00075   } else {
00076     WORD_ID w;
00077     for(w=0;w<ndata->max_word_num;w++) {
00078       free(ndata->wname[w]);
00079     }
00080     free(ndata->wname);
00081   }
00082   /* free 2-gram for the 1st pass */
00083   if (ndata->bo_wt_1) free(ndata->bo_wt_1);
00084   if (ndata->p_2) free(ndata->p_2);
00085   /* free n-gram */
00086   for(i=0;i<ndata->n;i++) {
00087     free_ngram_tuple(&(ndata->d[i]));
00088   }
00089   /* free name index tree */
00090   free_ptree(ndata->root);
00091   /* free whole */
00092   free(ndata);
00093 }

Generated on Tue Dec 18 15:59:56 2007 for Julius by  doxygen 1.5.4