PocketSphinx  0.6
src/libpocketsphinx/ps_lattice_internal.h
Go to the documentation of this file.
00001 /* -*- c-basic-offset: 4; indent-tabs-mode: nil -*- */
00002 /* ====================================================================
00003  * Copyright (c) 2008 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 
00042 #ifndef __PS_LATTICE_INTERNAL_H__
00043 #define __PS_LATTICE_INTERNAL_H__
00044 
00053 typedef struct latlink_list_s {
00054     ps_latlink_t *link;
00055     struct latlink_list_s *next;
00056 } latlink_list_t;
00057 
00061 struct ps_lattice_s {
00062     int refcount;      
00064     logmath_t *lmath;    
00065     ps_search_t *search; 
00066     dict_t *dict;        
00067     int32 silence;       
00068     int32 frate;         
00070     ps_latnode_t *nodes;  
00071     ps_latnode_t *start;  
00072     ps_latnode_t *end;    
00074     int16 n_frames;    
00075     int16 n_nodes;     
00076     int32 final_node_ascr; 
00077     int32 norm;        
00078     char *hyp_str;     
00080     listelem_alloc_t *latnode_alloc;     
00081     listelem_alloc_t *latlink_alloc;     
00082     listelem_alloc_t *latlink_list_alloc; 
00084     /* This will probably be replaced with a heap. */
00085     latlink_list_t *q_head; 
00086     latlink_list_t *q_tail; 
00087 };
00088 
00096 struct ps_latlink_s {
00097     struct ps_latnode_s *from;  
00098     struct ps_latnode_s *to;    
00099     struct ps_latlink_s *best_prev;
00100     int32 ascr;                 
00101     int32 path_scr;             
00102     int32 ef;                   
00103     int32 alpha;                
00104     int32 beta;                 
00105 };
00106 
00113 struct ps_latnode_s {
00114     int32 id;                   
00115     int32 wid;                  
00116     int32 basewid;              
00117     /* FIXME: These are (ab)used to store backpointer indices, therefore they MUST be 32 bits. */
00118     int32 fef;                  
00119     int32 lef;                  
00120     int16 sf;                   
00121     int16 reachable;            
00122     union {
00123         glist_t velist;         
00124         int32 fanin;            
00125         int32 rem_score;        
00126         int32 best_exit;        
00127     } info;
00128     latlink_list_t *exits;      
00129     latlink_list_t *entries;    
00131     struct ps_latnode_s *alt;   
00132     struct ps_latnode_s *next;  
00133 };
00134 
00138 typedef struct dag_seg_s {
00139     ps_seg_t base;       
00140     ps_latlink_t **links;   
00141     int32 norm;     
00142     int16 n_links;  
00143     int16 cur;      
00144 } dag_seg_t;
00145 
00152 typedef struct ps_latpath_s {
00153     ps_latnode_t *node;            
00154     struct ps_latpath_s *parent;   
00155     struct ps_latpath_s *next;     
00156     int32 score;                  
00157 } ps_latpath_t;
00158 
00162 typedef struct ps_astar_s {
00163     ps_lattice_t *dag;
00164     ngram_model_t *lmset;
00165     float32 lwf;
00166 
00167     int16 sf;
00168     int16 ef;
00169     int32 w1;
00170     int32 w2;
00171 
00172     int32 n_hyp_tried;
00173     int32 n_hyp_insert;
00174     int32 n_hyp_reject;
00175     int32 insert_depth;
00176     int32 n_path;
00177 
00178     ps_latpath_t *path_list;
00179     ps_latpath_t *path_tail;
00180     ps_latpath_t *top;
00181 
00182     glist_t hyps;                    
00183     listelem_alloc_t *latpath_alloc; 
00184 } ps_astar_t;
00185 
00189 typedef struct astar_seg_s {
00190     ps_seg_t base;
00191     ps_latnode_t **nodes;
00192     int n_nodes;
00193     int cur;
00194 } astar_seg_t;
00195 
00199 ps_lattice_t *ps_lattice_init_search(ps_search_t *search, int n_frame);
00200 
00204 void ps_lattice_bypass_fillers(ps_lattice_t *dag, int32 silpen, int32 fillpen);
00205 
00209 void ps_lattice_delete_unreachable(ps_lattice_t *dag);
00210 
00214 void ps_lattice_pushq(ps_lattice_t *dag, ps_latlink_t *link);
00215 
00219 ps_latlink_t *ps_lattice_popq(ps_lattice_t *dag);
00220 
00224 void ps_lattice_delq(ps_lattice_t *dag);
00225 
00229 latlink_list_t *latlink_list_new(ps_lattice_t *dag, ps_latlink_t *link,
00230                                  latlink_list_t *next);
00231 
00235 char const *ps_lattice_hyp(ps_lattice_t *dag, ps_latlink_t *link);
00236 
00240 ps_seg_t *ps_lattice_seg_iter(ps_lattice_t *dag, ps_latlink_t *link,
00241                               float32 lwf);
00242 
00252 ps_astar_t *ps_astar_start(ps_lattice_t *dag,
00253                            ngram_model_t *lmset,
00254                            float32 lwf,
00255                            int sf, int ef,
00256                            int w1, int w2);
00257 
00263 ps_latpath_t *ps_astar_next(ps_astar_t *nbest);
00264 
00268 void ps_astar_finish(ps_astar_t *nbest);
00269 
00273 char const *ps_astar_hyp(ps_astar_t *nbest, ps_latpath_t *path);
00274 
00278 ps_seg_t *ps_astar_seg_iter(ps_astar_t *astar, ps_latpath_t *path, float32 lwf);
00279 
00280 
00281 #endif /* __PS_LATTICE_INTERNAL_H__ */