• 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 <bitvec.h>
00059 #include <listelem_alloc.h>
00060 #include <sphinxbase_export.h>
00061 
00062 /*
00063  * A single transition in the FSG.
00064  */
00065 typedef struct fsg_link_s {
00066     int32 from_state;
00067     int32 to_state;
00068     int32 logs2prob;    
00069     int32 wid;          
00070 } fsg_link_t;
00071 
00072 /* Access macros */
00073 #define fsg_link_from_state(l)  ((l)->from_state)
00074 #define fsg_link_to_state(l)    ((l)->to_state)
00075 #define fsg_link_wid(l)         ((l)->wid)
00076 #define fsg_link_logs2prob(l)   ((l)->logs2prob)
00077 
00078 
00086 typedef struct fsg_model_s {
00087     int refcount;       
00088     char *name;         
00089     int32 n_word;       
00090     int32 n_word_alloc; 
00091     char **vocab;       
00092     bitvec_t *silwords; 
00093     bitvec_t *altwords; 
00094     logmath_t *lmath;   
00095     int32 n_state;      
00096     int32 start_state;  
00097     int32 final_state;  
00098     float32 lw;         
00100     glist_t **trans;    
00103     fsg_link_t ***null_trans; 
00107     listelem_alloc_t *link_alloc; 
00108 } fsg_model_t;
00109 
00110 /* Access macros */
00111 #define fsg_model_name(f)               ((f)->name)
00112 #define fsg_model_n_state(f)            ((f)->n_state)
00113 #define fsg_model_start_state(f)        ((f)->start_state)
00114 #define fsg_model_final_state(f)        ((f)->final_state)
00115 #define fsg_model_log(f,p)              logmath_log((f)->lmath, p)
00116 #define fsg_model_lw(f)                 ((f)->lw)
00117 #define fsg_model_trans(f,i,j)          ((f)->trans[i][j])
00118 #define fsg_model_null_trans(f,i,j)     ((f)->null_trans[i][j])
00119 #define fsg_model_n_word(f)             ((f)->n_word)
00120 #define fsg_model_word_str(f,wid)       (wid == -1 ? "(NULL)" : (f)->vocab[wid])
00121 
00125 #define fsg_model_has_sil(f)            ((f)->silwords != NULL)
00126 
00130 #define fsg_model_has_alt(f)            ((f)->altwords != NULL)
00131 
00132 #define fsg_model_is_filler(f,wid) \
00133     (fsg_model_has_sil(f) ? bitvec_is_set((f)->silwords, wid) : FALSE)
00134 #define fsg_model_is_alt(f,wid) \
00135     (fsg_model_has_alt(f) ? bitvec_is_set((f)->altwords, wid) : FALSE)
00136 
00140 SPHINXBASE_EXPORT
00141 fsg_model_t *fsg_model_init(char const *name, logmath_t *lmath,
00142                             float32 lw, int32 n_state);
00143 
00183 SPHINXBASE_EXPORT
00184 fsg_model_t *fsg_model_readfile(const char *file, logmath_t *lmath, float32 lw);
00185 
00189 SPHINXBASE_EXPORT
00190 fsg_model_t *fsg_model_read(FILE *fp, logmath_t *lmath, float32 lw);
00191 
00197 SPHINXBASE_EXPORT
00198 fsg_model_t *fsg_model_retain(fsg_model_t *fsg);
00199 
00205 SPHINXBASE_EXPORT
00206 int fsg_model_free(fsg_model_t *fsg);
00207 
00213 SPHINXBASE_EXPORT
00214 int fsg_model_word_add(fsg_model_t *fsg, char const *word);
00215 
00221 SPHINXBASE_EXPORT
00222 int fsg_model_word_id(fsg_model_t *fsg, char const *word);
00223 
00230 SPHINXBASE_EXPORT
00231 void fsg_model_trans_add(fsg_model_t * fsg,
00232                          int32 from, int32 to, int32 logp, int32 wid);
00233 
00244 SPHINXBASE_EXPORT
00245 int32 fsg_model_null_trans_add(fsg_model_t * fsg, int32 from, int32 to, int32 logp);
00246 
00253 SPHINXBASE_EXPORT
00254 glist_t fsg_model_null_trans_closure(fsg_model_t * fsg, glist_t nulls);
00255 
00262 SPHINXBASE_EXPORT
00263 int fsg_model_add_silence(fsg_model_t * fsg, char const *silword,
00264                           int state, float32 silprob);
00265 
00269 SPHINXBASE_EXPORT
00270 int fsg_model_add_alt(fsg_model_t * fsg, char const *baseword,
00271                       char const *altword);
00272 
00276 SPHINXBASE_EXPORT
00277 void fsg_model_write(fsg_model_t *fsg, FILE *fp);
00278 
00282 SPHINXBASE_EXPORT
00283 void fsg_model_writefile(fsg_model_t *fsg, char const *file);
00284 
00288 SPHINXBASE_EXPORT
00289 void fsg_model_write_fsm(fsg_model_t *fsg, FILE *fp);
00290 
00294 SPHINXBASE_EXPORT
00295 void fsg_model_writefile_fsm(fsg_model_t *fsg, char const *file);
00296 
00300 SPHINXBASE_EXPORT
00301 void fsg_model_write_symtab(fsg_model_t *fsg, FILE *file);
00302 
00306 SPHINXBASE_EXPORT
00307 void fsg_model_writefile_symtab(fsg_model_t *fsg, char const *file);
00308 
00309 #endif /* __FSG_MODEL_H__ */

Generated on Thu Jan 6 2011 for SphinxBase by  doxygen 1.7.1