PocketSphinx  0.6
ps_lattice_internal.h
Go to the documentation of this file.
1 /* -*- c-basic-offset: 4; indent-tabs-mode: nil -*- */
2 /* ====================================================================
3  * Copyright (c) 2008 Carnegie Mellon University. All rights
4  * reserved.
5  *
6  * Redistribution and use in source and binary forms, with or without
7  * modification, are permitted provided that the following conditions
8  * are met:
9  *
10  * 1. Redistributions of source code must retain the above copyright
11  * notice, this list of conditions and the following disclaimer.
12  *
13  * 2. Redistributions in binary form must reproduce the above copyright
14  * notice, this list of conditions and the following disclaimer in
15  * the documentation and/or other materials provided with the
16  * distribution.
17  *
18  * This work was supported in part by funding from the Defense Advanced
19  * Research Projects Agency and the National Science Foundation of the
20  * United States of America, and the CMU Sphinx Speech Consortium.
21  *
22  * THIS SOFTWARE IS PROVIDED BY CARNEGIE MELLON UNIVERSITY ``AS IS'' AND
23  * ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
24  * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
25  * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL CARNEGIE MELLON UNIVERSITY
26  * NOR ITS EMPLOYEES BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
27  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
28  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
29  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
30  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
31  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
32  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
33  *
34  * ====================================================================
35  *
36  */
37 
42 #ifndef __PS_LATTICE_INTERNAL_H__
43 #define __PS_LATTICE_INTERNAL_H__
44 
53 typedef struct latlink_list_s {
54  ps_latlink_t *link;
55  struct latlink_list_s *next;
57 
61 struct ps_lattice_s {
62  int refcount;
64  logmath_t *lmath;
67  int32 silence;
68  int32 frate;
74  int16 n_frames;
75  int16 n_nodes;
77  int32 norm;
78  char *hyp_str;
80  listelem_alloc_t *latnode_alloc;
81  listelem_alloc_t *latlink_alloc;
82  listelem_alloc_t *latlink_list_alloc;
84  /* This will probably be replaced with a heap. */
87 };
88 
96 struct ps_latlink_s {
97  struct ps_latnode_s *from;
98  struct ps_latnode_s *to;
99  struct ps_latlink_s *best_prev;
100  int32 ascr;
101  int32 path_scr;
102  int32 ef;
103  int32 alpha;
104  int32 beta;
105 };
106 
113 struct ps_latnode_s {
114  int32 id;
115  int32 wid;
116  int32 basewid;
117  /* FIXME: These are (ab)used to store backpointer indices, therefore they MUST be 32 bits. */
118  int32 fef;
119  int32 lef;
120  int16 sf;
121  int16 reachable;
122  union {
123  glist_t velist;
124  int32 fanin;
125  int32 rem_score;
126  int32 best_exit;
127  } info;
131  struct ps_latnode_s *alt;
132  struct ps_latnode_s *next;
133 };
134 
138 typedef struct dag_seg_s {
141  int32 norm;
142  int16 n_links;
143  int16 cur;
144 } dag_seg_t;
145 
152 typedef struct ps_latpath_s {
155  struct ps_latpath_s *next;
156  int32 score;
157 } ps_latpath_t;
158 
162 typedef struct ps_astar_s {
163  ps_lattice_t *dag;
164  ngram_model_t *lmset;
165  float32 lwf;
166 
167  int16 sf;
168  int16 ef;
169  int32 w1;
170  int32 w2;
171 
172  int32 n_hyp_tried;
173  int32 n_hyp_insert;
174  int32 n_hyp_reject;
175  int32 insert_depth;
176  int32 n_path;
177 
178  ps_latpath_t *path_list;
179  ps_latpath_t *path_tail;
180  ps_latpath_t *top;
181 
182  glist_t hyps;
183  listelem_alloc_t *latpath_alloc;
184 } ps_astar_t;
185 
189 typedef struct astar_seg_s {
190  ps_seg_t base;
191  ps_latnode_t **nodes;
192  int n_nodes;
193  int cur;
194 } astar_seg_t;
195 
199 ps_lattice_t *ps_lattice_init_search(ps_search_t *search, int n_frame);
200 
204 void ps_lattice_bypass_fillers(ps_lattice_t *dag, int32 silpen, int32 fillpen);
205 
210 
214 void ps_lattice_pushq(ps_lattice_t *dag, ps_latlink_t *link);
215 
220 
224 void ps_lattice_delq(ps_lattice_t *dag);
225 
230  latlink_list_t *next);
231 
235 char const *ps_lattice_hyp(ps_lattice_t *dag, ps_latlink_t *link);
236 
241  float32 lwf);
242 
253  ngram_model_t *lmset,
254  float32 lwf,
255  int sf, int ef,
256  int w1, int w2);
257 
264 
268 void ps_astar_finish(ps_astar_t *nbest);
269 
273 char const *ps_astar_hyp(ps_astar_t *nbest, ps_latpath_t *path);
274 
278 ps_seg_t *ps_astar_seg_iter(ps_astar_t *astar, ps_latpath_t *path, float32 lwf);
279 
280 
281 #endif /* __PS_LATTICE_INTERNAL_H__ */