• Main Page
  • Related Pages
  • Data Structures
  • Files
  • File List
  • Globals

include/fsg_model.h

00001 /* -*- c-basic-offset: 4; indent-tabs-mode: nil -*- */
00002 /* ====================================================================
00003  * Copyright (c) 1999-2004 Carnegie Mellon University.  All rights
00004  * reserved.
00005  *
00006  * Redistribution and use in source and binary forms, with or without
00007  * modification, are permitted provided that the following conditions
00008  * are met:
00009  *
00010  * 1. Redistributions of source code must retain the above copyright
00011  *    notice, this list of conditions and the following disclaimer. 
00012  *
00013  * 2. Redistributions in binary form must reproduce the above copyright
00014  *    notice, this list of conditions and the following disclaimer in
00015  *    the documentation and/or other materials provided with the
00016  *    distribution.
00017  *
00018  *
00019  * THIS SOFTWARE IS PROVIDED BY CARNEGIE MELLON UNIVERSITY ``AS IS'' AND 
00020  * ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, 
00021  * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
00022  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL CARNEGIE MELLON UNIVERSITY
00023  * NOR ITS EMPLOYEES BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
00024  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 
00025  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 
00026  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 
00027  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 
00028  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 
00029  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00030  *
00031  * ====================================================================
00032  *
00033  */
00034 
00035 /*
00036  * fsg_model.h -- Word-level finite state graph
00037  * 
00038  * **********************************************
00039  * CMU ARPA Speech Project
00040  *
00041  * Copyright (c) 2003 Carnegie Mellon University.
00042  * ALL RIGHTS RESERVED.
00043  * **********************************************
00044  */
00045 
00046 
00047 #ifndef __FSG_MODEL_H__
00048 #define __FSG_MODEL_H__
00049 
00050 /* System headers. */
00051 #include <stdio.h>
00052 #include <string.h>
00053 
00054 /* SphinxBase headers. */
00055 #include <prim_type.h>
00056 #include <glist.h>
00057 #include <logmath.h>
00058 #include <hash_table.h>
00059 #include <bitvec.h>
00060 #include <listelem_alloc.h>
00061 #include <sphinxbase_export.h>
00062 
00063 /*
00064  * A single transition in the FSG.
00065  */
00066 typedef struct fsg_link_s {
00067     int32 from_state;
00068     int32 to_state;
00069     int32 logs2prob;    
00070     int32 wid;          
00071 } fsg_link_t;
00072 
00073 /* Access macros */
00074 #define fsg_link_from_state(l)  ((l)->from_state)
00075 #define fsg_link_to_state(l)    ((l)->to_state)
00076 #define fsg_link_wid(l)         ((l)->wid)
00077 #define fsg_link_logs2prob(l)   ((l)->logs2prob)
00078 
00079 
00087 typedef struct fsg_model_s {
00088     int refcount;       
00089     char *name;         
00090     int32 n_word;       
00091     int32 n_word_alloc; 
00092     char **vocab;       
00093     bitvec_t *silwords; 
00094     bitvec_t *altwords; 
00095     logmath_t *lmath;   
00096     int32 n_state;      
00097     int32 start_state;  
00098     int32 final_state;  
00099     float32 lw;         
00101     glist_t **trans;    
00104     fsg_link_t ***null_trans; 
00108     listelem_alloc_t *link_alloc; 
00109 } fsg_model_t;
00110 
00111 /* Access macros */
00112 #define fsg_model_name(f)               ((f)->name)
00113 #define fsg_model_n_state(f)            ((f)->n_state)
00114 #define fsg_model_start_state(f)        ((f)->start_state)
00115 #define fsg_model_final_state(f)        ((f)->final_state)
00116 #define fsg_model_log(f,p)              logmath_log((f)->lmath, p)
00117 #define fsg_model_lw(f)                 ((f)->lw)
00118 #define fsg_model_trans(f,i,j)          ((f)->trans[i][j])
00119 #define fsg_model_null_trans(f,i,j)     ((f)->null_trans[i][j])
00120 #define fsg_model_n_word(f)             ((f)->n_word)
00121 #define fsg_model_word_str(f,wid)       (wid == -1 ? "(NULL)" : (f)->vocab[wid])
00122 
00126 #define fsg_model_has_sil(f)            ((f)->silwords != NULL)
00127 
00131 #define fsg_model_has_alt(f)            ((f)->altwords != NULL)
00132 
00133 #define fsg_model_is_filler(f,wid) \
00134     (fsg_model_has_sil(f) ? bitvec_is_set((f)->silwords, wid) : FALSE)
00135 #define fsg_model_is_alt(f,wid) \
00136     (fsg_model_has_alt(f) ? bitvec_is_set((f)->altwords, wid) : FALSE)
00137 
00141 SPHINXBASE_EXPORT
00142 fsg_model_t *fsg_model_init(char const *name, logmath_t *lmath,
00143                             float32 lw, int32 n_state);
00144 
00184 SPHINXBASE_EXPORT
00185 fsg_model_t *fsg_model_readfile(const char *file, logmath_t *lmath, float32 lw);
00186 
00190 SPHINXBASE_EXPORT
00191 fsg_model_t *fsg_model_read(FILE *fp, logmath_t *lmath, float32 lw);
00192 
00198 SPHINXBASE_EXPORT
00199 fsg_model_t *fsg_model_retain(fsg_model_t *fsg);
00200 
00206 SPHINXBASE_EXPORT
00207 int fsg_model_free(fsg_model_t *fsg);
00208 
00214 SPHINXBASE_EXPORT
00215 int fsg_model_word_add(fsg_model_t *fsg, char const *word);
00216 
00222 SPHINXBASE_EXPORT
00223 int fsg_model_word_id(fsg_model_t *fsg, char const *word);
00224 
00231 SPHINXBASE_EXPORT
00232 void fsg_model_trans_add(fsg_model_t * fsg,
00233                          int32 from, int32 to, int32 logp, int32 wid);
00234 
00245 SPHINXBASE_EXPORT
00246 int32 fsg_model_null_trans_add(fsg_model_t * fsg, int32 from, int32 to, int32 logp);
00247 
00254 SPHINXBASE_EXPORT
00255 glist_t fsg_model_null_trans_closure(fsg_model_t * fsg, glist_t nulls);
00256 
00263 SPHINXBASE_EXPORT
00264 int fsg_model_add_silence(fsg_model_t * fsg, char const *silword,
00265                           int state, float32 silprob);
00266 
00270 SPHINXBASE_EXPORT
00271 int fsg_model_add_alt(fsg_model_t * fsg, char const *baseword,
00272                       char const *altword);
00273 
00277 SPHINXBASE_EXPORT
00278 void fsg_model_write(fsg_model_t *fsg, FILE *fp);
00279 
00283 SPHINXBASE_EXPORT
00284 void fsg_model_writefile(fsg_model_t *fsg, char const *file);
00285 
00286 #endif /* __FSG_MODEL_H__ */

Generated on Fri Jan 14 2011 for SphinxBase by  doxygen 1.7.1