00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047 #ifndef __FSG_MODEL_H__
00048 #define __FSG_MODEL_H__
00049
00050
00051 #include <stdio.h>
00052 #include <string.h>
00053
00054
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
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
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
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