• Main Page
  • 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         glist_t velist;         
00120         int32 fanin;            
00121         int32 rem_score;        
00122         int32 best_exit;        
00123     } info;
00124     latlink_list_t *exits;      
00125     latlink_list_t *entries;    
00127     struct ps_latnode_s *alt;   
00128     struct ps_latnode_s *next;  
00129 };
00130 
00134 typedef struct dag_seg_s {
00135     ps_seg_t base;       
00136     ps_latlink_t **links;   
00137     int32 norm;     
00138     int16 n_links;  
00139     int16 cur;      
00140 } dag_seg_t;
00141 
00148 typedef struct ps_latpath_s {
00149     ps_latnode_t *node;            
00150     struct ps_latpath_s *parent;   
00151     struct ps_latpath_s *next;     
00152     int32 score;                  
00153 } ps_latpath_t;
00154 
00158 typedef struct ps_astar_s {
00159     ps_lattice_t *dag;
00160     ngram_model_t *lmset;
00161     float32 lwf;
00162 
00163     int16 sf;
00164     int16 ef;
00165     int32 w1;
00166     int32 w2;
00167 
00168     int32 n_hyp_tried;
00169     int32 n_hyp_insert;
00170     int32 n_hyp_reject;
00171     int32 insert_depth;
00172     int32 n_path;
00173 
00174     ps_latpath_t *path_list;
00175     ps_latpath_t *path_tail;
00176     ps_latpath_t *top;
00177 
00178     glist_t hyps;                    
00179     listelem_alloc_t *latpath_alloc; 
00180 } ps_astar_t;
00181 
00185 typedef struct astar_seg_s {
00186     ps_seg_t base;
00187     ps_latnode_t **nodes;
00188     int n_nodes;
00189     int cur;
00190 } astar_seg_t;
00191 
00195 ps_lattice_t *ps_lattice_init_search(ps_search_t *search, int n_frame);
00196 
00200 void ps_lattice_bypass_fillers(ps_lattice_t *dag, int32 silpen, int32 fillpen);
00201 
00205 void ps_lattice_delete_unreachable(ps_lattice_t *dag);
00206 
00210 void ps_lattice_pushq(ps_lattice_t *dag, ps_latlink_t *link);
00211 
00215 ps_latlink_t *ps_lattice_popq(ps_lattice_t *dag);
00216 
00220 void ps_lattice_delq(ps_lattice_t *dag);
00221 
00225 latlink_list_t *latlink_list_new(ps_lattice_t *dag, ps_latlink_t *link,
00226                                  latlink_list_t *next);
00227 
00231 char const *ps_lattice_hyp(ps_lattice_t *dag, ps_latlink_t *link);
00232 
00236 ps_seg_t *ps_lattice_seg_iter(ps_lattice_t *dag, ps_latlink_t *link,
00237                               float32 lwf);
00238 
00248 ps_astar_t *ps_astar_start(ps_lattice_t *dag,
00249                            ngram_model_t *lmset,
00250                            float32 lwf,
00251                            int sf, int ef,
00252                            int w1, int w2);
00253 
00259 ps_latpath_t *ps_astar_next(ps_astar_t *nbest);
00260 
00264 void ps_astar_finish(ps_astar_t *nbest);
00265 
00269 char const *ps_astar_hyp(ps_astar_t *nbest, ps_latpath_t *path);
00270 
00274 ps_seg_t *ps_astar_seg_iter(ps_astar_t *astar, ps_latpath_t *path, float32 lwf);
00275 
00276 
00277 #endif /* __PS_LATTICE_INTERNAL_H__ */

Generated on Sat Jan 8 2011 for PocketSphinx by  doxygen 1.7.1