src/libpocketsphinx/s3dict.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  * 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 
00114 #include "bin_mdef.h"
00115 #include "lts.h" 
00116 
00117 #define S3DICT_INC_SZ 4096
00118 
00119 #ifdef __cplusplus
00120 extern "C" {
00121 #endif
00122 #if 0
00123 } /* Fool Emacs into not indenting things. */
00124 #endif
00125 
00130 typedef struct {
00131     char *word;         
00132     s3cipid_t *ciphone; 
00133     int32 pronlen;      
00134     s3wid_t alt;        
00135     s3wid_t basewid;    
00136 } dictword_t;
00137 
00143 typedef struct {
00144     int refcnt;
00145     bin_mdef_t *mdef;   
00146     dictword_t *word;   
00147     hash_table_t *ht;   
00148     int32 max_words;    
00149     int32 n_word;       
00150     int32 filler_start; 
00151     int32 filler_end;   
00152     s3wid_t startwid;   
00153     s3wid_t finishwid;  
00154     s3wid_t silwid;     
00156     lts_t *lts_rules;     
00157 } s3dict_t;
00158 
00159 
00165 s3dict_t *s3dict_init(bin_mdef_t *mdef, 
00166                       const char *dictfile,     
00167                       const char *fillerfile,   
00168                       int useLTS,          
00169                       int breport          
00170     );
00171 
00173 s3wid_t s3dict_wordid(s3dict_t *d, const char *word);
00174 
00179 int s3dict_filler_word(s3dict_t *d,  
00180                        s3wid_t w     
00181     );
00182 
00186 int s3dict_real_word(s3dict_t *d,  
00187                      s3wid_t w     
00188     );
00189 
00194 s3wid_t s3dict_add_word(s3dict_t *d,  
00195                         char *word, 
00196                         s3cipid_t *p, 
00197                         int32 np
00198     );
00199 
00203 const char *s3dict_ciphone_str(s3dict_t *d,     
00204                                s3wid_t wid,     
00205                                int32 pos        
00206     );
00207 
00209 #define s3dict_size(d)          ((d)->n_word)
00210 #define s3dict_num_fillers(d)   (s3dict_filler_end(d) - s3dict_filler_start(d))
00211 
00216 #define s3dict_num_real_words(d) \
00217     (s3dict_size(d) - (s3dict_filler_end(d) - s3dict_filler_start(d)) - 2)
00218 #define s3dict_basewid(d,w)     ((d)->word[w].basewid)
00219 #define s3dict_wordstr(d,w)     ((d)->word[w].word)
00220 #define s3dict_basestr(d,w)     ((d)->word[s3dict_basewid(d,w)].word)
00221 #define s3dict_nextalt(d,w)     ((d)->word[w].alt)
00222 #define s3dict_pronlen(d,w)     ((d)->word[w].pronlen) 
00223 #define s3dict_pron(d,w,p)      ((d)->word[w].ciphone[p]) 
00224 #define s3dict_filler_start(d)  ((d)->filler_start)
00225 #define s3dict_filler_end(d)    ((d)->filler_end)
00226 #define s3dict_startwid(d)      ((d)->startwid)
00227 #define s3dict_finishwid(d)     ((d)->finishwid)
00228 #define s3dict_silwid(d)                ((d)->silwid)
00229 #define s3dict_first_phone(d,w) ((d)->word[w].ciphone[0])
00230 #define s3dict_second_last_phone(d,w)   ((d)->word[w].ciphone[(d)->word[w].pronlen - 2])
00231 #define s3dict_last_phone(d,w)  ((d)->word[w].ciphone[(d)->word[w].pronlen - 1])
00232 
00233 /* Hard-coded special words */
00234 #define S3_START_WORD           "<s>"
00235 #define S3_FINISH_WORD          "</s>"
00236 #define S3_SILENCE_WORD         "<sil>"
00237 #define S3_UNKNOWN_WORD         "<UNK>"
00238 
00239 /* Function versions of some of the above macros; note the leading underscore. */
00240 
00244 s3wid_t _s3dict_basewid(s3dict_t *d, s3wid_t w);
00245 
00249 char *_s3dict_wordstr(s3dict_t *d, s3wid_t wid);
00250 
00255 s3wid_t _s3dict_nextalt(s3dict_t *d, s3wid_t wid);
00256 
00264 int32 s3dict_word2basestr(char *word);
00265 
00269 s3dict_t *s3dict_retain(s3dict_t *d);
00270 
00274 int s3dict_free(s3dict_t *d);
00275 
00277 void s3dict_report(s3dict_t *d 
00278     );
00279 
00280 #if 0
00281 { /* Stop indent from complaining */
00282 #endif
00283 #ifdef __cplusplus
00284 }
00285 #endif
00286 
00287 #endif

Generated on Mon Jan 24 21:50:16 2011 for PocketSphinx by  doxygen 1.4.7