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

src/libpocketsphinx/dict.h

00001 /* -*- c-basic-offset: 4; indent-tabs-mode: nil -*- */
00002 /* ====================================================================
00003  * Copyright (c) 1999-2001 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 #ifndef _DICT_H_
00036 #define _DICT_H_
00037 
00038 /* SphinxBase headers. */
00039 #include <hash_table.h>
00040 #include <glist.h>
00041 #include <listelem_alloc.h>
00042 #include <cmd_ln.h>
00043 
00044 /* Local headers. */
00045 #include "bin_mdef.h"
00046 
00047 #define NO_WORD         -1
00048 
00049 /* DICT_ENTRY
00050  *------------------------------------------------------------*
00051  * DESCRIPTION
00052  *      Each dictionary entry consists of the word pronunciation
00053  * and list of next words in this grammar for this word.
00054  */ 
00055 typedef struct dict_entry {
00056     char               *word;           /* Ascii rep of the word */
00057     int32              *phone_ids;      /* gt List of the of the Phones */
00058     int32              *ci_phone_ids;   /* context independent phone ids */
00059     int16               len;            /* Number of Phones in the word */
00060     int16               mpx;            /* Is this a multiplexed entry? */
00061     int32               wid;            /* Actual word id */
00062     int32               alt;            /* Alt word idx */
00063 }                   dict_entry_t;
00064 
00065 typedef struct dict_s {
00066     cmd_ln_t            *config;
00067     bin_mdef_t          *mdef;
00068     hash_table_t        *dict;
00069     int32               dict_entry_count;
00070     listelem_alloc_t    *dict_entry_alloc;
00071     dict_entry_t        **dict_list;
00072     int32               ci_index_len;           /* number of indecies */
00073     int32               *ci_index;              /* Index to each group */
00074     int32               filler_start;           /* Start of filler words */
00075 
00076     hash_table_t *lcHT;      /* Left context hash table */
00077     glist_t lcList;
00078     uint16 **lcFwdTable;
00079     uint16 **lcBwdTable;
00080     uint16 **lcBwdPermTable;
00081     uint16 *lcBwdSizeTable;
00082 
00083     hash_table_t *rcHT;      /* Right context hash table */
00084     glist_t rcList;
00085     uint16 **rcFwdTable;
00086     uint16 **rcFwdPermTable;
00087     uint16 **rcBwdTable;
00088     uint16 *rcFwdSizeTable;
00089 
00090     int32 initial_dummy;     /* 1st placeholder for dynamic OOVs after initialization */
00091     int32 first_dummy;       /* 1st dummy available for dynamic OOVs at any time */
00092     int32 last_dummy;        /* last dummy available for dynamic OOVs */
00093 } dict_t;
00094 
00095 dict_t *dict_init(cmd_ln_t *config,
00096                   bin_mdef_t *mdef);
00097 void dict_free (dict_t *dict);
00098 
00099 #define DICT_SILENCE_WORDSTR    "<sil>"
00100 
00101 int32 dict_to_id(dict_t *dict, char const *dict_str);
00102 int32 dict_add_word (dict_t *dict, char const *word, char *pron);
00103 int32 dict_pron (dict_t *dict, int32 w, int32 **pron);
00104 int32 dict_next_alt (dict_t *dict, int32 w);
00105 int32 dict_get_num_main_words (dict_t *dict);
00106 
00107 /* Return TRUE if the given wid is a filler word, FALSE otherwise */
00108 int32 dict_is_filler_word (dict_t *dict, int32 wid);
00109 
00110 #define dict_word_str(d,x)      ((x == NO_WORD) ? "" : d->dict_list[x]->word)
00111 
00112 #define dict_base_str(d,x)      ((x == NO_WORD) ? "" :  \
00113                                    d->dict_list[d->dict_list[x]->wid]->word)
00114 #define dict_base_wid(d,x)      ((x == NO_WORD) ? NO_WORD :     \
00115                                    d->dict_list[x]->wid)
00116 
00117 #define dict_pronlen(dict,wid)  ((dict)->dict_list[wid]->len)
00118 #define dict_ciphone(d,w,p)     ((d)->dict_list[w]->ci_phone_ids[p])
00119 #define dict_phone(d,w,p)       ((d)->dict_list[w]->phone_ids[p])
00120 #define dict_mpx(d,w)           ((d)->dict_list[w]->mpx)
00121 
00122 #define dict_n_words(d)         ((d)->dict_entry_count)
00123 
00124 #define dict_ciphone_id(d,p) \
00125     ((d)->dict->nocase \
00126      ? bin_mdef_ciphone_id_nocase((d)->mdef, (p)) \
00127      : bin_mdef_ciphone_id((d)->mdef, (p)))
00128 #endif

Generated on Thu Jan 27 2011 for PocketSphinx by  doxygen 1.7.1