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 * This work was supported in part by funding from the Defense Advanced 00019 * Research Projects Agency and the National Science Foundation of the 00020 * United States of America, and the CMU Sphinx Speech Consortium. 00021 * 00022 * THIS SOFTWARE IS PROVIDED BY CARNEGIE MELLON UNIVERSITY ``AS IS'' AND 00023 * ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, 00024 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 00025 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL CARNEGIE MELLON UNIVERSITY 00026 * NOR ITS EMPLOYEES BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 00027 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 00028 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 00029 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 00030 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 00031 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 00032 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 00033 * 00034 * ==================================================================== 00035 * 00036 */ 00037 /* 00038 * dict.h -- Pronunciation dictionary structures 00039 * 00040 * ********************************************** 00041 * CMU ARPA Speech Project 00042 * 00043 * Copyright (c) 1997 Carnegie Mellon University. 00044 * ALL RIGHTS RESERVED. 00045 * ********************************************** 00046 * 00047 * HISTORY 00048 * $Log$ 00049 * Revision 1.1 2006/04/05 20:27:30 dhdfu 00050 * A Great Reorganzation of header files and executables 00051 * 00052 * Revision 1.10 2006/02/22 20:55:06 arthchan2003 00053 * Merged from branch SPHINX3_5_2_RCI_IRII_BRANCH: 00054 * 00055 * 1, Added Letter-to-sound LTS rule, dict_init will only specify 00056 * d->lts_rules to be true if the useLTS is specified. Only if 00057 * d->lts_rules is specified, the LTS logic will be used. The code safe 00058 * guarded the case when a phone in mdef doesn't appear in LTS, in that 00059 * case, the code will force exit. 00060 * 00061 * 2, The LTS logic is only used as a reserved measure. By default, it 00062 * is not turned on. See also the comment in kbcore.c and the default 00063 * parameters in revision 1.3 cmdln_macro.h . We added it because we have 00064 * this functionality in SphinxTrain. 00065 * 00066 * Revision 1.9.4.4 2005/10/07 18:58:04 arthchan2003 00067 * Added macro for getting second last phone for a word. 00068 * 00069 * Revision 1.9.4.3 2005/09/25 19:12:09 arthchan2003 00070 * Added optional LTS support for the dictionary. 00071 * 00072 * Revision 1.9.4.2 2005/09/18 01:15:45 arthchan2003 00073 * Add one doxy-doc in dict.h 00074 * 00075 * Revision 1.9.4.1 2005/07/05 06:55:26 arthchan2003 00076 * Fixed dox-doc. 00077 * 00078 * Revision 1.9 2005/06/21 21:04:36 arthchan2003 00079 * 1, Introduced a reporting routine. 2, Fixed doyxgen documentation, 3, Added keyword. 00080 * 00081 * Revision 1.5 2005/06/13 04:02:57 archan 00082 * Fixed most doxygen-style documentation under libs3decoder. 00083 * 00084 * Revision 1.4 2005/04/21 23:50:26 archan 00085 * Some more refactoring on the how reporting of structures inside kbcore_t is done, it is now 50% nice. Also added class-based LM test case into test-decode.sh.in. At this moment, everything in search mode 5 is already done. It is time to test the idea whether the search can really be used. 00086 * 00087 * Revision 1.3 2005/03/30 01:22:46 archan 00088 * Fixed mistakes in last updates. Add 00089 * 00090 * 19-Apr-01 Ricky Houghton, added code for freeing memory that is allocated internally. 00091 * 00092 * 23-Apr-98 M K Ravishankar (rkm@cs.cmu.edu) at Carnegie Mellon University. 00093 * Made usage of mdef optional. If no mdef is specified while loading 00094 * a dictionary, it maintains the needed CI phone information internally. 00095 * Added dict_ciphone_str(). 00096 * 00097 * 02-Jul-97 M K Ravishankar (rkm@cs.cmu.edu) at Carnegie Mellon University. 00098 * Added startwid, finishwid, silwid to dict_t structure. 00099 * 00100 * 07-Feb-97 M K Ravishankar (rkm@cs.cmu.edu) at Carnegie Mellon University. 00101 * Created from previous Sphinx-3 version. 00102 */ 00103 00104 00105 #ifndef _S3_DICT_H_ 00106 #define _S3_DICT_H_ 00107 00111 #include <hash_table.h> 00112 #include <s3types.h> 00113 #include "mdef.h" /* This is still a sore point; dict should be independent of mdef */ 00114 #include "lts.h" 00115 00116 #define DICT_INC_SZ 4096 00117 #ifdef __cplusplus 00118 extern "C" { 00119 #endif 00120 #if 0 00121 } /* Fool Emacs into not indenting things. */ 00122 #endif 00123 00128 typedef struct { 00129 char *word; 00130 s3cipid_t *ciphone; 00131 int32 pronlen; 00132 s3wid_t alt; 00133 s3wid_t basewid; 00134 int32 n_comp; 00138 s3wid_t *comp; 00139 } dictword_t; 00140 00146 typedef struct { 00147 mdef_t *mdef; 00148 hash_table_t *pht; 00149 char **ciphone_str; 00150 int32 n_ciphone; 00151 dictword_t *word; 00152 hash_table_t *ht; 00153 int32 max_words; 00154 int32 n_word; 00155 int32 filler_start; 00156 int32 filler_end; 00157 s3wid_t *comp_head; 00160 s3wid_t startwid; 00161 s3wid_t finishwid; 00162 s3wid_t silwid; 00164 lts_t *lts_rules; 00165 } dict_t; 00166 00167 00173 S3DECODER_EXPORT 00174 dict_t *dict_init (mdef_t *mdef, 00176 const char *dictfile, 00177 const char *fillerfile, 00178 const char comp_sep, 00180 int useLTS, 00181 int breport 00182 ); 00183 00185 S3DECODER_EXPORT 00186 s3wid_t dict_wordid (dict_t *d, const char *word); 00187 00192 S3DECODER_EXPORT 00193 int32 dict_filler_word (dict_t *d, 00194 s3wid_t w 00195 ); 00196 00201 s3wid_t dict_add_word (dict_t *d, 00202 char *word, 00203 s3cipid_t *p, 00204 int32 np 00205 ); 00206 00211 s3wid_t dict_wids2compwid (dict_t *d, 00212 s3wid_t *wid, 00213 int32 len 00214 ); 00215 00219 const char *dict_ciphone_str (dict_t *d, 00220 s3wid_t wid, 00221 int32 pos 00222 ); 00223 00225 #define dict_size(d) ((d)->n_word) 00226 #define dict_basewid(d,w) ((d)->word[w].basewid) 00227 #define dict_wordstr(d,w) ((d)->word[w].word) 00228 #define dict_nextalt(d,w) ((d)->word[w].alt) 00229 #define dict_pronlen(d,w) ((d)->word[w].pronlen) 00230 #define dict_pron(d,w,p) ((d)->word[w].ciphone[p]) 00231 #define dict_filler_start(d) ((d)->filler_start) 00232 #define dict_filler_end(d) ((d)->filler_end) 00233 #define dict_startwid(d) ((d)->startwid) 00234 #define dict_finishwid(d) ((d)->finishwid) 00235 #define dict_silwid(d) ((d)->silwid) 00236 #define dict_first_phone(d,w) ((d)->word[w].ciphone[0]) 00237 #define dict_second_last_phone(d,w) ((d)->word[w].ciphone[(d)->word[w].pronlen - 2]) 00238 #define dict_last_phone(d,w) ((d)->word[w].ciphone[(d)->word[w].pronlen - 1]) 00239 00240 /* Hard-coded special words */ 00241 #define S3_START_WORD "<s>" 00242 #define S3_FINISH_WORD "</s>" 00243 #define S3_SILENCE_WORD "<sil>" 00244 #define S3_UNKNOWN_WORD "<UNK>" 00245 00246 /* Function versions of some of the above macros; note the leading underscore. */ 00247 00251 s3wid_t _dict_basewid (dict_t *d, s3wid_t w); 00252 00256 char *_dict_wordstr (dict_t *d, s3wid_t wid); 00257 00262 s3wid_t _dict_nextalt (dict_t *d, s3wid_t wid); 00263 00271 int32 dict_word2basestr (char *word); 00272 00273 /* RAH, free memory allocated for the dictionary */ 00275 S3DECODER_EXPORT 00276 void dict_free (dict_t *d); 00277 00279 void dict_report(dict_t *d 00280 ); 00281 00282 #if 0 00283 { /* Stop indent from complaining */ 00284 #endif 00285 #ifdef __cplusplus 00286 } 00287 #endif 00288 00289 #endif