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

src/libpocketsphinx/dict.h

Go to the documentation of this file.
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 #ifndef _S3_DICT_H_
00039 #define _S3_DICT_H_
00040 
00044 #include <hash_table.h>
00045 #include <s3types.h>
00046 
00047 #include "bin_mdef.h"
00048 #include "pocketsphinx_export.h"
00049 
00050 #define S3DICT_INC_SZ 4096
00051 
00052 #ifdef __cplusplus
00053 extern "C" {
00054 #endif
00055 #if 0
00056 } /* Fool Emacs into not indenting things. */
00057 #endif
00058 
00063 typedef struct {
00064     char *word;         
00065     s3cipid_t *ciphone; 
00066     int32 pronlen;      
00067     s3wid_t alt;        
00068     s3wid_t basewid;    
00069 } dictword_t;
00070 
00076 typedef struct {
00077     int refcnt;
00078     bin_mdef_t *mdef;   
00079     dictword_t *word;   
00080     hash_table_t *ht;   
00081     int32 max_words;    
00082     int32 n_word;       
00083     int32 filler_start; 
00084     int32 filler_end;   
00085     s3wid_t startwid;   
00086     s3wid_t finishwid;  
00087     s3wid_t silwid;     
00088     int nocase;
00089 } dict_t;
00090 
00091 
00097 dict_t *dict_init(cmd_ln_t *config, 
00098                   bin_mdef_t *mdef      
00099     );
00100 
00104 int dict_write(dict_t *dict, char const *filename, char const *format);
00105 
00107 POCKETSPHINX_EXPORT
00108 s3wid_t dict_wordid(dict_t *d, const char *word);
00109 
00114 int dict_filler_word(dict_t *d,  
00115                      s3wid_t w     
00116     );
00117 
00121 POCKETSPHINX_EXPORT
00122 int dict_real_word(dict_t *d,  
00123                    s3wid_t w     
00124     );
00125 
00130 s3wid_t dict_add_word(dict_t *d,          
00131                       char const *word,   
00132                       s3cipid_t const *p, 
00133                       int32 np            
00134     );
00135 
00139 const char *dict_ciphone_str(dict_t *d, 
00140                              s3wid_t wid,       
00141                              int32 pos          
00142     );
00143 
00145 #define dict_size(d)            ((d)->n_word)
00146 #define dict_num_fillers(d)   (dict_filler_end(d) - dict_filler_start(d))
00147 
00152 #define dict_num_real_words(d)                                          \
00153     (dict_size(d) - (dict_filler_end(d) - dict_filler_start(d)) - 2)
00154 #define dict_basewid(d,w)       ((d)->word[w].basewid)
00155 #define dict_wordstr(d,w)       ((d)->word[w].word)
00156 #define dict_basestr(d,w)       ((d)->word[dict_basewid(d,w)].word)
00157 #define dict_nextalt(d,w)       ((d)->word[w].alt)
00158 #define dict_pronlen(d,w)       ((d)->word[w].pronlen) 
00159 #define dict_pron(d,w,p)        ((d)->word[w].ciphone[p]) 
00160 #define dict_filler_start(d)    ((d)->filler_start)
00161 #define dict_filler_end(d)      ((d)->filler_end)
00162 #define dict_startwid(d)        ((d)->startwid)
00163 #define dict_finishwid(d)       ((d)->finishwid)
00164 #define dict_silwid(d)          ((d)->silwid)
00165 #define dict_is_single_phone(d,w)       ((d)->word[w].pronlen == 1)
00166 #define dict_first_phone(d,w)   ((d)->word[w].ciphone[0])
00167 #define dict_second_phone(d,w)  ((d)->word[w].ciphone[1])
00168 #define dict_second_last_phone(d,w)     ((d)->word[w].ciphone[(d)->word[w].pronlen - 2])
00169 #define dict_last_phone(d,w)    ((d)->word[w].ciphone[(d)->word[w].pronlen - 1])
00170 
00171 /* Hard-coded special words */
00172 #define S3_START_WORD           "<s>"
00173 #define S3_FINISH_WORD          "</s>"
00174 #define S3_SILENCE_WORD         "<sil>"
00175 #define S3_UNKNOWN_WORD         "<UNK>"
00176 
00184 int32 dict_word2basestr(char *word);
00185 
00189 dict_t *dict_retain(dict_t *d);
00190 
00194 int dict_free(dict_t *d);
00195 
00197 void dict_report(dict_t *d 
00198     );
00199 
00200 #if 0
00201 { /* Stop indent from complaining */
00202 #endif
00203 #ifdef __cplusplus
00204 }
00205 #endif
00206 
00207 #endif

Generated on Tue Aug 17 2010 for PocketSphinx by  doxygen 1.7.1