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

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     ps_search_t *search; 
00065     logmath_t *lmath;    
00067     ps_latnode_t *nodes;  
00068     ps_latnode_t *start;  
00069     ps_latnode_t *end;    
00071     int32 n_frames;    
00072     int32 final_node_ascr; 
00073     int32 norm;        
00074     char *hyp_str;     
00076     listelem_alloc_t *latnode_alloc;     
00077     listelem_alloc_t *latlink_alloc;     
00078     listelem_alloc_t *latlink_list_alloc; 
00080     /* This will probably be replaced with a heap. */
00081     latlink_list_t *q_head; 
00082     latlink_list_t *q_tail; 
00083 };
00084 
00092 struct ps_latlink_s {
00093     struct ps_latnode_s *from;  
00094     struct ps_latnode_s *to;    
00095     struct ps_latlink_s *best_prev;
00096     int32 ascr;                 
00097     int32 path_scr;             
00098     int32 ef;                   
00099     int32 alpha;                
00100     int32 beta;                 
00101 };
00102 
00109 struct ps_latnode_s {
00110     int32 id;                   
00111     int32 wid;                  
00112     int32 basewid;              
00113     /* FIXME: These are (ab)used to store backpointer indices, therefore they MUST be 32 bits. */
00114     int32 fef;                  
00115     int32 lef;                  
00116     int16 sf;                   
00117     int16 reachable;            
00118     union {
00119         int32 fanin;            
00120         int32 rem_score;        
00121         int32 best_exit;        
00122     } info;
00123     latlink_list_t *exits;      
00124     latlink_list_t *entries;    
00126     struct ps_latnode_s *alt;   
00127     struct ps_latnode_s *next;  
00128 };
00129 
00133 typedef struct dag_seg_s {
00134     ps_seg_t base;       
00135     ps_latlink_t **links;   
00136     int32 norm;     
00137     int16 n_links;  
00138     int16 cur;      
00139 } dag_seg_t;
00140 
00147 typedef struct ps_latpath_s {
00148     ps_latnode_t *node;            
00149     struct ps_latpath_s *parent;   
00150     struct ps_latpath_s *next;     
00151     int32 score;                  
00152 } ps_latpath_t;
00153 
00157 typedef struct ps_astar_s {
00158     ps_lattice_t *dag;
00159     ngram_model_t *lmset;
00160     float32 lwf;
00161 
00162     int16 sf;
00163     int16 ef;
00164     int32 w1;
00165     int32 w2;
00166 
00167     int32 n_hyp_tried;
00168     int32 n_hyp_insert;
00169     int32 n_hyp_reject;
00170     int32 insert_depth;
00171     int32 n_path;
00172 
00173     ps_latpath_t *path_list;
00174     ps_latpath_t *path_tail;
00175     ps_latpath_t *paths_done;
00176 
00177     glist_t hyps;                    
00178     listelem_alloc_t *latpath_alloc; 
00179 } ps_astar_t;
00180 
00184 typedef struct astar_seg_s {
00185     ps_seg_t base;
00186     ps_latnode_t **nodes;
00187     int n_nodes;
00188     int cur;
00189 } astar_seg_t;
00190 
00194 ps_lattice_t *ps_lattice_init_search(ps_search_t *search, int n_frame);
00195 
00199 void ps_lattice_bypass_fillers(ps_lattice_t *dag, int32 silpen, int32 fillpen);
00200 
00204 void ps_lattice_delete_unreachable(ps_lattice_t *dag);
00205 
00209 void ps_lattice_pushq(ps_lattice_t *dag, ps_latlink_t *link);
00210 
00214 ps_latlink_t *ps_lattice_popq(ps_lattice_t *dag);
00215 
00219 void ps_lattice_delq(ps_lattice_t *dag);
00220 
00224 latlink_list_t *latlink_list_new(ps_lattice_t *dag, ps_latlink_t *link,
00225                                  latlink_list_t *next);
00226 
00230 char const *ps_lattice_hyp(ps_lattice_t *dag, ps_latlink_t *link);
00231 
00235 ps_seg_t *ps_lattice_seg_iter(ps_lattice_t *dag, ps_latlink_t *link,
00236                               float32 lwf);
00237 
00247 ps_astar_t *ps_astar_start(ps_lattice_t *dag,
00248                            ngram_model_t *lmset,
00249                            float32 lwf,
00250                            int sf, int ef,
00251                            int w1, int w2);
00252 
00258 ps_latpath_t *ps_astar_next(ps_astar_t *nbest);
00259 
00263 void ps_astar_finish(ps_astar_t *nbest);
00264 
00268 char const *ps_astar_hyp(ps_astar_t *nbest, ps_latpath_t *path);
00269 
00273 ps_seg_t *ps_astar_seg_iter(ps_astar_t *astar, ps_latpath_t *path, float32 lwf);
00274 
00275 
00276 #endif /* __PS_LATTICE_INTERNAL_H__ */

Generated on Thu Jan 27 2011 for PocketSphinx by  doxygen 1.7.1